Trait edgedb_client::Executor
source · [−]pub trait Executor: Sealed { }
Expand description
The main trait that allows query execution.
Note that compared to Client this trait has &mut self
for query methods.
This is because we need to support Executor for a transaction.
To overcome this issue for Client you can either use inherent methods on
the pool rather than this trait or just clone it (cloning Client is cheap):
do_query(&mut global_pool_reference.clone())?;
Due to limitations of the Rust type system, the query methods are part of
the inherent implementation for dyn Executor
, not in the trait
itself. This should not be a problem in most cases.
This trait is sealed (no imlementation can be done outside of this crate), since we don’t want to expose too many implementation details for now.
Implementations
sourceimpl dyn Executor + '_
impl dyn Executor + '_
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<R, Error> where
A: QueryArgs,
R: QueryResult,
pub async fn query_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.
You will usually have to specify the return type for the query:
let greeting = pool.query_single::<String, _>("SELECT 'hello'", &());
// or
let greeting: String = pool.query_single("SELECT 'hello'", &());
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.
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<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Json, Error> where
A: QueryArgs,
pub async fn query_json<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Json, Error> where
A: QueryArgs,
Execute a query and return the result as JSON.
sourcepub async fn query_single_json<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Json, Error> where
A: QueryArgs,
pub async fn query_single_json<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<Json, Error> where
A: QueryArgs,
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<ExecuteResult, Error> where
A: QueryArgs,
pub async fn execute<A>(
&mut self,
query: &str,
arguments: &A
) -> Result<ExecuteResult, Error> where
A: QueryArgs,
Execute one or more EdgeQL commands.
Note that if you want the results of query, use
query()
or query_single()
instead.