diff options
Diffstat (limited to 'crates/turtle/src/atuin_client/meta.rs')
| -rw-r--r-- | crates/turtle/src/atuin_client/meta.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/turtle/src/atuin_client/meta.rs b/crates/turtle/src/atuin_client/meta.rs index 2fbfe275..502d7421 100644 --- a/crates/turtle/src/atuin_client/meta.rs +++ b/crates/turtle/src/atuin_client/meta.rs @@ -24,13 +24,13 @@ const KEY_LATEST_VERSION: &str = "latest_version"; const KEY_SESSION: &str = "session"; const KEY_FILES_MIGRATED: &str = "files_migrated"; -pub struct MetaStore { +pub(crate) struct MetaStore { pool: SqlitePool, cached_host_id: OnceCell<HostId>, } impl MetaStore { - pub async fn new(path: impl AsRef<Path>, timeout: f64) -> Result<Self> { + pub(crate) async fn new(path: impl AsRef<Path>, timeout: f64) -> Result<Self> { let path = path.as_ref(); let path_str = path .as_os_str() @@ -86,7 +86,7 @@ impl MetaStore { // Generic key-value operations - pub async fn get(&self, key: &str) -> Result<Option<String>> { + pub(crate) async fn get(&self, key: &str) -> Result<Option<String>> { let row: Option<(String,)> = sqlx::query_as("SELECT value FROM meta WHERE key = ?1") .bind(key) .fetch_optional(&self.pool) @@ -95,7 +95,7 @@ impl MetaStore { Ok(row.map(|r| r.0)) } - pub async fn set(&self, key: &str, value: &str) -> Result<()> { + pub(crate) async fn set(&self, key: &str, value: &str) -> Result<()> { sqlx::query( "INSERT INTO meta (key, value, updated_at) VALUES (?1, ?2, strftime('%s', 'now')) ON CONFLICT(key) DO UPDATE SET value = ?2, updated_at = strftime('%s', 'now')", @@ -108,7 +108,7 @@ impl MetaStore { Ok(()) } - pub async fn delete(&self, key: &str) -> Result<()> { + pub(crate) async fn delete(&self, key: &str) -> Result<()> { sqlx::query("DELETE FROM meta WHERE key = ?1") .bind(key) .execute(&self.pool) @@ -119,7 +119,7 @@ impl MetaStore { // Typed accessors - pub async fn host_id(&self) -> Result<HostId> { + pub(crate) async fn host_id(&self) -> Result<HostId> { self.cached_host_id .get_or_try_init(|| async { if let Some(id) = self.get(KEY_HOST_ID).await? { @@ -138,14 +138,14 @@ impl MetaStore { .copied() } - pub async fn last_sync(&self) -> Result<OffsetDateTime> { + pub(crate) async fn last_sync(&self) -> Result<OffsetDateTime> { match self.get(KEY_LAST_SYNC).await? { Some(v) => Ok(OffsetDateTime::parse(v.as_str(), &Rfc3339)?), None => Ok(OffsetDateTime::UNIX_EPOCH), } } - pub async fn save_sync_time(&self) -> Result<()> { + pub(crate) async fn save_sync_time(&self) -> Result<()> { self.set( KEY_LAST_SYNC, OffsetDateTime::now_utc().format(&Rfc3339)?.as_str(), @@ -153,14 +153,14 @@ impl MetaStore { .await } - pub async fn last_version_check(&self) -> Result<OffsetDateTime> { + pub(crate) async fn last_version_check(&self) -> Result<OffsetDateTime> { match self.get(KEY_LAST_VERSION_CHECK).await? { Some(v) => Ok(OffsetDateTime::parse(v.as_str(), &Rfc3339)?), None => Ok(OffsetDateTime::UNIX_EPOCH), } } - pub async fn save_version_check_time(&self) -> Result<()> { + pub(crate) async fn save_version_check_time(&self) -> Result<()> { self.set( KEY_LAST_VERSION_CHECK, OffsetDateTime::now_utc().format(&Rfc3339)?.as_str(), @@ -168,27 +168,27 @@ impl MetaStore { .await } - pub async fn latest_version(&self) -> Result<Option<String>> { + pub(crate) async fn latest_version(&self) -> Result<Option<String>> { self.get(KEY_LATEST_VERSION).await } - pub async fn save_latest_version(&self, version: &str) -> Result<()> { + pub(crate) async fn save_latest_version(&self, version: &str) -> Result<()> { self.set(KEY_LATEST_VERSION, version).await } - pub async fn session_token(&self) -> Result<Option<String>> { + pub(crate) async fn session_token(&self) -> Result<Option<String>> { self.get(KEY_SESSION).await } - pub async fn save_session(&self, token: &str) -> Result<()> { + pub(crate) async fn save_session(&self, token: &str) -> Result<()> { self.set(KEY_SESSION, token).await } - pub async fn delete_session(&self) -> Result<()> { + pub(crate) async fn delete_session(&self) -> Result<()> { self.delete(KEY_SESSION).await } - pub async fn logged_in(&self) -> Result<bool> { + pub(crate) async fn logged_in(&self) -> Result<bool> { Ok(self.session_token().await?.is_some()) } |
