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"
time = "0.3.44"
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-sqlx-store = { version = "0.15.0", features = ["sqlite"] }
tracing = { version = "0.1.41", features = ["attributes"] }

View file

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

View file

@ -129,6 +129,8 @@ pub async fn insert_mentions<'a>(
mentions: impl IntoIterator<Item = &'a Mention>,
pool: &SqlitePool,
) -> Result<(), AppError> {
let mut mentions = mentions.into_iter().peekable();
if mentions.peek().is_some() {
let mut qb = QueryBuilder::<sqlx::Sqlite>::new(
"insert into mentions (
entity_id, entity_type, url, input_text,
@ -143,5 +145,6 @@ pub async fn insert_mentions<'a>(
.push_bind(mention.byte_range_end);
});
qb.build().execute(pool).await?;
}
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
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());
textarea name="value" placeholder="New entry..." autofocus {}
input type="submit" value="Add Entry";
}
#journal-error {}
.entries {
@for entry in entries {
(entry.to_html(pool).await?)

View file

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

View file

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