pub struct DbWriteConnection(/* private fields */);Expand description
Write pool. Single connection; serialises in-process writes so the SQLite writer lock is never contested from within one process.
Cross-process contention with other writers (e.g. the in-VM runtime)
still exists and is absorbed by the busy_timeout PRAGMA + the
retry-on-busy transaction helpers (added in a follow-up step).
Clone is cheap: the inner DatabaseConnection holds an Arc over
the underlying sqlx pool, so clones share the same single connection.
Implementations§
Source§impl DbWriteConnection
impl DbWriteConnection
Sourcepub fn new(inner: DatabaseConnection) -> Self
pub fn new(inner: DatabaseConnection) -> Self
Wrap a sea-orm connection as a write pool.
Sourcepub async fn open(
db_path: &Path,
connect_timeout: Duration,
busy_timeout: Duration,
) -> Result<Self, Error>
pub async fn open( db_path: &Path, connect_timeout: Duration, busy_timeout: Duration, ) -> Result<Self, Error>
Open a stand-alone single-connection write pool at db_path.
Used by callers that don’t need a paired read pool (e.g. the in-VM runtime, which only writes run records).
Sourcepub fn inner(&self) -> &DatabaseConnection
pub fn inner(&self) -> &DatabaseConnection
Borrow the underlying sea-orm connection.
Sourcepub async fn transaction<F, Fut, T, E>(&self, f: F) -> Result<T, E>where
F: Fn(DatabaseTransaction) -> Fut,
Fut: Future<Output = Result<(DatabaseTransaction, T), E>> + Send,
T: Send,
E: From<DbErr> + IsSqliteBusy,
pub async fn transaction<F, Fut, T, E>(&self, f: F) -> Result<T, E>where
F: Fn(DatabaseTransaction) -> Fut,
Fut: Future<Output = Result<(DatabaseTransaction, T), E>> + Send,
T: Send,
E: From<DbErr> + IsSqliteBusy,
Run a multi-statement atomic write inside a transaction with
automatic retry on SQLITE_BUSY / SQLITE_BUSY_SNAPSHOT. Use this
when you need several writes to commit (or roll back) as a unit.
Single-statement writes don’t need this — auto-commit .exec(db)
already retries via the ConnectionTrait impl below.
f is invoked once per attempt with a freshly opened transaction.
Return Ok((txn, value)) to commit, or any Err to roll back (the
helper drops the transaction on failure, which sea-orm rolls back).
The closure must be callable multiple times: clone owned data inside
the body so retries see fresh values.
Generic over the closure’s error type E so callers can return
app-level errors directly (e.g. MicrosandboxError) provided
E: From<DbErr> + IsSqliteBusy.
Trait Implementations§
Source§impl Clone for DbWriteConnection
impl Clone for DbWriteConnection
Source§fn clone(&self) -> DbWriteConnection
fn clone(&self) -> DbWriteConnection
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl ConnectionTrait for DbWriteConnection
impl ConnectionTrait for DbWriteConnection
Source§fn get_database_backend(&self) -> DbBackend
fn get_database_backend(&self) -> DbBackend
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_unprepared<'life0, 'life1, 'async_trait>(
&'life0 self,
sql: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<ExecResult, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn query_one<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn query_one<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Option<QueryResult>, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn query_all<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn query_all<'life0, 'async_trait>(
&'life0 self,
stmt: Statement,
) -> Pin<Box<dyn Future<Output = Result<Vec<QueryResult>, DbErr>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn support_returning(&self) -> bool
fn support_returning(&self) -> bool
RETURNING syntax on insert and updateSource§fn is_mock_connection(&self) -> bool
fn is_mock_connection(&self) -> bool
Auto Trait Implementations§
impl Freeze for DbWriteConnection
impl !RefUnwindSafe for DbWriteConnection
impl Send for DbWriteConnection
impl Sync for DbWriteConnection
impl Unpin for DbWriteConnection
impl UnsafeUnpin for DbWriteConnection
impl !UnwindSafe for DbWriteConnection
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 more