pub struct Transaction { /* private fields */ }
Expand description

Transaction object passed to the closure via Client::transaction() method

The Transaction object must be dropped by the end of the closure execution.

All database queries in transaction should be executed using methods on this object instead of using original Client instance.

Implementations§

source§

impl Transaction

source

pub fn iteration(&self) -> u32

Zero-based iteration (attempt) number for the current transaction

First attempt gets iteration = 0, second attempt iteration = 1, etc.

source

pub async fn query<R, A>( &mut self, query: &str, arguments: &A ) -> Result<Vec<R>, Error>where A: QueryArgs, R: QueryResult,

Execute a query and return a collection of results.

You will usually have to specify the return type for the query:

let greeting = pool.query::<String, _>("SELECT 'hello'", &());
// or
let greeting: Vec<String> = pool.query("SELECT 'hello'", &());

This method can be used with both static arguments, like a tuple of scalars, and with dynamic arguments edgedb_protocol::value::Value. Similarly, dynamically typed results are also supported.

source

pub async fn query_single<R, A>( &mut self, query: &str, arguments: &A ) -> Result<Option<R>, Error>where A: QueryArgs, R: QueryResult,

Execute a query and return a single result

You will usually have to specify the return type for the query:

let greeting = pool.query_single::<String, _>("SELECT 'hello'", &());
// or
let greeting: Option<String> = pool.query_single(
    "SELECT 'hello'",
    &()
);

This method can be used with both static arguments, like a tuple of scalars, and with dynamic arguments edgedb_protocol::value::Value. Similarly, dynamically typed results are also supported.

source

pub async fn query_required_single<R, A>( &mut self, query: &str, arguments: &A ) -> Result<R, Error>where A: QueryArgs, R: QueryResult,

Execute a query and return a single result

The query must return exactly one element. If the query returns more than one element, a ResultCardinalityMismatchError is raised. If the query returns an empty set, a NoDataError is raised.

You will usually have to specify the return type for the query:

let greeting = pool.query_required_single::<String, _>(
    "SELECT 'hello'",
    &(),
);
// or
let greeting: String = pool.query_required_single(
    "SELECT 'hello'",
    &(),
);

This method can be used with both static arguments, like a tuple of scalars, and with dynamic arguments edgedb_protocol::value::Value. Similarly, dynamically typed results are also supported.

source

pub async fn query_json( &mut self, query: &str, arguments: &impl QueryArgs ) -> Result<Json, Error>

Execute a query and return the result as JSON.

source

pub async fn query_single_json( &mut self, query: &str, arguments: &impl QueryArgs ) -> Result<Option<Json>, Error>

Execute a query and return a single result as JSON.

The query must return exactly one element. If the query returns more than one element, a ResultCardinalityMismatchError is raised.

source

pub async fn query_required_single_json( &mut self, query: &str, arguments: &impl QueryArgs ) -> Result<Json, Error>

Execute a query and return a single result as JSON.

The query must return exactly one element. If the query returns more than one element, a ResultCardinalityMismatchError is raised. If the query returns an empty set, a NoDataError is raised.

source

pub async fn execute<A>( &mut self, query: &str, arguments: &A ) -> Result<(), Error>where A: QueryArgs,

Execute a query and don’t expect result

This method can be used with both static arguments, like a tuple of scalars, and with dynamic arguments edgedb_protocol::value::Value. Similarly, dynamically typed results are also supported.

Trait Implementations§

source§

impl Debug for Transaction

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Transaction

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V