Skip to main content

Tx

Struct Tx 

Source
pub struct Tx<'db> { /* private fields */ }
Expand description

A synchronous transaction bound to its checked-out connection and thread.

Tx is intentionally not Send: SQLite transaction work and rollback must remain on the checkout owner thread. Use the async handle to schedule database work instead of moving a synchronous transaction between threads. An uncommitted transaction is rolled back when dropped. With the live feature, PRAGMA statements conservatively accumulate full invalidation, including read-only forms.

Implementations§

Source§

impl Tx<'_>

Source

pub fn commit(self) -> Result<()>

커밋 — 이 Tx 소비. 성공 시 누적 무효화 방출 (명세 §9.2 — commit API 성공 반환 후)

Source

pub fn rollback(self) -> Result<()>

명시 롤백 — 이 Tx 소비

Source

pub fn execute<P: Params>(&self, sql: &str, params: P) -> Result<u64>

쓰기 실행 (트랜잭션 커넥션)

Source

pub fn query_one<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<T>

정확히 1건 조회

Source

pub fn query_optional<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Option<T>>

0~1건 조회

Source

pub fn query_scalar<T: FromSql, P: Params>( &self, sql: &str, params: P, ) -> Result<T>

스칼라 1건 조회

Source

pub fn query_all<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Vec<T>>

N건 조회

Source

pub fn execute_batch(&self, sql: &str) -> Result<()>

배치 실행 — 여러 문장 세미콜론 구분 (마이그레이션·일괄 write용).

Batch writes participate in invalidation (M-2): affected tables are collected per statement and emitted after the transaction commits. A statement that cannot be parsed degrades to a conservative full invalidation.

Source

pub fn savepoint<R>(&self, f: impl FnOnce(&Tx<'_>) -> Result<R>) -> Result<R>

중첩 트랜잭션 — SAVEPOINT (명세 §5.9). 실패 시 savepoint까지만 롤백, 외부 트랜잭션은 계속된다. 무효화 누적도 레벨 단위 — 롤백된 write는 방출하지 않는다 (L-8)

Trait Implementations§

Source§

impl Drop for Tx<'_>

Source§

fn drop(&mut self)

미커밋 drop = 롤백 — 실패해도 panic하지 않는다(커넥션 반납이 우선)

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl SqlContext for Tx<'_>

Source§

fn ctx_transaction<R>(&self, f: impl FnOnce(&Tx<'_>) -> Result<R>) -> Result<R>

tx-바운드 트랜잭션 = 중첩 savepoint (명세 §5.9)

Source§

fn ctx_execute<P: Params>(&self, sql: &str, params: P) -> Result<u64>

쓰기 실행 — 영향 행 수
Source§

fn ctx_insert<P: Params>(&self, sql: &str, params: P) -> Result<i64>

INSERT — 새 rowid
Source§

fn ctx_query_all<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Vec<T>>

N건 조회
Source§

fn ctx_query_optional<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<Option<T>>

0~1건 조회
Source§

fn ctx_query_scalar<T: FromSql, P: Params>( &self, sql: &str, params: P, ) -> Result<T>

스칼라 1건 조회
Source§

fn ctx_query_one<T: FromRow, P: Params>( &self, sql: &str, params: P, ) -> Result<T>

정확히 1건 조회 (0건 = NotFound)

Auto Trait Implementations§

§

impl<'db> !Freeze for Tx<'db>

§

impl<'db> !RefUnwindSafe for Tx<'db>

§

impl<'db> !Send for Tx<'db>

§

impl<'db> !Sync for Tx<'db>

§

impl<'db> !UnwindSafe for Tx<'db>

§

impl<'db> Unpin for Tx<'db>

§

impl<'db> UnsafeUnpin for Tx<'db>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.