pub struct Client { /* private fields */ }
Expand description
A database connection client.
This is the struct used to interact with the database. Typically, you will
use the connect()
function to create this struct, or
with a Builder
that you pass to
Client::new()
.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(builder: Config) -> Client
pub fn new(builder: Config) -> Client
Create a new connection pool.
Note this does not create a connection immediately.
Use ensure_connected()
to establish a
connection and verify that the connection is usable.
Sourcepub async fn close(&self)
pub async fn close(&self)
Start shutting down the connection pool.
Note that this waits for all connections to be released when called for the first time. But if it is called multiple times concurrently, only the first call will wait and subsequent call will exit immediately.
Sourcepub async fn ensure_connected(&self) -> Result<(), Error>
pub async fn ensure_connected(&self) -> Result<(), Error>
Ensure that there is at least one working connection to the pool.
This can be used at application startup to ensure that you have a working connection.
Sourcepub async fn query<R, A>(
&self,
request: &str,
arguments: &A,
) -> Result<Vec<R>, Error>where
A: QueryArgs,
R: QueryResult,
pub async fn query<R, A>(
&self,
request: &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>(
&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 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>(
&self,
request: &str,
arguments: &A,
) -> Result<Json, Error>where
A: QueryArgs,
pub async fn query_json<A>(
&self,
request: &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>(
&self,
request: &str,
arguments: &A,
) -> Result<Json, Error>where
A: QueryArgs,
pub async fn query_single_json<A>(
&self,
request: &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>(
&self,
request: &str,
arguments: &A,
) -> Result<ExecuteResult, Error>where
A: QueryArgs,
pub async fn execute<A>(
&self,
request: &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.