From 4077c33adfdacaf0ed68657a1955a7b69a78d373 Mon Sep 17 00:00:00 2001 From: Vlad Stepanov <8uk.8ak@gmail.com> Date: Thu, 15 Jun 2023 14:29:40 +0400 Subject: Builder interface for History objects (#933) * [feature] store env variables in History records WIP: remove `HistoryWithoutDelete`, add some docstrings, tests * Create History objects through builders. Assure in compile-time that all required fields are set for the given construction scenario * (from #882) split Cmd::run into subfns * Update `History` doc * remove rmp-serde from history * update warning --------- Co-authored-by: Conrad Ludgate --- atuin-client/src/database.rs | 47 +++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'atuin-client/src/database.rs') diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index a2d8c533..b7b44409 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -168,17 +168,18 @@ impl Sqlite { fn query_history(row: SqliteRow) -> History { let deleted_at: Option = row.get("deleted_at"); - History { - id: row.get("id"), - timestamp: Utc.timestamp_nanos(row.get("timestamp")), - duration: row.get("duration"), - exit: row.get("exit"), - command: row.get("command"), - cwd: row.get("cwd"), - session: row.get("session"), - hostname: row.get("hostname"), - deleted_at: deleted_at.map(|t| Utc.timestamp_nanos(t)), - } + History::from_db() + .id(row.get("id")) + .timestamp(Utc.timestamp_nanos(row.get("timestamp"))) + .duration(row.get("duration")) + .exit(row.get("exit")) + .command(row.get("command")) + .cwd(row.get("cwd")) + .session(row.get("session")) + .hostname(row.get("hostname")) + .deleted_at(deleted_at.map(|t| Utc.timestamp_nanos(t))) + .build() + .into() } } @@ -594,17 +595,19 @@ mod test { } async fn new_history_item(db: &mut impl Database, cmd: &str) -> Result<()> { - let history = History::new( - chrono::Utc::now(), - cmd.to_string(), - "/home/ellie".to_string(), - 0, - 1, - Some("beep boop".to_string()), - Some("booop".to_string()), - None, - ); - db.save(&history).await + let mut captured: History = History::capture() + .timestamp(chrono::Utc::now()) + .command(cmd) + .cwd("/home/ellie") + .build() + .into(); + + captured.exit = 0; + captured.duration = 1; + captured.session = "beep boop".to_string(); + captured.hostname = "booop".to_string(); + + db.save(&captured).await } #[tokio::test(flavor = "multi_thread")] -- cgit v1.3.1