pub struct SyncHandle<'db> { /* private fields */ }Expand description
동기 핸들 — db.run_sync() 반환 타입 (명세 §5.0).
모든 작업은 read/write 통합 풀에서 커넥션을 체크아웃한다.
With the live feature, SQL classification is conservative. PRAGMA
statements, including read-only forms, trigger full invalidation because
SQLite state-changing forms cannot be distinguished reliably by the parser.
Implementations§
Source§impl<'db> SyncHandle<'db>
impl<'db> SyncHandle<'db>
Sourcepub fn query_one<T: FromRow, P: Params>(
&self,
sql: &str,
params: P,
) -> Result<T>
pub fn query_one<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<T>
정확히 1건 조회 — 0건이면 Error::NotFound
Sourcepub fn query_optional<T: FromRow, P: Params>(
&self,
sql: &str,
params: P,
) -> Result<Option<T>>
pub fn query_optional<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Option<T>>
0~1건 조회
Sourcepub fn query_scalar<T: FromSql, P: Params>(
&self,
sql: &str,
params: P,
) -> Result<T>
pub fn query_scalar<T: FromSql, P: Params>( &self, sql: &str, params: P, ) -> Result<T>
스칼라 1건 조회
Sourcepub fn query_all<T: FromRow, P: Params>(
&self,
sql: &str,
params: P,
) -> Result<Vec<T>>
pub fn query_all<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Vec<T>>
N건 조회
Sourcepub fn transaction<R>(
&self,
f: impl FnOnce(&mut Tx<'_>) -> Result<R>,
) -> Result<R>
pub fn transaction<R>( &self, f: impl FnOnce(&mut Tx<'_>) -> Result<R>, ) -> Result<R>
클로저 트랜잭션 (명세 §5.5) — 에러 시 롤백, 성공 시 커밋
Sourcepub fn with_connection<R>(
&self,
f: impl FnOnce(&Connection) -> Result<R>,
) -> Result<R>
pub fn with_connection<R>( &self, f: impl FnOnce(&Connection) -> Result<R>, ) -> Result<R>
Runs a closure with one exclusively checked-out read/write connection.
Do not acquire another connection from the same database inside the closure when every pooled connection may already be checked out. Doing so can block indefinitely (or until the configured queue timeout) because the outer checkout cannot return.
With the live feature, direct writes are observed through SQLite’s
update hook. SQLite does not invoke that hook for every change: notably,
truncate-optimized DELETE statements and changes to WITHOUT ROWID
tables may be missed. Use the handle’s SQL methods when live-query
invalidation must be guaranteed.
Installing an SQLite preupdate_hook replaces roomrs’ live-query hook on
that connection. With the live feature, call [Self::rearm_hooks]
afterwards.
Trait Implementations§
Source§impl<'db> Clone for SyncHandle<'db>
impl<'db> Clone for SyncHandle<'db>
Source§fn clone(&self) -> SyncHandle<'db>
fn clone(&self) -> SyncHandle<'db>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<'db> Copy for SyncHandle<'db>
Source§impl Execute for SyncHandle<'_>
impl Execute for SyncHandle<'_>
fn run_all<T: FromRow + Send + 'static>( self, sql: String, params: Vec<Value>, ) -> Result<Vec<T>>
fn run_optional<T: FromRow + Send + 'static>( self, sql: String, params: Vec<Value>, ) -> Result<Option<T>>
fn run_one<T: FromRow + Send + 'static>( self, sql: String, params: Vec<Value>, ) -> Result<T>
fn run_scalar(self, sql: String, params: Vec<Value>) -> Result<i64>
Source§impl SqlContext for SyncHandle<'_>
impl SqlContext for SyncHandle<'_>
Source§fn ctx_transaction<R>(&self, f: impl FnOnce(&Tx<'_>) -> Result<R>) -> Result<R>
fn ctx_transaction<R>(&self, f: impl FnOnce(&Tx<'_>) -> Result<R>) -> Result<R>
풀-바운드 트랜잭션 — BEGIN/COMMIT (에러 시 롤백)