Skip to main content

PgTransaction

Struct PgTransaction 

Source
pub struct PgTransaction { /* private fields */ }
Expand description

A PostgreSQL transaction that holds exclusive access to the client for the duration of the transaction scope.

§Preferred cleanup

Call Transaction::commit or Transaction::rollback to end the transaction explicitly. If neither is called before this value is dropped, the Drop implementation attempts to schedule a ROLLBACK on the current Tokio runtime (best-effort). If no runtime is reachable the connection is simply released; the server will clean up via connection reset.

Implementations§

Source§

impl PgTransaction

Source

pub async fn savepoint_pg(&mut self, name: &str) -> Result<(), PgError>

Create a savepoint with the given name.

The name must consist only of ASCII alphanumeric characters and underscores ([a-zA-Z0-9_]). This restriction prevents SQL injection because savepoint names cannot be parameterized in the PostgreSQL wire protocol.

§Errors

Returns PgError::Notify if the name is empty or contains unsafe characters. Returns PgError::Postgres on wire-level errors.

Source

pub async fn rollback_to_savepoint_pg( &mut self, name: &str, ) -> Result<(), PgError>

Roll back to a savepoint without releasing it.

The savepoint remains active after this call; you can roll back to it again or release it with PgTransaction::release_savepoint_pg.

§Errors

Returns PgError::Notify if the name is invalid or the transaction has already been consumed. Returns PgError::Postgres on server errors (e.g. the named savepoint does not exist).

Source

pub async fn release_savepoint_pg(&mut self, name: &str) -> Result<(), PgError>

Release (remove) a savepoint.

All savepoints created after the named savepoint are also removed.

§Errors

Returns PgError::Notify if the name is invalid or the transaction has already been consumed. Returns PgError::Postgres on server errors (e.g. the named savepoint does not exist).

Trait Implementations§

Source§

impl Drop for PgTransaction

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
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 Transaction for PgTransaction

Source§

fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<u64, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a DML/DDL statement within the transaction.
Source§

fn query<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, sql: &'life1 str, params: &'life2 [&'life3 dyn ToSqlValue], ) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Execute a SELECT statement within the transaction.
Source§

fn commit<'async_trait>( self: Box<Self>, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,

Commit all changes made within this transaction.
Source§

fn rollback<'async_trait>( self: Box<Self>, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait,

Roll back all changes made within this transaction.
Source§

fn savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create a named savepoint within the transaction. Read more
Source§

fn release_savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Release (discard) a named savepoint. Read more
Source§

fn rollback_to_savepoint<'life0, 'life1, 'async_trait>( &'life0 mut self, name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), OxiSqlError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Roll back the transaction to the named savepoint, undoing all changes made after the savepoint was created without ending the transaction. Read more
Source§

fn query_stream<'a>( &'a mut self, sql: &'a str, params: &'a [&'a dyn ToSqlValue], ) -> Pin<Box<dyn Stream<Item = Result<Row, OxiSqlError>> + Send + 'a>>

Execute a SELECT within the transaction and return rows as an async stream. Read more

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more