Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
MIT License
This patch release fixes exclusively
not working on the web (#3089). The fix requires a drift_worker.js
update.
Published by simolus3 3 months ago
Drift 2.19.0 expands the migrator API and adds a method to exclusively use the database without a transaction (useful for things like setting pragmas which are unsupported in transactions).
exclusively
method to database classes, allowing a block to temporarily take exclusive control over a database connection without starting a transaction.enableMigrations
parameter to WasmDatabase
to control whether drift migrations are enabled on that database.initiallyDeferred
option to references()
column builder for foreign key constraints.dropColumn
method to Migrator
.selectExpressions
method to build select statements without a FROM
clause.transaction
and exclusively
will wait for the transaction or the exclusive lock to be set up before invoking their callback now.This release also fixes the following bugs:
BigInt
arguments in batched statements sent to web workers. Note that the fix also requires the latest drift_worker.js
to be effective.CREATE VIEW
statements containing existing row class syntax only supposed to be used during static analysis.drift_dev schema steps
generating invalid code when no migrations have been defined yet.While not part of the core packages in this repository, another addition is drift_hrana, which allows using drift with a libsql server - that may be useful for some Dart backends using Turso or related offerings.
Published by simolus3 6 months ago
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.Published by simolus3 6 months ago
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.Published by simolus3 8 months ago
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.Published by simolus3 9 months ago
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.
Published by simolus3 11 months ago
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.Published by simolus3 11 months ago
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.Published by simolus3 about 1 year ago
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.Published by simolus3 about 1 year ago
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).Published by simolus3 about 1 year ago
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.Published by simolus3 about 1 year ago
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
.Published by simolus3 about 1 year ago
This release adds new features to the Dart query builder API:
isInExp
and isNotInExp
to construct IS IN
expressions with arbitrary expressions.substr
extension on Expression<String>
to call the sqlite3 function from the Dart API.Other new additions to drift:
isolateSetup
to NativeDatabase.createInBackground()
to override native libraries or perform other database-unrelated setup work.WasmDatabase.probe()
, a method probing for available implementations and existing databases on the web without opening one directly.drift_dev
has also seen some optimizations in how it generates query code, which enables new features:
dialects
builder option to generate code supporting multiple SQL dialects.preamble
option for non-shared or modular build setups to mirror the preamble
option from source_gen:combining_builder
.Published by simolus3 over 1 year ago
The main new feature of drift 2.10 is the drift_dev schema steps
command, which generates a single Dart file with all schema versions of your database available.
A generated API in that file makes it easy to write incremental schema migrations.
Additionally, this release fixes an issue with the new WASM implementation when the set of available storage implements in a browser changes and makes drift_dev
print a warning when Dart tables are implicitly added to a database through a transitive import.
Published by simolus3 over 1 year ago
The biggest feature of this release is stable web support! The WasmDatabase.open
factory with a drift web worker is a performant and reliable web implementation for drift. The new web documentation at https://drift.simonbinder.eu/web/ shows how to use the new API and how to migrate from the old and experimental drift web APIs.
In addition to the new web API, this release
fatal_warnings
builder option, causing the build to fail when drift_dev
reports warnings.0
from the schemaVersion
getter. This has always been broken, so the explicit check leads to a better error message.Published by simolus3 over 1 year ago
This patch release fixes the following issues in the core drift
package:
connectToDriftWorker
.Also, drift_dev: 2.8.3
and sqlparser: 0.30.1
have been released with these changes:
WITH
clauses in triggers.Published by simolus3 over 1 year ago
This drift release adds support for named constructors for existing row types in drift files (#2399) and allows targeting partial indices in DoUpdate
(#2394).
It also fixes the following noteworthy bugs:
setup
callback throws an exception. Instead, drift will retry the next time the database is used.computeWithDatabase
is called inside a transaction()
.analyzer: 5.12.0
.Published by simolus3 over 1 year ago
CASE
expressions without a base in the Dart API with the CaseWhenExpression
class.package:drift/web/workers.dart
library which makes it easier to create web workers for drift.validateDatabaseSchema()
work in migration tests.AS
aliases in subqueries used in triggers.GROUP BY
or HAVING
clause.Published by simolus3 over 1 year ago
This release adds support for general IS
operators to the query builder, makes drift isolates much easier to use and allows applying type converters on columns in queries.
isExp
, isValue
, isNotExp
and isNotValue
methods to Expression
to generate the IS
operator in SQL.all()
extension on tables and views to quickly query all rows.serializableConnection()
and computeWithDatabase()
as extensions on databases. The methods allow sharing any drift database between isolates, regardless of how the database has been set up.DatabaseConnection
class now implements QueryExecutor
, meaning that you no longer need a special .connect()
constructor to use it.generate_connect_constructor
option is now deprecated, as a DatabaseConnection
can be passed whereever a QueryExecutor
is used too.MAPPED BY
for individual columns in queries or in views defined with SQL.CAST
to an enum type in drift files.CAST (x AS DATETIME)
and CAST(x AS TEXT)
in drift files.LIST()
columns having the same result class name.@UseDataClass
with extending
not working with modular generation.async
modifier when mapping queries to existing row classes.Published by simolus3 almost 2 years ago
schema generate --companions
implicitly requiring --data-classes
as well.toColumns()
not being generated correctly.schema generate
when using existing row types on views.Literal
subclasses and NumberedVariable
.