Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
The biggest new feature in this release is the addition of manager APIs, which make it much easier to write common simple queries. The new API has been designed to be easier to use and to avoid boilerplate for common CRUD queries. This feature requires additional code to be generated - if you prefer using the existing APIs exclusively, you can use the generate_manager: false
builder option.
.drift
files if the extension is enabled.AggregateFunctionExpression
to write custom aggregate function invocations in the Dart query builder.json_group_array
and jsonb_group_array
functions now contain an orderBy
and filter
parameter.TypeConverter.extensionType
factory to create type converters for extension types.BLOB
literals on postgres.setup
parameter to SchemaVerifier
. It is called when the verifier creates database connections (similar to the callback on NativeDatabase
) and can be used to register custom functions.companion
entry to DataClassName
to override the name of the generated companion class.use_sql_column_name_as_json_key
builder option.IN
expressions in drift files, they now support tuples on the left-hand side and the shorthand syntax for table references and table-valued functions.CREATE VIEW
statements.INT64
hint for CREATE TABLE
statements.Drift 2.16.0 mostly contains performance and stability improvements:
NativeDatabase.createInBackground
).UpdateStatement
with database.update
outside of a transaction and then calling UpdateStatement.write
inside of a transaction will now perform the update inside of the transaction, instead of causing a deadlock.EXPLAIN
statements, avoiding schema locks.Value.ofNullable
in favor of Value.absentIfNull
, which is more explicit about its behavior and allows nullable types too.WasmDatabase
to dart:js_interop
and package:web
.drift_postgres
date
or timestamp
types.Drift 2.15 introduces new features improving web support and for sharing database classes against different databases (e.g. sqlite3 and Postgres):
DialectAwareSqlType
, a custom type depending on the runtime dialect. This allows writing "polyfill" types that use native date types on Postgres while falling back to a textual representation on sqlite3 for instance.jsonb
functions in the query builder through package:drift/extensions/json1.dart
. jsonb
functions are also supported by sqlparser
when analyzing drift files.enableMigrations
parameter to NativeDatabase
to disable migrations, a flag useful for existing databases managed with an external schema tool.old
and new
in CREATE TRIGGER
statements.This release fixes a bug in the generator that is potentially breaking: Tables defined in .drift
files with a NULL
column constraint (e.g. CREATE TABLE users (display_name TEXT NULL, ...)
) were not generated correctly - the NULL
constraint was absent from the generated schema. This is not a soundness issue since NULL
constraints are the default and ignored by sqlite3. However, it means that the actual schema of databases deviates from what drift will now expect, since NULL
constraints will be expected from drift 2.15. This can cause issues with the schema validator after upgrading. If you are affected by this problem, the two possible ways to fix this are:
NULL
constraints from column declarations in drift files. You don't need a migration for this since they don't affect semantics.NULL
constraints. In this case, you'll have to increment the schema version of your database and use Migrator.alterTable(affectedTable)
on all affected tables to make it consistent with the schema with NULL
constraints that drift is now expecting.Also note that this only applies to drift files and not to NOT NULL
constraints, which have always been generated correctly. Finally, older snapshots generated with drift_dev schema generate
will continue to not report the NULL
constraint, meaning that older migration tests won't break due to this change. If you have any questions or concerns about this, please reach out by opening an issue.
This minor release fixes bugs in the drift
and the drift_dev
packages:
WasmProbeResult.open
ignoring the ìnitializeDatabase
callback.Variable
instances for columns with custom types.New features in drift:
QueryInterceptor
API to easily monitor or transform all database calls made by drift.count()
extension on tables to easily count rows in tables or views.Changes to the generator:
@DataClassName
annotation named Categories
would now generate a Category
class instead of Categorie
. This is done in a minor release because we assume users previously running into this are already using @DataClassName
as a workaround.drift_dev schema steps
public.const
row classes when they are extending a class which isn't const.Expression.and
and Expression.or
to create disjunctions and conjunctions of sub-predicates.TypeConverter.json
factory reduces the boilerplate needed to define type converters doing JSON conversions.drift_postgres
package is now available on pub.dev.This minor release fixes the following issues:
readWithConverter
throwing an exception for null values in non-nullable columns (#2640).*
columns in analyzed SQL queries expanding to more columns than what would be correct (#2641).views
crashing the generator (#2636).This drift release adds support for defining a database index in Dart and improves JSON support.
Full list of changes:
json_each
and json_tree
table-valued functions.@TableIndex
annotation for table classes to add an index to the table.TypeConverter.json
method to define type converters storing JSON values more easily.TypedResult.readWithConverter
to read a column with a type converter from a join result row.This minor drift release contains bug fixes and performance improvements for the builder:
sqlite_schema
in drift files.timediff
and octet_length
functions from sqlite 3.43.0.@UseRowClass
with generateInsertable: true
when modular code generation is enabled..read()
for a column added to a join from the table, fixing a regression in drift 2.11.0.Migrator.runMigrationSteps
.