Struct edgedb_tokio::Transaction
source · 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
impl Transaction
sourcepub fn iteration(&self) -> u32
pub fn iteration(&self) -> u32
Zero-based iteration (attempt) number for the current transaction
First attempt gets iteration = 0
, second attempt iteration = 1
,
etc.
sourcepub async fn query<R, A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Vec<R>, Error>where
A: QueryArgs,
R: QueryResult,
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.
sourcepub async fn query_single<R, A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Option<R>, Error>where
A: QueryArgs,
R: QueryResult,
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.
sourcepub async fn query_required_single<R, A>(
&mut self,
query: &str,
arguments: &A
) -> Result<R, Error>where
A: QueryArgs,
R: QueryResult,
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.
sourcepub async fn query_json(
&mut self,
query: &str,
arguments: &impl QueryArgs
) -> Result<Json, Error>
pub async fn query_json( &mut self, query: &str, arguments: &impl QueryArgs ) -> Result<Json, Error>
Execute a query and return the result as JSON.
sourcepub async fn query_single_json(
&mut self,
query: &str,
arguments: &impl QueryArgs
) -> Result<Option<Json>, Error>
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.
sourcepub async fn query_required_single_json(
&mut self,
query: &str,
arguments: &impl QueryArgs
) -> Result<Json, Error>
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.
sourcepub async fn execute<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<(), Error>where
A: QueryArgs,
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.