diff options
| author | Conrad Ludgate <conradludgate@gmail.com> | 2023-03-19 20:49:57 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-19 20:49:57 +0000 |
| commit | edcd477153d00944c5dae16ec3ba69e339e1450c (patch) | |
| tree | 472e0151222cdfc8978875ee3531079c58ece75b /atuin-client/src/database.rs | |
| parent | fix: many wins were broken :memo: (#789) (diff) | |
| download | atuin-edcd477153d00944c5dae16ec3ba69e339e1450c.zip | |
skim-demo (#695)
* skim-demo
* skim some more
* Weight first word match higher (#712)
* some improvements
* make skim opt-in
---------
Co-authored-by: Frank Hamand <frankhamand@gmail.com>
Diffstat (limited to 'atuin-client/src/database.rs')
| -rw-r--r-- | atuin-client/src/database.rs | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 3b579153..b24020c0 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -21,9 +21,9 @@ use super::{ }; pub struct Context { - session: String, - cwd: String, - hostname: String, + pub session: String, + pub cwd: String, + pub hostname: String, } pub fn current_context() -> Context { @@ -85,6 +85,8 @@ pub trait Database: Send + Sync { ) -> Result<Vec<History>>; async fn query_history(&self, query: &str) -> Result<Vec<History>>; + + async fn all_with_count(&self) -> Result<Vec<(History, i32)>>; } // Intended for use on a developer machine and not a sync server. @@ -428,7 +430,7 @@ impl Database for Sqlite { match search_mode { SearchMode::Prefix => sql.and_where_like_left("command", query), SearchMode::FullText => sql.and_where_like_any("command", query), - SearchMode::Fuzzy => { + SearchMode::Skim | SearchMode::Fuzzy => { // don't recompile the regex on successive calls! lazy_static! { static ref SPLIT_REGEX: Regex = Regex::new(r" +").unwrap(); @@ -492,6 +494,40 @@ impl Database for Sqlite { Ok(res) } + + async fn all_with_count(&self) -> Result<Vec<(History, i32)>> { + debug!("listing history"); + + let mut query = SqlBuilder::select_from(SqlName::new("history").alias("h").baquoted()); + + query + .fields(&[ + "id", + "max(timestamp) as timestamp", + "max(duration) as duration", + "exit", + "command", + "group_concat(cwd, ':') as cwd", + "group_concat(session) as session", + "group_concat(hostname, ',') as hostname", + "count(*) as count", + ]) + .group_by("command") + .group_by("exit") + .order_desc("timestamp"); + + let query = query.sql().expect("bug in list query. please report"); + + let res = sqlx::query(&query) + .map(|row: SqliteRow| { + let count: i32 = row.get("count"); + (Self::query_history(row), count) + }) + .fetch_all(&self.pool) + .await?; + + Ok(res) + } } #[cfg(test)] |
