diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-09 22:00:59 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-07-09 22:00:59 +0200 |
| commit | 620cf8fa33835c1ce1e56b1028ff6e2a6fbe0f39 (patch) | |
| tree | e97e54ff112c8e3fa9f88335bfd1275420a4d69f /crates/server/src/database | |
| parent | chore: Separate daemon, client, server, and lib into crates (diff) | |
| download | atuin-620cf8fa33835c1ce1e56b1028ff6e2a6fbe0f39.zip | |
chore: Add more things
Diffstat (limited to '')
| -rw-r--r-- | crates/server/src/database/db/mod.rs | 18 | ||||
| -rw-r--r-- | crates/server/src/database/db/wrappers.rs | 4 | ||||
| -rw-r--r-- | crates/server/src/database/mod.rs | 18 | ||||
| -rw-r--r-- | crates/server/src/database/models.rs | 4 |
4 files changed, 21 insertions, 23 deletions
diff --git a/crates/server/src/database/db/mod.rs b/crates/server/src/database/db/mod.rs index 77bd0c61..c95a2ed4 100644 --- a/crates/server/src/database/db/mod.rs +++ b/crates/server/src/database/db/mod.rs @@ -2,11 +2,9 @@ use std::collections::HashMap; use rand::Rng; -use crate::{ - atuin_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus}, - atuin_server::database::{DbError, DbResult, DbSettings, models::User}, -}; +use crate::database::{DbError, DbResult, DbSettings, models::User}; use sqlx::postgres::PgPoolOptions; +use turtle_common::record::{EncryptedData, HostId, Record, RecordIdx, RecordStatus}; use tracing::instrument; use uuid::Uuid; @@ -17,7 +15,7 @@ mod wrappers; const MIN_PG_VERSION: u32 = 14; #[derive(Clone)] -pub(crate) struct ServerPostgres { +pub struct ServerPostgres { pool: sqlx::Pool<sqlx::postgres::Postgres>, /// Optional read replica pool for read-only queries read_pool: Option<sqlx::Pool<sqlx::postgres::Postgres>>, @@ -32,7 +30,7 @@ impl ServerPostgres { } impl ServerPostgres { - pub(crate) async fn new(settings: &DbSettings) -> DbResult<Self> { + pub async fn new(settings: &DbSettings) -> DbResult<Self> { let pool = PgPoolOptions::new() .max_connections(100) .connect(settings.db_uri.as_str()) @@ -93,7 +91,7 @@ impl ServerPostgres { } #[instrument(skip_all)] - pub(crate) async fn add_records( + pub async fn add_records( &self, user: &User, records: &[Record<EncryptedData>], @@ -110,7 +108,7 @@ impl ServerPostgres { let mut heads = HashMap::<(HostId, &str), u64>::new(); for i in records { - let id = crate::atuin_common::utils::uuid_v7(); + let id = turtle_common::utils::uuid_v7(); let result = sqlx::query( " @@ -169,7 +167,7 @@ impl ServerPostgres { } #[instrument(skip_all)] - pub(crate) async fn next_records( + pub async fn next_records( &self, user: &User, host: HostId, @@ -222,7 +220,7 @@ impl ServerPostgres { Ok(ret) } - pub(crate) async fn status(&self, user: &User) -> DbResult<RecordStatus> { + pub async fn status(&self, user: &User) -> DbResult<RecordStatus> { // If IDX_CACHE_ROLLOUT is set, then we // 1. Read the value of the var, use it as a % chance of using the cache // 2. If we use the cache, just read from the cache table diff --git a/crates/server/src/database/db/wrappers.rs b/crates/server/src/database/db/wrappers.rs index 0315e331..8054289a 100644 --- a/crates/server/src/database/db/wrappers.rs +++ b/crates/server/src/database/db/wrappers.rs @@ -1,7 +1,7 @@ -use crate::atuin_common::record::{EncryptedData, Host, Record}; +use turtle_common::record::{EncryptedData, Host, Record}; use sqlx::{Row, postgres::PgRow}; -pub(crate) struct DbRecord(pub Record<EncryptedData>); +pub struct DbRecord(pub Record<EncryptedData>); impl<'a> ::sqlx::FromRow<'a, PgRow> for DbRecord { fn from_row(row: &'a PgRow) -> ::sqlx::Result<Self> { diff --git a/crates/server/src/database/mod.rs b/crates/server/src/database/mod.rs index 43fe5c3b..c05fa783 100644 --- a/crates/server/src/database/mod.rs +++ b/crates/server/src/database/mod.rs @@ -1,12 +1,12 @@ -pub(crate) mod db; -pub(crate) mod models; +pub mod db; +pub mod models; use std::fmt::{Debug, Display}; use serde::{Deserialize, Serialize}; #[derive(Debug)] -pub(crate) enum DbError { +pub enum DbError { NotFound, Other(eyre::Report), } @@ -43,24 +43,24 @@ impl From<sqlx::Error> for DbError { impl std::error::Error for DbError {} -pub(crate) type DbResult<T> = Result<T, DbError>; +pub type DbResult<T> = Result<T, DbError>; #[derive(Debug, PartialEq)] -pub(crate) enum DbType { +pub enum DbType { Postgres, Unknown, } #[derive(Clone, Deserialize, Serialize)] -pub(crate) struct DbSettings { - pub(crate) db_uri: String, +pub struct DbSettings { + pub db_uri: String, /// Optional URI for read replicas. If set, read-only queries will use this connection. - pub(crate) read_db_uri: Option<String>, + pub read_db_uri: Option<String>, } impl DbSettings { - pub(crate) fn db_type(&self) -> DbType { + pub fn db_type(&self) -> DbType { if self.db_uri.starts_with("postgres://") || self.db_uri.starts_with("postgresql://") { DbType::Postgres } else { diff --git a/crates/server/src/database/models.rs b/crates/server/src/database/models.rs index 3fa6f471..9f6241ae 100644 --- a/crates/server/src/database/models.rs +++ b/crates/server/src/database/models.rs @@ -1,5 +1,5 @@ use uuid::Uuid; -pub(crate) struct User { - pub(crate) id: Uuid, +pub struct User { + pub id: Uuid, } |
