diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-08-22 21:54:12 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-08-22 21:54:12 +0200 |
| commit | 1261fd5d7ff67c907c72fbbd6959d68bd7c8063b (patch) | |
| tree | ce18c0240b0d4fb00bd4d7d1b9829fb0b7d8c152 /crates/daemon/src/aclient/database/mod.rs | |
| parent | treewide: Update Cargo.toml metadata (diff) | |
| download | atuin-1261fd5d7ff67c907c72fbbd6959d68bd7c8063b.zip | |
treewide: Upgrade and update dependencies
`rusty_paseto` was left explicitly on v0.8 because the v0.10 is no longer
compatible with `rusty_paserk`.
Diffstat (limited to 'crates/daemon/src/aclient/database/mod.rs')
| -rw-r--r-- | crates/daemon/src/aclient/database/mod.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/crates/daemon/src/aclient/database/mod.rs b/crates/daemon/src/aclient/database/mod.rs index f24eb777..7cee866e 100644 --- a/crates/daemon/src/aclient/database/mod.rs +++ b/crates/daemon/src/aclient/database/mod.rs @@ -3,7 +3,7 @@ use std::{path::Path, str::FromStr, time::Duration}; use fs_err::{self as fs}; use sql_builder::{SqlBuilder, SqlName}; use sqlx::{ - Result, Row, + AssertSqlSafe, Result, Row, sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePool, SqliteRow, SqliteSynchronous}, }; use time::OffsetDateTime; @@ -56,8 +56,11 @@ impl ClientSqlite { async fn save_raw(tx: &mut sqlx::Transaction<'_, sqlx::Sqlite>, h: &History) -> Result<()> { sqlx::query( - "insert or ignore into history(id, timestamp, duration, exit, command, cwd, session, hostname, author, intent, deleted_at) - values(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)", + " + INSERT OR IGNORE + INTO history (id, timestamp, duration, exit, command, cwd, session, hostname, author, intent, deleted_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11) + ", ) .bind(h.id.to_string().as_str()) .bind(h.timestamp.unix_timestamp_nanos() as i64) @@ -156,12 +159,16 @@ impl ClientSqlite { } if let Some(max) = max { + let max: usize = max; query.limit(max); } let query = query.sql().expect("bug in list query. please report"); - let res = sqlx::query(&query) + // SAFETY: + // - The query is constructed via sql_bulider, and as such should be safe. + // - The only value, that is directly added to the query is a `usize`. + let res = sqlx::query(AssertSqlSafe(query)) .map(Self::query_history_inner) .fetch_all(&self.pool) .await?; @@ -177,11 +184,16 @@ impl ClientSqlite { debug!("listing history from {:?} to {:?}", from, to); let res = sqlx::query( - "select * from history where timestamp >= ?1 and timestamp <= ?2 order by timestamp asc", + " + SELECT * + FROM history + WHERE timestamp >= ?1 AND timestamp <= ?2 + ORDER BY timestamp ASC + ", ) .bind(from.unix_timestamp_nanos() as i64) .bind(to.unix_timestamp_nanos() as i64) - .map(Self::query_history_inner) + .map(Self::query_history_inner) .fetch_all(&self.pool) .await?; |
