pub trait DatabaseService: Send + Sync {
// Required methods
fn execute<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<usize, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn query_one<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
where T: Send + 'static + 'async_trait,
F: Fn(&Row<'_>) -> SqliteResult<T> + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn query_optional<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, String>> + Send + 'async_trait>>
where T: Send + 'static + 'async_trait,
F: Fn(&Row<'_>) -> SqliteResult<T> + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn query_many<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, String>> + Send + 'async_trait>>
where T: Send + 'static + 'async_trait,
F: Fn(&Row<'_>) -> SqliteResult<T> + Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn transaction<'life0, 'async_trait, F, T>(
&'life0 self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
where F: FnOnce(&mut Transaction<'_>) -> Result<T, String> + Send + 'static + 'async_trait,
T: Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn transaction_without_foreign_keys<'life0, 'async_trait, F, T>(
&'life0 self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
where F: FnOnce(&mut Transaction<'_>) -> Result<T, String> + Send + 'static + 'async_trait,
T: Send + 'static + 'async_trait,
Self: 'async_trait,
'life0: 'async_trait;
fn insert<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn execute_detached(&self, query: Query);
}Expand description
Database service trait - abstraction over database operations
Required Methods§
Sourcefn execute<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<usize, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<usize, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute a query that doesn’t return results (INSERT, UPDATE, DELETE)
Sourcefn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute a batch of SQL statements (for migrations)
Sourcefn query_one<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
fn query_one<'life0, 'async_trait, T, F>( &'life0 self, query: Query, mapper: F, ) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
Query a single row
Sourcefn query_optional<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<Option<T>, String>> + Send + 'async_trait>>
fn query_optional<'life0, 'async_trait, T, F>( &'life0 self, query: Query, mapper: F, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, String>> + Send + 'async_trait>>
Query a single optional row
Sourcefn query_many<'life0, 'async_trait, T, F>(
&'life0 self,
query: Query,
mapper: F,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, String>> + Send + 'async_trait>>
fn query_many<'life0, 'async_trait, T, F>( &'life0 self, query: Query, mapper: F, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, String>> + Send + 'async_trait>>
Query multiple rows
Sourcefn transaction<'life0, 'async_trait, F, T>(
&'life0 self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
fn transaction<'life0, 'async_trait, F, T>( &'life0 self, f: F, ) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
Run a transaction with multiple operations
Sourcefn transaction_without_foreign_keys<'life0, 'async_trait, F, T>(
&'life0 self,
f: F,
) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
fn transaction_without_foreign_keys<'life0, 'async_trait, F, T>( &'life0 self, f: F, ) -> Pin<Box<dyn Future<Output = Result<T, String>> + Send + 'async_trait>>
Run a transaction with foreign-key enforcement switched off for its duration only.
PRAGMA foreign_keys is per connection and is a no-op inside a
transaction, so it has to be flipped around the BEGIN/COMMIT — and
all of that must happen as one job on the writer, or any other write
that got in between would run unchecked too.
Sourcefn insert<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert<'life0, 'async_trait>(
&'life0 self,
query: Query,
) -> Pin<Box<dyn Future<Output = Result<i64, String>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Execute an INSERT and return the rowid of the row it inserted.
The rowid is read in the same job as the insert. Reading it with a second call would race every other write, returning someone else’s id.
Sourcefn execute_detached(&self, query: Query)
fn execute_detached(&self, query: Query)
Queue a write without waiting for it — for best-effort bookkeeping (an LRU access time) that must not hold up the caller. It still runs in order with every other write; failures are only logged.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.