pub struct Database { /* private fields */ }Implementations§
Source§impl Database
impl Database
pub async fn connect(url: &str, max_connections: u32) -> DbResult<Self>
pub async fn ping(&self) -> DbResult<()>
pub fn pool(&self) -> &SqlitePool
pub async fn create_user(&self, api_key: &str) -> DbResult<String>
pub async fn get_user_by_api_key( &self, api_key: &str, ) -> DbResult<Option<String>>
pub async fn create_library( &self, user_id: &str, name: &str, ) -> DbResult<String>
pub async fn list_libraries( &self, user_id: &str, limit: i32, offset: i32, ) -> DbResult<(Vec<Library>, i32)>
pub async fn delete_library( &self, user_id: &str, library_id: &str, ) -> DbResult<()>
pub async fn get_default_library(&self, user_id: &str) -> DbResult<String>
pub async fn verify_library_ownership( &self, user_id: &str, library_id: &str, ) -> DbResult<bool>
pub async fn get_snippets( &self, user_id: &str, library_id: &str, since: i64, limit: i32, offset: i32, include_deleted: bool, ) -> DbResult<(Vec<Snippet>, i32)>
Sourcepub async fn get_snippets_page(
&self,
user_id: &str,
library_id: &str,
cursor: DeltaCursor,
limit: i32,
offset: i32,
include_deleted: bool,
) -> DbResult<SnippetPage>
pub async fn get_snippets_page( &self, user_id: &str, library_id: &str, cursor: DeltaCursor, limit: i32, offset: i32, include_deleted: bool, ) -> DbResult<SnippetPage>
Fetch one page of snippets together with the paging facts derived from it.
The page is read with LIMIT limit + 1, so has_more comes from the
rows themselves instead of a second COUNT(*) scan over the same
range. The exact total is taken from the page whenever the page is
the last one (the range then holds exactly offset + rows rows); when
the range continues past the page — or the requested offset is past
the end of the range — the range is still counted so total keeps
its exact meaning.
pub async fn upsert_snippet_in_tx( &self, tx: &mut Transaction<'_, Sqlite>, snippet: &Snippet, user_id: &str, library_id: &str, ) -> DbResult<UpsertOutcome>
pub async fn get_latest_timestamp( &self, user_id: &str, library_id: &str, ) -> DbResult<i64>
Sourcepub async fn get_latest_sequence(
&self,
user_id: &str,
library_id: &str,
) -> DbResult<i64>
pub async fn get_latest_sequence( &self, user_id: &str, library_id: &str, ) -> DbResult<i64>
The library’s write-sequence watermark.
This is the cursor the server hands back to a client that syncs on the sequence path. It is the highest sequence any row of the library holds, so it never moves backwards and never skips a row.
Sourcepub async fn migrate_snippet_sequence(&self) -> DbResult<bool>
pub async fn migrate_snippet_sequence(&self) -> DbResult<bool>
Add the write-sequence cursor: its column, its per-library counter, and the unique index that turns a counter race into a loud failure.
The backfill gives every row a sequence that preserves the
pre-migration updated_at ordering (ranked inside the row’s library,
ties broken by the row id), so a migrated database selects the same
rows as an unmigrated one for the first sync and every client’s stored
cursor stays valid. The counter is then seeded from the highest
sequence of each library, so the next write can never collide with a
backfilled row.
Idempotent: it is safe to run on every start.
Sourcepub async fn migrate_snippet_visible_at(&self) -> DbResult<bool>
pub async fn migrate_snippet_visible_at(&self) -> DbResult<bool>
Add the visible_at cursor column to an existing database.
The column carries the delta cursor position of a row; updated_at
keeps the client’s logical modification time. Existing rows are
backfilled with their current updated_at, so a migrated database
selects exactly the same rows as before the migration and every
client’s stored cursor stays valid.
pub async fn migrate_plaintext_api_keys(&self) -> DbResult<usize>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Database
impl !UnwindSafe for Database
impl Forget for Database
impl Freeze for Database
impl Move for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnsafeUnpin for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request