Client class
Represents a pool of connections to the database, provides methods to run queries and manages the context in which queries are run (ie. setting globals, modifying session config, etc.)
The Client class cannot be instantiated directly, and is instead created by the createClient() function. Since creating a client is relatively expensive, it is recommended to create a single Client instance that you can then import and use across your app.
The with*()
methods return a new Client instance derived from this
instance. The derived instances all share the pool of connections managed
by the root Client instance (ie. the instance created by createClient()),
so calling the ensureConnected(), close() or terminate() methods on
any of these instances will affect them all.
- Implemented types
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isClosed → bool
-
Whether close() (or terminate()) has been called on the client.
If isClosed is
true
, subsequent calls to query methods will fail.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Close the client's open connections gracefully.
-
ensureConnected(
) → Future< void> - If the client does not yet have any open connections in its pool, attempts to open a connection, else returns immediately.
-
execute(
String query, [dynamic args]) → Future< void> -
Executes a query, returning no result.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query(
String query, [dynamic args]) → Future< List> -
Executes a query, returning a
List
of results.override -
queryJSON(
String query, [dynamic args]) → Future< String> -
Executes a query, returning the result as a JSON encoded
String
.override -
queryRequiredSingle(
String query, [dynamic args]) → Future -
Executes a query, returning a single (non-
null
) result.override -
queryRequiredSingleJSON(
String query, [dynamic args]) → Future< String> -
Executes a query, returning the result as a JSON encoded
String
.override -
querySingle(
String query, [dynamic args]) → Future -
Executes a query, returning a single (possibly
null
) result.override -
querySingleJSON(
String query, [dynamic args]) → Future< String> -
Executes a query, returning the result as a JSON encoded
String
.override -
terminate(
) → void - Immediately closes all connections in the client's pool, without waiting for any running queries to finish.
-
toString(
) → String -
A string representation of this object.
inherited
-
transaction<
T> (Future< T> action(Transaction)) → Future<T> - Execute a retryable transaction.
-
withConfig(
Map< String, Object> config) → Client - Returns a new Client instance with the specified client session configuration.
-
withGlobals(
Map< String, dynamic> globals) → Client - Returns a new Client instance with the specified global values.
-
withModuleAliases(
Map< String, String> aliases) → Client - Returns a new Client instance with the specified module aliases.
-
withRetryOptions(
RetryOptions options) → Client - Returns a new Client instance with the specified RetryOptions.
-
withSession(
Session session) → Client - Returns a new Client instance with the specified Session options.
-
withTransactionOptions(
TransactionOptions options) → Client - Returns a new Client instance with the specified TransactionOptions.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited