drift library

Classes

AddColumnStatement
A statement adding a column to a table.
AggregateFunctionExpression<D extends Object>
An expression invoking an aggregate function.
BaseSelectStatement<Self extends BaseSelectStatement<Self, Row>, Row>
Common class for generated SELECT statements on databases.
Batch
Contains operations to run queries in a batched mode.
BatchedStatement
A statement that was created through a Batch.
BatchResult
Results of running statements from a Batch.
BeginStatement
A statement to begin a transaction.
BetweenExpression
A BETWEEN expression in SQL.
BinaryExpression<T extends Object>
An expression of the form <left> <operator> <right>.
CaseWhenExpression<T extends Object, R extends Object>
CASE WHEN expression in sqlite.
CastExpression<D1 extends Object, D2 extends Object>
A CAST ([inner]) AS [type] expression in SQL.
Collate
Collating functions used to compare texts in SQL.
CollateExpression
An expression that changes the collation used to e.g. compare texts.
ColumnCheckConstraint
A check constraint on column.
ColumnConstraint
A column constraint modifies a column to add e.g. a not-null requirement, foreign keys, checks or additional information.
ColumnDefaultConstraint<T extends Object>
A DEFAULT constraint in SQL.
ColumnForeignKeyConstraint
A constraint describing that a column references values in another row.
ColumnGeneratedAs
A GENERATED AS clause in SQL.
ColumnNotNullConstraint
A NOT NULL constraint used to disallow NULL values on a column.
ColumnPrimaryKeyConstraint
A PRIMARY KEY constraint applied to a singe column.
ColumnUniqueConstraint
A UNIQUE constraint on an individual column.
CommitStatement
A statement to commit a transaction.
CompoundSelect
A select statement that has been added to an existing SelectStatement by using a CompoundOperator.
CreateIndexStatement
Represents a CREATE INDEX statement in SQL.
CreateStatement<T extends DatabaseSchemaEntity>
A statement that creates a DatabaseSchemaEntity (such as tables, views, triggers or indices).
CreateTableStatement
Represents a CREATE TABLE statement in SQL.
CreateTriggerStatement
Represents a CREATE TRIGGER statement in SQL.
CreateViewStatement
Represents a CREATE VIEW statement in SQL.
CurrentDateOrTimeExpression
An expression that evaluates to the current date or the current date and time.
CustomColumnConstraint
A custom column constraint.
CustomComponent
A custom component, used to embed a fixed SQL string into drift-generated statements.
CustomResultSet
Base class for classes generated by custom queries in .drift files.
CustomRow
For custom select statements, represents a row in the result set.
DatabaseAccessor<T extends GeneratedDatabase>
Class that runs queries to a subset of all available queries in a database.
DatabaseConnectionUser
The shared base class for drift databases and database accessors.
DatabaseJson
A JSON value in a drift database.
DatabaseSchemaEntity
Some abstract schema entity that can be stored in a database. This includes tables, triggers, views, indexes, etc.
DataClassName
A class to be used as an annotation on Table classes to customize the name for the data class that will be generated for the table class. The data class is a dart object that will be used to represent a row in the table.
DateExtractionOperator<T extends Object>
An expression that extracts some field(s) from a DateTime expression.
DeleteStatement<Row extends Object, RS extends GeneratedTable<Row, RS>>
A DELETE statement in SQL.
DialectSpecificComponent
A common mixin for components with dialect-specific variants (or options that only exist in some dialects).
DoNothing<Row extends Object, RS extends GeneratedTable<Row, RS>>
Upsert clause that does nothing on conflict
DoUpdate<Row extends Object, RS extends GeneratedTable<Row, RS>>
A DoUpdate upsert clause can be used to insert or update a custom companion when the underlying companion already exists.
DriftAccessor
Annotation to use on classes that implement DatabaseAccessor. It specifies which tables should be made available in this dao.
DriftColumnDeclarationBuilder
An annotation on a method on Table (or an extension) used to begin a chain of methods describing a table column.
DriftConnection
A pending connection that can be opened into a OpenedDriftConnection.
DriftDatabase
Use this class as an annotation to inform the generator that a database class should be generated using the specified DriftDatabase.tables.
DriftDialect
SQL dialect.
DriftResultSet
A list of DriftRows from which structured values can be read in a type-safe way.
DriftRow
A row in a DriftResultSet.
DriftRuntimeOptions
Defines additional runtime behavior for drift. Changing the fields of this class is rarely necessary.
DriftSession
A session used to run statements against a database.
DriftSessionWithInternalLocks
For sessions that can provide exclusive access to the database, exposes an exclusive method.
DriftTransactionParent
For sessions that support starting transactions, exposes an begin method for starting transaction.
DriftTransactionSession
A handle to control transaction, expanding DriftSession.close to suppport explicitly committing or rolling transactions back.
DriftView
An annotation specifying view properties
DropColumnStatement
A statement removing a column to a table.
DropStatement
Represents a DROP TABLE statement in SQL.
EnumIndexConverter<T extends Enum>
Implementation for an enum to int converter that uses the index of the enum as the value stored in the database.
EnumNameConverter<T extends Enum>
Implementation for an enum to string converter that uses the name of the enum as the value stored in the database.
ExistsExpression
An EXISTS (or NOT EXISTS) expression in SQL.
Expression<T extends Object>
An SQL expression, which evaluates to a value when evaluated by a database engine.
ExpressionTuple<T extends Object>
A tuple of multiple expressions.
FrameBoundary
Base Class for Boundary in a window frame.
FromClause
A FROM clause providing the tables in SQL.
FromClauseElement
A source for from clauses
FromResultSet
Select from a generated table or view.
FunctionCallExpression<R extends Object>
A sql expression that calls a function.
FunctionParameter
Parameters that can be passed to SQL function calls.
GeneratedDatabase
The superclass for all databases class generated by drift.
GeneratedTable<Row extends Object, Self extends GeneratedTable<Row, Self>>
The common superclass for table classes generated by drift_dev.
GeneratedView<Row extends Object, Self extends GeneratedView<Row, Self>>
The common superclass for view classes generated by drift_dev.
GroupBy
A GROUP BY clause in SQL.
Index
An index on a table.
IndexedColumn
A column that can appear in a TableIndex.
InMemoryStreamQueryStore
A StreamQueryStore implementation backed by a stream controller and explicit notifications via handleTableUpdates.
Insertable<D>
Common interface for objects which can be inserted or updated into a database. D is the associated data class.
InsertDefaultValues
Insert the default values for each column.
InsertFromSelect
Insert rows returned by a select statement.
InsertFromValues
Insert values from an values map.
InsertSource
Possible values for InsertStatement.source.
InsertStatement<Row extends Object, RS extends GeneratedTable<Row, RS>>
An INSERT statement in SQL.
Join
Represents a join of a table to a query.
JsonKey
Annotation to use on column getters inside of a Table to define the name of the column in the json used by DataClass.toJson.
LegacyDataClass
A common supertype for all data classes generated by drift in the legacy v2 generation mode. Data classes are immutable structures that represent a single row in a database table.
LikeExpression
A LIKE expression in SQL, with an optional ESCAPE clause.
Limit
A limit clause inside a select, update or delete statement.
Literal<T extends Object>
An expression that represents the value of a dart object encoded to sql by writing them into the sql statements. For most cases, consider using Variable instead.
MigrationStrategy
Handles database migrations by delegating work to OnCreate and OnUpgrade methods.
Migrator
Provides methods for generating SQL statements used to create, alter, or drop elements in a database.
MultiSelectable<T>
Selectable methods for returning multiple results.
NullAwareTypeConverter<D, S extends Object>
A type converter automatically mapping null values to null in both directions.
OnCreateQuery
A query defined in a drift file that should run when the database is created.
OpenedDriftConnection
The underlying opened database connection implementation used for drift databases.
OpeningDetails
Provides information about whether migrations ran before opening the database.
OrderBy
An order-by clause as part of a select statement. The clause can consist of multiple OrderingTerms, with the first terms being more important and the later terms only being considered if the first term considers two rows equal.
OrderingTerm
A single term in a OrderBy clause. The priority of this term is determined by its position in OrderBy.terms.
PersistentSchemaVersion
A schema version that can be persisted in a database.
PhysicalSqlType<T extends Object>
A dialect-specific implementation of a SqlType.
QueryInterceptor
An interceptor for SQL queries.
QueryResult
The result of running an SQL statement against a DriftSession.
RawResultSet
A raw view of result sets returned by the connection implementation.
RawValuesInsertable<D>
An Insertable implementation based on raw column expressions.
ReferenceName
Annotation to use on reference columns inside of a Table to define the name that the manager will use when refering to this relation in the reverse.
RenameColumnStatement
A statement renaming oldName in table to column.
RenameTableStatement
A statement renaming oldName to table.
ResultSetDsl
Common superclass for Table and Views.
ResultSetStructure
The expected column structure of a result set.
ReturningClause
A RETURNING * clause that can appear as part of an INSERT, UPDATE or DELETE statement.
RollbackStatement
A statement to roll back (possibly nested) transactions.
SchemaColumn<T extends Object>
A column that appears as part of some schema object.
SchemaEntityWithResultSet<Row extends Object, Self extends ResultSet<Row, Self>>
A generated table or view that appears in a schema.
Selectable<T>
Abstract class for queries which can return one-time values or a stream of values.
SelectStatement
A select statement referencing multiple tables.
SingleOrNullSelectable<T>
Selectable methods for returning or streaming single, nullable results.
SingleSelectable<T>
Selectable methods for returning or streaming single, non-nullable results.
SingleTableSelectStatement<Row extends Object, RS extends ResultSet<Row, RS>>
A select statement selecting from a single table.
SqlComponent
Base class for anything that can be compiled to SQL.
SqlStatement
Common superclass for SQL statements generated by drift.
SqlType<T extends Object>
The base class for column types in databases.
StarFunctionParameter
A * parameter passed to functions.
StatementBatch
A batch of statements to prepare and run at once.
StatementBuffer
A mutable buffer of SQL text, parameters and associated state.
StatementCompiler
A compiler that iteratively builds SQL text by recursively visiting a tree of SqlComponents.
StatementInBatch
An instantiated statement in a StatementBatch.
StatementInfo
Information about a SQL statement generated by drift's query builder.
StatementWithReturningClause<Row extends Object, RS extends GeneratedTable<Row, RS>>
A statement with an optional ReturningClause.
StreamKey
Key that uniquely identifies a select statement. If two keys created from two select statements are equal, the statements are equal as well.
StreamQueryStore
Defines interfaces for running streams that refresh on table updates, as well as dispatching table updates.
StreamQueryUpdateRules
Collects a set of UpdateRules which can be used to express how a set of direct updates to a table affects other updates.
Subquery<Row extends Object>
A subquery allows reading from another complex query in a join.
SubqueryExpression<R extends Object>
An expression evaluating to the single row and single column of an inner select statement.
Table
Subclasses represent a table in a database generated by drift.
TableColumn<T extends Object>
A fully-resolved column in a GeneratedTable.
TableColumnWithTypeConverter<D, S extends Object>
A TableColumn that has a TypeConverter attached to it.
TableConstraint
A table constraint supported by drift.
TableIndex
Annotations for Dart table classes to define a SQL index to add to the table.
TableOrViewStatements<Row extends Object, RS extends ResultSet<Row, RS>>
Methods to compose common queries and statements on tables or views.
TablePrimaryKeyConstraint
A PRIMARY KEY constraint set on a table.
TableUniqueKeyConstraint
A UNIQUE constraint attached to a table.
TableUpdate
Contains information on how a table was updated, which can be used to find queries that are affected by this.
TableUpdateQuery
A table update query describes information to listen for TableUpdates.
TransactionOptions
An interface describing options to use when beginning a transaction.
Trigger
A sqlite trigger that's executed before, after or instead of a subset of writes on a specific tables. In drift, triggers can only be declared in .drift files.
TypeConverter<D, S>
Maps a custom dart object of type D into a primitive type S understood by the sqlite backend.
TypeProvider
Provides access types that every drift dialect implementation must support.
UnaryExpression<T extends Object>
An expression of the form <operator> <operand> or <operand> <operator>.
UnixTimestampToDateTime
An expression converting the inner timestamp (as unix seconds) to a DateTime value.
UpdateCompanion<D>
An update companion for a row which is used to write data into a database during insert or update operations.
UpdateRule
A common rule that describes how a TableUpdate has other TableUpdates.
UpdateStatement<Row extends Object, RS extends GeneratedTable<Row, RS>>
Represents an UPDATE statement in sql.
UpsertClause<Row extends Object, RS extends GeneratedTable<Row, RS>>
A upsert clause controls how to behave when a uniqueness constraint is violated during an insert.
UpsertMultiple<Row extends Object, RS extends GeneratedTable<Row, RS>>
Upsert clause that consists of multiple clauses.
UseRowClass
An annotation specifying an existing class to be used as a data class.
Value<T>
A wrapper around arbitrary data T to indicate presence or absence explicitly.
ValueSerializer
Serializer responsible for mapping atomic types from and to json.
Variable<T extends Object>
An expression that represents the value of a dart object encoded to sql using prepared statements.
View
Subclasses represent a view in a database generated by drift.
ViewColumn<T extends Object>
A column in a GeneratedView.
ViewColumnWithTypeConverter<D, S extends Object>
A Expression that has a TypeConverter attached to it.
WhereClause
A WHERE clause acting as a filter in SQL.
WindowFunctionExpression<T extends Object>
Represents a window function expression in SQL.
WritePropagation
An UpdateRule for triggers that exist in a database.

Enums

BinaryOperator
Binary operators supported by drift.
CompoundOperator
A set operator used to combine the results of multiple select statement into one.
DateExtractionField<T extends Object>
Fields that can be extracted from DateTime values in SQL.
FrameExclude
Specifies how to exclude rows from the window frame.
FrameType
Describes the type of frame for a window function.
JoinOperator
An operator used to compose joins, see Join.
KeyAction
A KeyAction can be used on a BuildColumn.references clause to describe how updates and deletes to a referenced table should propagate in your database.
KnownSqlDialect
An enumeration of SQL dialects supported by drift.
NullsOrder
Describes how to order nulls
OrderingMode
Describes how to order rows
Precedence
Used to order the precedence of sql expressions so that we can avoid unnecessary parens when generating sql statements.
ReferenceAction
An action for foreign keys controlling the behavior if the referenced value is changed or deleted.
UnaryOperator
Unary SQL operators supported by drift.
UpdateKind
Classifies a TableUpdate by what kind of write happened - an insert, an update or a delete operation.

Mixins

JsonTypeConverter<D, S>
A mixin for TypeConverters that should also apply to drift's builtin JSON serialization of data classes.
JsonTypeConverter2<D, S, J>
A mixin for TypeConverters that should also apply to drift's builtin JSON serialization of data classes.
ResultSet<Row extends Object, Self extends ResultSet<Row, Self>>
A result set as it appears in the database schema.
SchemaColumnWithTypeConverter<D, S extends Object>
A SchemaColumn with a type converter attached to it.
VirtualTableInfo<Row extends Object, Self extends GeneratedTable<Row, Self>>
Additional interface for tables in a drift file that have been created with an CREATE VIRTUAL TABLE STATEMENT.

Extension Types

BaseColumnBuilder
Common definitions shared between regular columns (ColumnBuilders) and virtual columns (VirtualColumnBuilder).
ColumnBuilder
A column builder is used to specify which columns should appear in a table. All of the methods defined in this class and its subclasses are not meant to be called at runtime. Instead, the generator will take a look at your source code (specifically, it will analyze which of the methods you use) to figure out the column structure of a table.
ColumnPosition
Information about where we expect a high-level drift column to appear in the low-level result map returned by database implementation.
DatabaseSchema
The resolved static schema of a drift database.
VirtualColumnBuilder
A column builder for virtual, generated columns.

Extensions

ApplyInterceptor on DriftSession
Extension to wrap a DriftSession with a QueryInterceptor.
ApplyInterceptorConnection on DriftConnection
Extension to wrap a DriftConnection with a QueryInterceptor.
ArithmeticAggregates on Expression<DT>
Provides aggregate functions that are available for numeric expressions.
ArithmeticBigIntExpr on Expression<BigInt>
Defines the -, * and / operators on sql expressions that support it.
ArithmeticExpr on Expression<DT>
Defines the -, * and / operators on sql expressions that support it.
BaseAggregate on Expression<DT>
Provides aggregate functions that are available for each expression.
BigIntAggregates on Expression<BigInt>
Provides aggregate functions that are available for BigInt expressions.
BitwiseBigInt on Expression<BigInt>
Extensions providing bitwise operators ~, on integer expressions that are represented as a Dart BigInt.
BitwiseInt on Expression<int>
Extensions providing bitwise operators ~, on integer expressions.
BlobExpressionOperators on Expression<Uint8List>
Defines operations on blob (Uint8List) values.
BooleanExpressionOperators on Expression<bool>
Defines operations on boolean values.
BuildInt64Column on ColumnBuilder<BigInt>
Tells the generator to build an Int64Column. See the docs at ColumnBuilder for details.
BuildIntColumn on ColumnBuilder<T>
Tells the generator to build an IntColumn. See the docs at ColumnBuilder for details.
BuildTextColumn on ColumnBuilder<T>
Tells the generator to build an TextColumn. See the docs at ColumnBuilder for details.
ComparableExpr on Expression<DT>
Defines extension functions to express comparisons in sql
DateTimeAggregate on Expression<DateTime>
Provides aggregate functions that are available on date time expressions.
DateTimeExpressions on Expression<DateTime>
Provides expressions to extract information from date time values, or to calculate the difference between datetimes.
DestructiveMigrationExtension on GeneratedDatabase
Extension providing the destructiveFallback strategy.
GeneratedTableExtension on GeneratedTable<Object, GeneratedTable<Object, dynamic>>
Default methods for all generated tables.
GetTableOrViewStatements on ResultSet<Row, RS>
Extension providing the statements method for tables specifically.
OldDbFieldInDatabaseAccessor on DatabaseAccessor<T>
Extension for generated dao classes to keep the old db field that was renamed to DatabaseAccessor.attachedDatabase in drift 3.0
QueryTableExtensions on SingleTableStatementMixin<Row, RS, Self>
Extension for statements on a table.
StringExpressionOperators on Expression<String>
Defines methods that operate on a column storing String values.
TableStatements on TableOrViewStatements<Row, RS>
Utility to compose common statements for tables.
TypeExtension on SqlType<T>
Adds type implementation methods to SqlType by looking up the type in a DriftDialect implementation.

Constants

$driftBlobEquality → const ListEquality<int>
A ListEquality instance used by generated drift code for the == and Object.hashCode implementation of generated classes if they contain lists.
currentDate → const Expression<DateTime>
A sql expression that evaluates to the current date.
currentDateAndTime → const Expression<DateTime>
A sql expression that evaluates to the current date and time, similar to DateTime.now.

Properties

cancellationSignal → Future<void>?
If this getter is called in a cancellation zone, returns a Future that completes once the operation is cancelled.
no setter
driftRuntimeOptions ↔ DriftRuntimeOptions
Stores the DriftRuntimeOptions describing global drift behavior across databases.
getter/setter pair

Functions

checkIfCancelled() → void
Checks whether the active zone is a cancellation zone that has been cancelled. If it is, a CancellationException will be thrown.
coalesce<T extends Object>(List<Expression<T>> expressions) → Expression<T>
Evaluates to the first expression in expressions that's not null, or null if all expressions evaluate to null.
countAll({Expression<bool>? filter}) → Expression<int>
Returns the amount of rows in the current group matching the optional filter.
existsQuery(BaseSelectStatement<BaseSelectStatement, dynamic> select) → Expression<bool>
The EXISTS operator checks whether the select subquery returns any rows.
ifNull<T extends Object>(Expression<T> first, Expression<T> second) → Expression<T>
Evaluates to the first expression that's not null, or null if both evaluate to null. See coalesce if you need more than 2.
notExistsQuery(BaseSelectStatement<BaseSelectStatement, dynamic> select) → Expression<bool>
The NOT EXISTS operator evaluates to true if the select subquery does not return any rows.
subqueryExpression<R extends Object>(BaseSelectStatement<BaseSelectStatement, dynamic> statement) → Expression<R>
Creates a subquery expression from the given statement.

Typedefs

BlobColumn = Column<Uint8List>
A column that stores arbitrary blobs of data as a Uint8List.
BoolColumn = Column<bool>
A column that stores boolean values. Booleans will be stored as an integer that can either be 0 (false) or 1 (true).
CaseWhen<T extends Object, R extends Object> = ({Expression<R> then, Expression<T> when})
A single when-then case for CASE WHEN expression in sqlite.
Column<T extends Object> = SchemaColumn<T>
Base class for columns in sql. Type T refers to the type a value of this column will have in Dart.
DateTimeColumn = Column<DateTime>
A column that stores a DateTime. Times will be stored as unix timestamp and will thus have a second accuracy.
DriftDialectFactory = DriftDialect Function(Map<KnownSqlDialect, Object> dialectOptions)
A factory to create DriftDialect implementations based on available options.
Int64Column = Column<BigInt>
A column that stores BigInt values.
IntColumn = Column<int>
A column that stores int values.
JsonColumn = Column<DatabaseJson>
A column that stores json values.
OnBeforeOpen = Future<void> Function(OpeningDetails details)
Signature of a function that's called before a database is marked opened by drift, but after migrations took place. This is a suitable callback to to populate initial data or issue PRAGMA statements that you want to use.
OnCreate = Future<void> Function(Migrator m)
Signature of a function that will be invoked when a database is created.
OnUpgrade = Future<void> Function(Migrator m, int from, int to)
Signature of a function that will be invoked when a database is upgraded or downgraded. In version upgrades: from < to In version downgrades: from > to
OrderClauseGenerator<T> = OrderingTerm Function(T tbl)
Signature of a function that generates an OrderingTerm when provided with a table.
RawRow = List<Object?>
A row in a RawResultSet, a list of untyped values.
RealColumn = Column<double>
A column that stores floating point numeric values.
TextColumn = Column<String>
A column that stores text.

Exceptions / Errors

CancellationException
Thrown inside a cancellation zone when it has been cancelled.
CouldNotRollBackException
Exception thrown by drift when rolling back a transaction fails.
DriftException
Superclass for all exceptions thrown by drift.