AirpassDatabase class

Annotations
  • @DriftDatabase.new(tables: [Nodes, Messages, Groups, MessageDeliveries])

Constructors

AirpassDatabase([QueryExecutor? executor])
Creates the database using driftDatabase which handles platform-specific SQLite opening logic automatically, or a custom executor for testing.

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
connection → DatabaseConnection
The database connection used by this DatabaseConnectionUser.
finalinherited
executor → QueryExecutor
The executor to use when queries are executed.
no setterinherited
groups $GroupsTable
latefinalinherited
hashCode int
The hash code for this object.
no setterinherited
managers $AirpassDatabaseManager
no setterinherited
messageDeliveries $MessageDeliveriesTable
latefinalinherited
messages $MessagesTable
latefinalinherited
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 setter
nodes $NodesTable
latefinalinherited
options → DriftDatabaseOptions
The DriftDatabaseOptions to use for this database instance.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
schemaVersion int
Bump this when you change the schema. See migration below.
no setter
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

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
$writeUpdateInsertable(TableInfo<Table, dynamic> table, Insertable insertable, {int? startIndex}) → GenerationContext
Writes column names and values for an update statement.
inherited
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
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
close() Future<void>
Closes this database and releases associated resources.
inherited
computeWithDatabase<Ret, DB extends GeneratedDatabase>({required FutureOr<Ret> computation(DB), required DB connect(DatabaseConnection)}) Future<Ret>
On native platforms this spawns a short-lived isolate to run the computation with a drift database. On web platforms, this will run the computation on the current JavaScript context.
inherited
countGroupMemberships() Future<Map<String, int>>
Counts distinct group IDs across the nodes routing table. Returns a map of groupId → member count for updating the group directory.
createMessage({required String messageId, required String senderId, required String targetId, required List<int> payload, required int ttl, String? signature, MediaType mediaType = MediaType.text, String? mediaFileName, String? mediaMimeType, int? mediaFileSize, String? mediaHash, String? mediaLocalPath, MediaAvailability mediaAvailability = MediaAvailability.notApplicable, Uint8List? mediaThumbnail}) Future<void>
Convenience: insert a new outgoing message created by the local user.
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<Object>> variables = const [], Set<ResultSetImplementation>? updates}) Future<int>
Executes a custom insert statement and returns the last inserted rowid.
inherited
customSelect(String query, {List<Variable<Object>> variables = const [], Set<ResultSetImplementation> readsFrom = const {}}) → Selectable<QueryRow>
Creates a custom select statement from the given sql query.
inherited
customSelectQuery(String query, {List<Variable<Object>> 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.
inherited
customStatement(String statement, [List? args]) Future<void>
Executes the custom sql statement on the database.
inherited
customUpdate(String query, {List<Variable<Object>> variables = const [], Set<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 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<ResultSetImplementation>? 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
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
getAllGroups() Future<List<Group>>
Returns all known groups as a one-shot query.
getAllNodes() Future<List<Node>>
Returns all known nodes as a one-shot query.
getAllSyncableMessages() Future<List<Message>>
Returns all messages that are pending or sent (for full-mesh sync).
getGroupById(String groupId) Future<Group?>
Looks up a single group by ID. Returns null if not discovered yet.
getMessagesForSync(String peerNodeId) Future<List<Message>>
Returns messages that should be sent to a specific peer during sync.
getMessagesWithLocalMedia() Future<List<Message>>
Returns all messages that have media files stored locally. Used by MediaStorageService.pruneOrphanedMedia to find which files are still referenced.
getMessagesWithPendingMedia() Future<List<Message>>
Returns messages with media that are pending download.
getPendingMediaForSync(int maxAutoDownloadBytes) Future<List<Message>>
Returns pending media messages that qualify for auto-download (file size under maxAutoDownloadBytes) OR were manually requested.
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
markMessagesAsSent(List<String> messageIds) Future<void>
Mark all pending messages that were included in a sync as sent.
markMessageStatus(String messageId, MessageStatus newStatus) Future<void>
Update the status of a specific message.
markTablesUpdated(Iterable<TableInfo<Table, 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
pruneExpiredMessages({required int ttlHours}) Future<int>
Prune messages whose TTL has reached 0 or whose creation time exceeds the time-based TTL.
pruneOrphanedDeliveries() Future<int>
Removes delivery records for messages that no longer exist. Call this after pruneExpiredMessages to keep the table clean.
pruneStaleNodes(Duration threshold) Future<int>
Removes nodes that haven't been seen within threshold. Call this periodically from the background service.
recordDeliveries({required List<String> messageIds, required String peerNodeId}) Future<void>
Records that a list of messages were successfully delivered to a peer.
resolveFullNodeId(String prefix) Future<String?>
Resolves an 8-character node ID prefix to the full UUID stored in the routing table.
runWithInterceptor<T>(Future<T> action(), {required QueryInterceptor interceptor}) Future<T>
Executes action with calls intercepted by the given interceptor
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<Object>> columns) → BaseSelectStatement<TypedResult>
Creates a select statement without a FROM clause selecting columns.
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
subscribeToGroup(String groupId, {bool exclusive = false}) Future<void>
Subscribe the local node to a group.
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
unsubscribeFromGroup(String groupId) Future<void>
Unsubscribe from a specific group.
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
updateMediaAvailability(String messageId, MediaAvailability availability, {String? localPath}) Future<void>
Updates the media availability and local path for a message.
upsertDiscoveredGroup({required String groupId, String? displayName, int? memberCount}) Future<void>
Insert or update a discovered group.
upsertMessage(MessagesCompanion entry) Future<bool>
Insert a message, ignoring duplicates (same messageId). Returns true if the message was inserted (new), false if it was a duplicate.
upsertNode(NodesCompanion entry) Future<void>
Insert or update a node. On conflict (same nodeId), the existing row is unconditionally overwritten with the incoming data.
watchDirectMessages(String peerId, String localId) Stream<List<Message>>
Watches direct messages between the local node and a specific peer. Includes messages sent BY local TO peer, and BY peer TO local.
watchDiscoveredGroups() Stream<List<Group>>
Watches all discovered groups, ordered by most recently seen. Use this to populate a "Browse Groups" UI.
watchIncomingMessages(String localNodeId) Stream<List<Message>>
Watches all messages addressed to the local node or broadcast.
watchKnownNodes() Stream<List<Node>>
Watches all known nodes, ordered by most recently seen. Use this to build a live routing table view in the UI.
watchMessage(String messageId) Stream<Message?>
Watches a specific message by ID — used for media download progress.
watchMessagesForTarget(String targetId) Stream<List<Message>>
Watches all messages matching targetId — reactively.
watchPendingMessages() Stream<List<Message>>
Watches all pending messages (not yet synced to any peer).
watchSubscribedGroups() Stream<List<Group>>
Watches only the groups the local node is subscribed to.

Operators

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