diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 17:16:19 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 17:16:19 +0200 |
| commit | 2ca7dd57b12861e8c9bbc9238cda612e0ff22ff3 (patch) | |
| tree | 302a644f6a50d60cc8304c4498fe6bbb72ddaaa9 /crates/turtle/src/atuin_client/database.rs | |
| parent | feat(server): Really make users stateless (with tests) (diff) | |
| download | atuin-2ca7dd57b12861e8c9bbc9238cda612e0ff22ff3.zip | |
chore(treewide): Cleanup themes
Diffstat (limited to 'crates/turtle/src/atuin_client/database.rs')
| -rw-r--r-- | crates/turtle/src/atuin_client/database.rs | 99 |
1 files changed, 6 insertions, 93 deletions
diff --git a/crates/turtle/src/atuin_client/database.rs b/crates/turtle/src/atuin_client/database.rs index f8b73809..6a2d5887 100644 --- a/crates/turtle/src/atuin_client/database.rs +++ b/crates/turtle/src/atuin_client/database.rs @@ -8,7 +8,6 @@ use std::{ use crate::atuin_common::utils; use fs_err as fs; use itertools::Itertools; -use rand::{Rng, distributions::Alphanumeric}; use sql_builder::{SqlBuilder, SqlName, bind::Bind, esc, quote}; use sqlx::{ Result, Row, @@ -192,8 +191,10 @@ impl ClientSqlite { History::from_db() .id(row.get("id")) .timestamp( - OffsetDateTime::from_unix_timestamp_nanos(row.get::<i64, _>("timestamp") as i128) - .unwrap(), + OffsetDateTime::from_unix_timestamp_nanos(i128::from( + row.get::<i64, _>("timestamp"), + )) + .unwrap(), ) .duration(row.get("duration")) .exit(row.get("exit")) @@ -247,31 +248,6 @@ impl ClientSqlite { Ok(res) } - pub(crate) async fn update(&self, h: &History) -> Result<()> { - debug!("updating sqlite history"); - - sqlx::query( - "update history - set timestamp = ?2, duration = ?3, exit = ?4, command = ?5, cwd = ?6, session = ?7, hostname = ?8, author = ?9, intent = ?10, deleted_at = ?11 - where id = ?1", - ) - .bind(h.id.0.as_str()) - .bind(h.timestamp.unix_timestamp_nanos() as i64) - .bind(h.duration) - .bind(h.exit) - .bind(h.command.as_str()) - .bind(h.cwd.as_str()) - .bind(h.session.as_str()) - .bind(h.hostname.as_str()) - .bind(h.author.as_str()) - .bind(h.intent.as_deref()) - .bind(h.deleted_at.map(|t|t.unix_timestamp_nanos() as i64)) - .execute(&self.pool) - .await?; - - Ok(()) - } - // make a unique list, that only shows the *newest* version of things pub(crate) async fn list( &self, @@ -452,9 +428,9 @@ impl ClientSqlite { if !is_or { is_or = true; continue; - } else { - format!("{glob}|{glob}") } + + format!("{glob}|{glob}") } QueryToken::MatchStart(term, _) => { format!("{term}{glob}") @@ -584,22 +560,6 @@ impl ClientSqlite { Paged::new(self.clone(), page_size, include_deleted, unique) } - // deleted_at doesn't mean the actual time that the user deleted it, - // but the time that the system marks it as deleted - pub(crate) async fn delete(&self, mut h: History) -> Result<()> { - let now = OffsetDateTime::now_utc(); - h.command = rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(32) - .map(char::from) - .collect(); // overwrite with random string - h.deleted_at = Some(now); // delete it - - self.update(&h).await?; // save it - - Ok(()) - } - pub(crate) async fn delete_rows(&self, ids: &[HistoryId]) -> Result<()> { let mut tx = self.pool.begin().await?; @@ -1233,53 +1193,6 @@ mod test { } #[tokio::test(flavor = "multi_thread")] - async fn test_paged_include_deleted() { - let mut db = ClientSqlite::new("sqlite::memory:", test_local_timeout()) - .await - .unwrap(); - - // Add items - new_history_item(&mut db, "keep1").await.unwrap(); - new_history_item(&mut db, "keep2").await.unwrap(); - new_history_item(&mut db, "delete_me").await.unwrap(); - - // Delete one item - let all = db - .list( - &[], - &Context { - hostname: "".to_string(), - session: "".to_string(), - cwd: "".to_string(), - host_id: "".to_string(), - git_root: None, - }, - None, - false, - false, - ) - .await - .unwrap(); - - let to_delete = all - .iter() - .find(|h| h.command == "delete_me") - .unwrap() - .clone(); - db.delete(to_delete).await.unwrap(); - - // Without include_deleted - should get 2 - let mut paged = db.all_paged(10, false, false); - let page = paged.next().await.unwrap().unwrap(); - assert_eq!(page.len(), 2); - - // With include_deleted - should get 3 - let mut paged_deleted = db.all_paged(10, true, false); - let page_deleted = paged_deleted.next().await.unwrap().unwrap(); - assert_eq!(page_deleted.len(), 3); - } - - #[tokio::test(flavor = "multi_thread")] async fn test_search_bench_dupes() { let context = Context { hostname: "test:host".to_string(), |
