diff options
Diffstat (limited to 'atuin-client/src')
-rw-r--r-- | atuin-client/src/api_client.rs | 14 | ||||
-rw-r--r-- | atuin-client/src/history.rs | 2 | ||||
-rw-r--r-- | atuin-client/src/record/sqlite_store.rs | 10 | ||||
-rw-r--r-- | atuin-client/src/record/store.rs | 1 |
4 files changed, 25 insertions, 2 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index a19e5305..f31a796e 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -11,7 +11,7 @@ use reqwest::{ use atuin_common::{ api::{ AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest, - ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse, + ErrorResponse, LoginRequest, LoginResponse, MeResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, }, record::RecordStatus, @@ -234,6 +234,18 @@ impl<'a> Client<'a> { Ok(status) } + pub async fn me(&self) -> Result<MeResponse> { + let url = format!("{}/api/v0/me", self.sync_addr); + let url = Url::parse(url.as_str())?; + + let resp = self.client.get(url).send().await?; + let resp = handle_resp_error(resp).await?; + + let status = resp.json::<MeResponse>().await?; + + Ok(status) + } + pub async fn get_history( &self, sync_ts: OffsetDateTime, diff --git a/atuin-client/src/history.rs b/atuin-client/src/history.rs index bc74aebd..1b590e88 100644 --- a/atuin-client/src/history.rs +++ b/atuin-client/src/history.rs @@ -18,7 +18,7 @@ mod builder; pub mod store; const HISTORY_VERSION: &str = "v0"; -const HISTORY_TAG: &str = "history"; +pub const HISTORY_TAG: &str = "history"; #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct HistoryId(pub String); diff --git a/atuin-client/src/record/sqlite_store.rs b/atuin-client/src/record/sqlite_store.rs index e17893eb..31de311b 100644 --- a/atuin-client/src/record/sqlite_store.rs +++ b/atuin-client/src/record/sqlite_store.rs @@ -180,6 +180,16 @@ impl Store for SqliteStore { self.idx(host, tag, 0).await } + async fn len_all(&self) -> Result<u64> { + let res: Result<(i64,), sqlx::Error> = sqlx::query_as("select count(*) from store") + .fetch_one(&self.pool) + .await; + match res { + Err(e) => Err(eyre!("failed to fetch local store len: {}", e)), + Ok(v) => Ok(v.0 as u64), + } + } + async fn len_tag(&self, tag: &str) -> Result<u64> { let res: Result<(i64,), sqlx::Error> = sqlx::query_as("select count(*) from store where tag=?1") diff --git a/atuin-client/src/record/store.rs b/atuin-client/src/record/store.rs index 188e18ce..49ca4968 100644 --- a/atuin-client/src/record/store.rs +++ b/atuin-client/src/record/store.rs @@ -25,6 +25,7 @@ pub trait Store { async fn delete(&self, id: RecordId) -> Result<()>; async fn delete_all(&self) -> Result<()>; + async fn len_all(&self) -> Result<u64>; async fn len(&self, host: HostId, tag: &str) -> Result<u64>; async fn len_tag(&self, tag: &str) -> Result<u64>; |