DatabaseAccessor<T extends GeneratedDatabase> class Null safety

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
connection DatabaseConnection
The database connection used by this DatabaseConnectionUser.
@protected, final, inherited
executor QueryExecutor
The executor to use when queries are executed.
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
resolvedEngine DatabaseConnectionUser
A, potentially more specific, database engine based on the Zone context. [...]
@internal, read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
streamQueries → StreamQueryStore
Manages active streams from select statements.
@protected, @visibleForTesting, read-only, inherited
typeSystem SqlTypeSystem
The type system to use with this database. The type system is responsible for mapping Dart objects into sql expressions and vice-versa.
read-only, inherited

Methods

$write(Component component, {bool? hasMultipleTables}) GenerationContext
Will be used by generated code to resolve inline Dart components in sql.
@protected, inherited
$writeInsertable(TableInfo<Table, dynamic> table, Insertable insertable) GenerationContext
Writes column names and VALUES for an insert statement. [...]
@protected, inherited
alias<T extends Table, D>(TableInfo<T, D> table, String alias) → T
Creates a copy of the table with an alias so that it can be used in the same query more than once. [...]
inherited
batch(_BatchRunner runInBatch) Future<void>
Runs statements inside a batch. [...]
inherited
createStream(QueryStreamFetcher stmt) Stream<List<Map<String, Object?>>>
Creates and auto-updating stream from the given select statement. This method should not be used directly.
inherited
customInsert(String query, {List<Variable> variables = const [], Set<TableInfo<Table, dynamic>>? updates}) Future<int>
Executes a custom insert statement and returns the last inserted rowid. [...]
inherited
customSelect(String query, {List<Variable> variables = const [], Set<ResultSetImplementation> readsFrom = const {}}) Selectable<QueryRow>
Creates a custom select statement from the given sql query. To run the query once, use Selectable.get. For an auto-updating streams, set the set of tables the ready readsFrom and use Selectable.watch. If you know the query will never emit more than one row, you can also use getSingle and SelectableUtils.watchSingle which return the item directly without wrapping it into a list. [...]
inherited
customSelectQuery(String query, {List<Variable> variables = const [], Set<ResultSetImplementation> readsFrom = const {}}) Selectable<QueryRow>
Creates a custom select statement from the given sql query. To run the query once, use Selectable.get. For an auto-updating streams, set the set of tables the ready readsFrom and use Selectable.watch. If you know the query will never emit more than one row, you can also use getSingle and watchSingle which return the item directly without wrapping it into a list. [...]
@Deprecated('Renamed to customSelect'), inherited
customStatement(String statement, [List? args]) Future<void>
Executes the custom sql statement on the database.
inherited
customUpdate(String query, {List<Variable> variables = const [], Set<TableInfo<Table, 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> variables = const [], Set<TableInfo<Table, dynamic>>? updates, UpdateKind? updateKind}) Future<List<QueryRow>>
Runs a INSERT, UPDATE or DELETE statement returning rows. [...]
inherited
delete<T extends Table, D>(TableInfo<T, D> table) DeleteStatement<T, D>
Starts a DeleteStatement that can be used to delete rows from a table. [...]
inherited
doWhenOpened<T>(FutureOr<T> fn(QueryExecutor e)) Future<T>
Performs the async fn after this executor is ready, or directly if it's already ready. [...]
inherited
into<T extends Table, D>(TableInfo<T, D> table) InsertStatement<T, D>
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<TableInfo<Table, dynamic>> tables) → void
Marks the tables as updated. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyUpdates(Set<TableUpdate> updates) → void
Dispatches the set of updates to the stream query manager. [...]
inherited
select<T extends HasResultSet, R>(ResultSetImplementation<T, R> table, {bool distinct = false}) SimpleSelectStatement<T, R>
Starts a query on the given table. [...]
inherited
selectOnly<T extends HasResultSet, R>(ResultSetImplementation<T, R> table, {bool distinct = false}) JoinedSelectStatement<T, R>
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()) Future<T>
Executes action in a transaction, which means that all its queries and updates will be called atomically. [...]
inherited
update<Tbl extends Table, R>(TableInfo<Tbl, R> table) UpdateStatement<Tbl, R>
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