Struct edgedb_client::Client [−][src]
pub struct Client { /* fields omitted */ }
Expand description
A database connection pool
This is main way how to interact with the database. Usually it’s created using connect function.
Implementations
Create a new connection pool
Note this does not create any connection immediately.
Use ensure_connection()
to establish a
connection and verify that connection credentials are okay.
Start shutting down connection pool
Note: this waits for all connections to be released when called on the first call. But if multiple calls are executed concurrently only the first one will wait (subsequent ones will exit immediately).
Ensure that there is at least one working connection to the pool
This is often used at the start of the application to error out on invalid connection configuration earlier.
Execute a query returning a collection of results
Most of the times you have to specify 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 both with static arguments, like a tuple of
scalars. And with dynamic arguments edgedb_protocol::value::Value
.
Similarly dynamically typed results are also suported.
pub async fn query_single<R, A>(
&self,
request: &str,
arguments: &A
) -> Result<R, Error> where
A: QueryArgs,
R: QueryResult,
pub async fn query_single<R, A>(
&self,
request: &str,
arguments: &A
) -> Result<R, Error> where
A: QueryArgs,
R: QueryResult,
Execute a query returning a single result
Most of the times you have to specify return type for the query:
let greeting = pool.query::<String, _>("SELECT 'hello'", &());
// or
let greeting: String = pool.query("SELECT 'hello'", &());
The query must return exactly one element. If the query returns more
than one element, an
ResultCardinalityMismatchError
is raised, if it returns an empty set, an
NoDataError
is raised.
This method can be used both with static arguments, like a tuple of
scalars. And with dynamic arguments edgedb_protocol::value::Value
.
Similarly dynamically typed results are also suported.
Execute a query returning result as a JSON
Run a singleton-returning query and return its element in JSON
The query must return exactly one element. If the query returns more
than one element, an
ResultCardinalityMismatchError
is raised, if it returns an empty set, an
NoDataError
is raised.
Execute an EdgeQL command (or commands).
Note: If the results of query are desired, query()
or
query_single()
should be used instead.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
Blanket Implementations
Mutably borrows from an owned value. Read more