DatabaseAccessor<T extends GeneratedDatabase> class abstract base

Class that runs queries to a subset of all available queries in a database.

This comes in handy to structure large amounts of database code better: The migration logic can live in the main GeneratedDatabase class, but code can be extracted into DatabaseAccessors outside of that database. For details on how to write a dao, see DriftAccessor. T should be the associated database class you wrote.

Inheritance
Available extensions

Constructors

DatabaseAccessor(T attachedDatabase)
Used internally by drift

Properties

attachedDatabase → T
The main database instance for this dao
final
db → T

Available on DatabaseAccessor<T>, provided by the OldDbFieldInDatabaseAccessor extension

The generated database that this dao is attached to.
no setter
dialect → DriftDialect
The DriftDialect implementation for this opened database.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

$expandVar(int start, int amount) → String
Used by generated code to expand array variables.
inherited
$write(SqlComponent component, {bool? hasMultipleTables, int? startIndex}) → StatementBuffer
Will be used by generated code to resolve inline Dart components in sql by writing the component.
inherited
$writeInsertable(GeneratedTable<Object, GeneratedTable<Object, dynamic>> table, Insertable insertable, {int? startIndex}) → StatementBuffer
Writes column names and VALUES for an insert statement.
inherited
$writeUpdateInsertable(GeneratedTable<Object, GeneratedTable<Object, dynamic>> table, Insertable insertable, {int? startIndex}) → StatementBuffer
Writes column names and values for an update statement.
inherited
alias<Row extends Object, RS extends ResultSet<Row, RS>>(ResultSet<Row, RS> table, String alias) → RS
Creates a copy of the table with an alias so that it can be used in the same query more than once.
inherited
batch(FutureOr<void> runInBatch(Batch batch)) → Future<BatchResult>
Runs statements inside a batch.
inherited
count<Row extends Object, RS extends ResultSet<Row, RS>>(ResultSet<Row, RS> table, {Expression<bool> where(RS row)?}) → SingleSelectable<int>
Counts the amount of rows in a table.
inherited
currentSession() → Future<DriftSession>
The current DriftSession that this database will use to run statements.
inherited
customInsert(String query, {List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>>? updates}) → Future<int>
Executes a custom insert statement and returns the last inserted rowid.
inherited
customSelect(String query, {List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>> readsFrom = const {}, bool isReadOnly = true}) → Selectable<CustomRow>
Creates a custom select statement from the given sql query.
inherited
customSelectMapped<T>({required String query, required T Function(RawRow) createMapper(RawResultSet), List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>> readsFrom = const {}, bool isReadOnly = true}) → Selectable<T>
A variant of customSelect that uses createMapper to obtain a select statement for which rows can be mapped to a custom Dart type.
inherited
customSelectMappedAsync<T>({required String query, required Future<T> Function(RawRow) createMapper(RawResultSet), List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>> readsFrom = const {}, bool isReadOnly = true}) → Selectable<T>
Like customSelectMapped, but allows createMapper to be asynchronous and to fire off additional queries.
inherited
customStatement(String statement, [List<Variable<Object>> args = const []]) → Future<void>
Executes the custom sql statement on the database.
inherited
customUpdate(String query, {List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>>? updates, UpdateKind? updateKind}) → Future<int>
Executes a custom delete or update statement and returns the amount of rows that have been changed. You can use the updates parameter so that drift knows which tables are affected by your query. All select streams that depend on a table specified there will then update their data. For more accurate results, you can also set the updateKind parameter to UpdateKind.delete or UpdateKind.update. This is optional, but can improve the accuracy of query updates, especially when using triggers.
inherited
customWriteReturning(String query, {List<Variable<Object>> variables = const [], Set<SchemaEntityWithResultSet<Object, ResultSet<Object, dynamic>>>? updates, UpdateKind? updateKind}) → Future<RawResultSet>
Runs a INSERT, UPDATE or DELETE statement returning rows.
inherited
delete<Row extends Object, RS extends GeneratedTable<Row, RS>>(GeneratedTable<Row, RS> table) → DeleteStatement<Row, RS>
Starts a DeleteStatement that can be used to delete rows from a table.
inherited
doWhenOpened<T>(FutureOr<T> fn(DriftSession e)) → Future<T>
Performs the async fn after this executor is ready, or directly if it's already ready.
inherited
exclusively<T>(Future<T> action()) → Future<T>
Obtains an exclusive lock on the current database context, runs action in it and then releases the lock.
inherited
initialize() → Future<void>
Waits for the database to be initialized, meaning that all connections are fully set up and migrations ran.
inherited
into<Row extends Object, RS extends GeneratedTable<Row, RS>>(GeneratedTable<Row, RS> table) → InsertStatement<Row, RS>
Starts an InsertStatement for a given table. You can use that statement to write data into the table by using InsertStatement.insert.
inherited
markTablesUpdated(Iterable<GeneratedTable<Object, GeneratedTable<Object, dynamic>>> tables) → void
Marks the tables as updated.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyUpdates(Set<TableUpdate> updates) → void
Dispatches the set of updates to the stream query manager.
inherited
runStatement(SqlStatement statement) → Future<QueryResult>
Runs the compiled SqlStatement on the currentSession.
inherited
runWithInterceptor<T>(Future<T> action(), {required QueryInterceptor interceptor}) → Future<T>
Executes action with calls intercepted by the given interceptor
inherited
select<Row extends Object, RS extends ResultSet<Row, RS>>(ResultSet<Row, RS> table, {bool distinct = false}) → SingleTableSelectStatement<Row, RS>
Starts a query on the given table.
inherited
selectExpressions(Iterable<Expression<Object>> columns) → SelectStatement
Creates a select statement without a FROM clause selecting columns.
inherited
selectOnly(ResultSet<Object, ResultSet<Object, dynamic>> table, {bool distinct = false}) → SelectStatement
Starts a complex statement on table that doesn't necessarily use all of table's columns.
inherited
tableUpdates([TableUpdateQuery query = const TableUpdateQuery.any()]) → Stream<Set<TableUpdate>>
Listen for table updates reported through notifyUpdates.
inherited
toString() → String
A string representation of this object.
inherited
transaction<T>(Future<T> action(), {TransactionOptions? options}) → Future<T>
Executes action in a transaction, which means that all its queries and updates will be called atomically.
inherited
update<Row extends Object, RS extends GeneratedTable<Row, RS>>(GeneratedTable<Row, RS> table) → UpdateStatement<Row, RS>
Starts an UpdateStatement for the given table. You can use that statement to update individual rows in that table by setting a where clause on that table and then use UpdateStatement.write.
inherited

Operators

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