DatabaseConnection class

A database connection managed by drift. This consists of two components:

  • a QueryExecutor, which runs sql statements.
  • a StreamQueryStore, which dispatches table changes to listening queries, on which the auto-updating queries are based.
Implemented types
Available extensions

Constructors

DatabaseConnection(QueryExecutor executor, {StreamQueryStore? streamQueries, FutureOr<Object?> connectionData, bool closeStreamsSynchronously = false})
Constructs a raw database connection from the executor and optionally a specified streamQueries implementation to use.
DatabaseConnection.delayed(FutureOr<DatabaseConnection> connection, {SqlDialect dialect = SqlDialect.sqlite})
Database connection that is instantly available, but delegates work to a connection only available through a Future.
factory
DatabaseConnection.fromExecutor(QueryExecutor executor)
Constructs a DatabaseConnection from the QueryExecutor by using the default type system and a new StreamQueryStore.

Properties

connectionData → FutureOr<Object?>
Optional data attached to this connection.
final
dialect → SqlDialect
The SqlDialect to use for this database engine.
no setteroverride
executor → QueryExecutor
The executor to use when queries are executed.
final
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
streamQueries → StreamQueryStore
Manages active streams from select statements.
final

Methods

beginExclusive() → QueryExecutor
Returns a new QueryExecutor that, when first opened, takes an exclusive lock over this executor and prevents queries from running until it is closed.
override
beginTransaction() → TransactionExecutor
Starts a TransactionExecutor.
override
close() → Future<void>
Closes this database connection and releases all resources associated with it. Implementations should also handle close calls in a state where the database isn't open.
override
ensureOpen(QueryExecutorUser user) → Future<bool>
Opens the executor, if it has not yet been opened.
override
interceptWith(QueryInterceptor interceptor) → QueryExecutor

Available on QueryExecutor, provided by the ApplyInterceptor extension

Returns a QueryExecutor that will use this executor internally, but with calls intercepted by the given interceptor.
interceptWith(QueryInterceptor interceptor) → DatabaseConnection

Available on DatabaseConnection, provided by the ApplyInterceptorConnection extension

Returns a DatabaseConnection that will use the same stream queries as this, but replaces its executor by wrapping it with the interceptor.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
runBatched(BatchedStatements statements) → Future<void>
Prepares and runs statements.
override
runCustom(String statement, [List<Object?>? args]) → Future<void>
Runs a custom SQL statement without any variables. The result of that statement will be ignored.
override
runDelete(String statement, List<Object?> args) → Future<int>
Runs an delete statement and returns how many rows where affected.
override
runInsert(String statement, List<Object?> args) → Future<int>
Runs an insert statement with the given variables. Returns the row id or the auto_increment id of the inserted row.
override
runSelect(String statement, List<Object?> args) → Future<List<Map<String, Object?>>>
Runs a select statement with the given variables and returns the raw results.
override
runUpdate(String statement, List<Object?> args) → Future<int>
Runs an update statement with the given variables and returns how many rows where affected.
override
toString() → String
A string representation of this object.
inherited
withExecutor(QueryExecutor executor) → DatabaseConnection
Returns a database connection that is identical to this one, except that it uses the provided executor.

Operators

operator ==(Object other) → bool
The equality operator.
inherited