fix: don't generate broken sql

This commit is contained in:
Robert Perce 2026-02-04 13:07:26 -06:00
parent 57177612ec
commit c7130bbcd4
6 changed files with 23 additions and 14 deletions

View file

@ -34,7 +34,7 @@ sqlx = { version = "0.8", features = ["macros", "runtim
thiserror = "2.0.17" thiserror = "2.0.17"
time = "0.3.44" time = "0.3.44"
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] } tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread", "signal"] }
tower-http = { version = "0.6.6", features = ["fs"] } tower-http = { version = "0.6.6", features = ["fs", "trace"] }
tower-sessions = { version = "0.14.0", features = ["signed"] } tower-sessions = { version = "0.14.0", features = ["signed"] }
tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] } tower-sessions-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
tracing = { version = "0.1.41", features = ["attributes"] } tracing = { version = "0.1.41", features = ["attributes"] }

View file

@ -170,6 +170,7 @@ async fn serve(port: &u32) -> Result<(), anyhow::Error> {
.merge(ics::router()) .merge(ics::router())
.nest_service("/static", ServeDir::new("./hashed_static")) .nest_service("/static", ServeDir::new("./hashed_static"))
.layer(auth_layer) .layer(auth_layer)
.layer(tower_http::trace::TraceLayer::new_for_http())
.with_state(state); .with_state(state);
let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await?; let listener = TcpListener::bind(format!("0.0.0.0:{}", port)).await?;

View file

@ -129,19 +129,22 @@ pub async fn insert_mentions<'a>(
mentions: impl IntoIterator<Item = &'a Mention>, mentions: impl IntoIterator<Item = &'a Mention>,
pool: &SqlitePool, pool: &SqlitePool,
) -> Result<(), AppError> { ) -> Result<(), AppError> {
let mut qb = QueryBuilder::<sqlx::Sqlite>::new( let mut mentions = mentions.into_iter().peekable();
"insert into mentions ( if mentions.peek().is_some() {
let mut qb = QueryBuilder::<sqlx::Sqlite>::new(
"insert into mentions (
entity_id, entity_type, url, input_text, entity_id, entity_type, url, input_text,
byte_range_start, byte_range_end) ", byte_range_start, byte_range_end) ",
); );
qb.push_values(mentions, |mut b, mention| { qb.push_values(mentions, |mut b, mention| {
b.push_bind(mention.entity_id) b.push_bind(mention.entity_id)
.push_bind(mention.entity_type) .push_bind(mention.entity_type)
.push_bind(&mention.url) .push_bind(&mention.url)
.push_bind(&mention.input_text) .push_bind(&mention.input_text)
.push_bind(mention.byte_range_start) .push_bind(mention.byte_range_start)
.push_bind(mention.byte_range_end); .push_bind(mention.byte_range_end);
}); });
qb.build().execute(pool).await?; qb.build().execute(pool).await?;
}
Ok(()) Ok(())
} }

View file

@ -102,12 +102,14 @@ pub async fn journal_section(
are now, or leave everything blank to default to 'today'. Entries will be are now, or leave everything blank to default to 'today'. Entries will be
added to the top of the list regardless of date; refresh the page to re-sort." added to the top of the list regardless of date; refresh the page to re-sort."
} }
form hx-post="/journal_entry" hx-target="next .entries" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) this.reset()" { form hx-post="/journal_entry" hx-target="next .entries" hx-target-error="#journal-error" hx-swap="afterbegin" hx-on::after-request="if(event.detail.successful) this.reset()" {
input name="date" placeholder=(Local::now().date_naive().to_string()); input name="date" placeholder=(Local::now().date_naive().to_string());
textarea name="value" placeholder="New entry..." autofocus {} textarea name="value" placeholder="New entry..." autofocus {}
input type="submit" value="Add Entry"; input type="submit" value="Add Entry";
} }
#journal-error {}
.entries { .entries {
@for entry in entries { @for entry in entries {
(entry.to_html(pool).await?) (entry.to_html(pool).await?)

View file

@ -80,6 +80,7 @@ mod post {
let switchboard = sw_lock.read().unwrap(); let switchboard = sw_lock.read().unwrap();
switchboard.extract_mentions(&entry) switchboard.extract_mentions(&entry)
}; };
tracing::debug!("{:?}", mentions);
insert_mentions(&mentions, pool).await?; insert_mentions(&mentions, pool).await?;
Ok(entry.to_html(pool).await?) Ok(entry.to_html(pool).await?)

View file

@ -21,6 +21,8 @@ struct ContactLink {
name: String, name: String,
contact_id: DbId, contact_id: DbId,
} }
#[derive(Debug)]
pub struct Layout { pub struct Layout {
contact_links: Vec<ContactLink>, contact_links: Vec<ContactLink>,
user: User, user: User,