ScopedDatabase class
DriftDatabase storing MyUser scoped data.
- Inheritance
-
- Object
- DatabaseConnectionUser
- GeneratedDatabase
- ScopedDatabase
- Available extensions
- Annotations
-
- @DriftDatabase(tables: [Blocklist, CallCredentials, CallRectangles, ChatCredentials, ChatItems, ChatItemViews, ChatMembers, Chats, Drafts, Sessions, Users], queries: {'chatItemsAround' : '' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at <= :at ' 'ORDER BY at DESC LIMIT :before + 1) as a ' 'UNION ' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at > :at ' 'ORDER BY at ASC LIMIT :after) as b ' 'ORDER BY at ASC;', 'chatItemsAroundBottomless' : '' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at <= :at ' 'ORDER BY at DESC LIMIT :before + 1) as a ' 'UNION ' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at > :at ' 'ORDER BY at ASC) as b ' 'ORDER BY at ASC;', 'chatItemsAroundTopless' : '' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at <= :at ' 'ORDER BY at DESC) as a ' 'UNION ' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at > :at ' 'ORDER BY at ASC LIMIT :after) as b ' 'ORDER BY at ASC;', 'attachmentsAround' : '' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at <= :at AND chat_items.data LIKE \'%"attachments":[{%\' ' 'ORDER BY at DESC LIMIT :before + 1) as a ' 'UNION ' 'SELECT * FROM ' '(SELECT * FROM chat_item_views ' 'INNER JOIN chat_items ON chat_items.id = chat_item_views.chat_item_id ' 'WHERE chat_item_views.chat_id = :chat_id AND at > :at AND chat_items.data LIKE \'%"attachments":[{%\' ' 'ORDER BY at ASC LIMIT :after) as b ' 'ORDER BY at ASC;'})
Constructors
- ScopedDatabase(UserId userId, [QueryExecutor? e])
Properties
-
allSchemaEntities
→ List<
DatabaseSchemaEntity> -
A list of all
DatabaseSchemaEntity
that are specified in this database.no setterinherited -
allTables
→ Iterable<
TableInfo< Table, Object?> > -
A list of tables specified in this database.
no setterinherited
- attachedDatabase → GeneratedDatabase
-
The database class that this user is attached to.
no setterinherited
- blocklist → $BlocklistTable
-
latefinalinherited
- callCredentials → $CallCredentialsTable
-
latefinalinherited
- callRectangles → $CallRectanglesTable
-
latefinalinherited
- chatCredentials → $ChatCredentialsTable
-
latefinalinherited
- chatItems → $ChatItemsTable
-
latefinalinherited
- chatItemViews → $ChatItemViewsTable
-
latefinalinherited
- chatMembers → $ChatMembersTable
-
latefinalinherited
- chats → $ChatsTable
-
latefinalinherited
- connection → DatabaseConnection
-
The database connection used by this DatabaseConnectionUser.
finalinherited
- destructiveFallback → MigrationStrategy
-
Available on GeneratedDatabase, provided by the DestructiveMigrationExtension extension
Provides a destructive MigrationStrategy that will delete and then re-create all tables, triggers and indices.no setter - drafts → $DraftsTable
-
latefinalinherited
- executor → QueryExecutor
-
The executor to use when queries are executed.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- managers → $ScopedDatabaseManager
-
no setterinherited
- migration → MigrationStrategy
-
Defines the migration strategy that will determine how to deal with an
increasing schemaVersion. The default value only supports creating the
database by creating all tables known in this database. When you have
changes in your schema, you'll need a custom migration strategy to create
the new tables or change the columns.
no setteroverride
- options → DriftDatabaseOptions
-
The DriftDatabaseOptions to use for this database instance.
no setterinherited
- resolvedEngine → DatabaseConnectionUser
-
A, potentially more specific, database engine based on the Zone context.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schemaVersion → int
-
Specify the schema version of your database. Whenever you change or add
tables, you should bump this field and provide a migration strategy.
no setteroverride
- sessions → $SessionsTable
-
latefinalinherited
- streamQueries → StreamQueryStore
-
Manages active streams from select statements.
no setterinherited
- streamUpdateRules → StreamQueryUpdateRules
-
The collection of update rules contains information on how updates on
tables result in other updates, for instance due to a trigger.
no setterinherited
- typeMapping → SqlTypes
-
A SqlTypes mapping configuration to use when mapping values between Dart
and SQL.
latefinalinherited
- userId → UserId
-
UserId this ScopedDatabase is linked to.
final
- users → $UsersTable
-
latefinalinherited
Methods
-
$expandVar(
int start, int amount) → String -
Used by generated code to expand array variables.
inherited
-
$write(
Component component, {bool? hasMultipleTables, int? startIndex}) → GenerationContext -
Will be used by generated code to resolve inline Dart components in sql by
writing the
component
.inherited -
$writeInsertable(
TableInfo< Table, dynamic> table, Insertable insertable, {int? startIndex}) → GenerationContext -
Writes column names and
VALUES
for an insert statement.inherited -
accessor<
T extends DatabaseAccessor< (GeneratedDatabase> >T create(GeneratedDatabase)) → T -
Available on GeneratedDatabase, provided by the ReadDatabaseContainer extension
Find an accessor by itsname
in the database, or create it withcreate
. The result will be cached. -
alias<
T, D> (ResultSetImplementation< 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
-
attachmentsAround(
String chatId, PreciseDateTime at, double before, int after) → Selectable< AttachmentsAroundResult> -
inherited
-
batch(
FutureOr< void> runInBatch(Batch batch)) → Future<void> -
Runs statements inside a batch.
inherited
-
beforeOpen(
QueryExecutor executor, OpeningDetails details) → Future< void> -
A callbacks that runs after the database connection has been established,
but before any other query is sent.
inherited
-
chatItemsAround(
String chatId, PreciseDateTime at, double before, int after) → Selectable< ChatItemsAroundResult> -
inherited
-
chatItemsAroundBottomless(
String chatId, PreciseDateTime at, double before) → Selectable< ChatItemsAroundBottomlessResult> -
inherited
-
chatItemsAroundTopless(
String chatId, PreciseDateTime at, int after) → Selectable< ChatItemsAroundToplessResult> -
inherited
-
close(
) → Future< void> -
Closes this database and releases associated resources.
inherited
-
computeWithDatabase<
Ret> ({required FutureOr< Ret> computation(DB), required DB connect(DatabaseConnection)}) → Future<Ret> -
Available on DB, provided by the ComputeWithDriftIsolate extension
Spawns a short-lived isolate to run thecomputation
with a drift database. -
create(
) → Future< void> - Creates all tables, triggers, views, indexes and everything else defined in the database, if they don't exist.
-
createMigrator(
) → Migrator -
Creates a Migrator with the provided query executor. Migrators generate
sql statements to create or drop tables.
inherited
-
createStream<
T extends Object> (QueryStreamFetcher< T> stmt) → Stream<T> -
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<Object> >ResultSetImplementation> ? updates}) → Future<int> -
Executes a custom insert statement and returns the last inserted rowid.
inherited
-
customSelect(
String query, {List< Variable< variables = const [], Set<Object> >ResultSetImplementation> readsFrom = const {}}) → Selectable<QueryRow> -
Creates a custom select statement from the given sql
query
.inherited -
customSelectQuery(
String query, {List< Variable< variables = const [], Set<Object> >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 readyreadsFrom
and use Selectable.watch. If you know the query will never emit more than one row, you can also usegetSingle
andwatchSingle
which return the item directly without wrapping it into a list.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<Object> >ResultSetImplementation> ? 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 theupdateKind
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<Object> >ResultSetImplementation> ? updates, UpdateKind? updateKind}) → Future<List< QueryRow> > -
Runs a
INSERT
,UPDATE
orDELETE
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 -
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 -
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< tables) → voidTable, dynamic> > -
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 -
reset(
) → Future< void> - Resets everything, meaning dropping and re-creating every table.
-
resultSet<
T extends ResultSetImplementation> (String name) → T -
Available on GeneratedDatabase, provided by the ReadDatabaseContainer extension
Find a result set by itsname
in the database. The result is cached. -
runWithInterceptor<
T> (Future< T> action(), {required QueryInterceptor interceptor}) → Future<T> -
Executes
action
with calls intercepted by the giveninterceptor
inherited -
select<
T extends HasResultSet, R> (ResultSetImplementation< T, R> table, {bool distinct = false}) → SimpleSelectStatement<T, R> -
Starts a query on the given table.
inherited
-
selectExpressions(
Iterable< Expression< columns) → BaseSelectStatement<Object> >TypedResult> -
Creates a select statement without a
FROM
clause selectingcolumns
.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 oftable
's columns.inherited -
serializableConnection(
) → Future< DriftIsolate> -
Available on DB, provided by the ComputeWithDriftIsolate extension
Creates a DriftIsolate that, when connected to, will run queries on the database already opened bythis
. -
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(), {bool requireNew = false}) → 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