drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.

MIT License

Stars
2.5K
Committers
141
drift - Drift 2.19.1 Latest Release

Published by simolus3 3 months ago

This patch release fixes exclusively not working on the web (#3089). The fix requires a drift_worker.js update.

drift - Drift 2.19.0

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).

  • Add exclusively method to database classes, allowing a block to temporarily take exclusive control over a database connection without starting a transaction.
  • Add the enableMigrations parameter to WasmDatabase to control whether drift migrations are enabled on that database.
  • Add initiallyDeferred option to references() column builder for foreign key constraints.
  • Add dropColumn method to Migrator.
  • Add selectExpressions method to build select statements without a FROM clause.
  • Both transaction and exclusively will wait for the transaction or the exclusive lock to be set up before invoking their callback now.
  • In drift files: Support for sqlite 3.46.0.

This release also fixes the following bugs:

  • Fix encoding BigInt arguments in batched statements sent to web workers. Note that the fix also requires the latest drift_worker.js to be effective.
  • Fix stream queries possibly cancelling a migration if they are the first method on the database.
  • Drift files: Make columns coming from subquery expressions nullable.
  • Fix generated CREATE VIEW statements containing existing row class syntax only supposed to be used during static analysis.
  • Fix Dart views referencing the same column from different table aliases using columns with the same name.
  • Fix drift_dev schema steps generating invalid code when no migrations have been defined yet.
  • Fix generated imports for extension member references in modular mode.

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.

drift - Drift 2.18.0

Published by simolus3 6 months ago

Manager APIs

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.

Other additions

  • Drift now supports geopoly tables and queries in .drift files if the extension is enabled.
  • Add AggregateFunctionExpression to write custom aggregate function invocations in the Dart query builder.
  • The json_group_array and jsonb_group_array functions now contain an orderBy and filter parameter.

Fixes

  • Improve finding the correct import alias in generated code for part files.
drift - Drift 2.17.0

Published by simolus3 6 months ago

Core

  • Add the TypeConverter.extensionType factory to create type converters for extension types.
  • Fix invalid SQL syntax being generated for BLOB literals on postgres.
  • Add a 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.

Generator

  • Adds companion entry to DataClassName to override the name of the generated companion class.
  • Fix drift using the wrong import alias in generated part files.
  • Add the use_sql_column_name_as_json_key builder option.
  • Fix parsing binary literals in drift files.
  • Expand support for 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.
  • Allow custom class names for CREATE VIEW statements.
  • Support the INT64 hint for CREATE TABLE statements.
drift - Drift 2.16.0

Published by simolus3 8 months ago

Drift 2.16.0 mostly contains performance and stability improvements:

  • When a migration throws, the database will now block subsequent operations instead of potentially allowing them to operate on a database in an inconsistent state.
  • Improve stack traces for errors happening on drift isolates (which includes usages of NativeDatabase.createInBackground).
  • Statements built through the Dart query builder will now run in the context active while they are running, instead of the context active at the time they were created. For instance, creating an 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.
  • Improve performance when reading results from joined statements with many rows.
  • Don't cache EXPLAIN statements, avoiding schema locks.
  • Deprecate Value.ofNullable in favor of Value.absentIfNull, which is more explicit about its behavior and allows nullable types too.
  • Migrate WasmDatabase to dart:js_interop and package:web.

Improvements to the generator

  • Allow selecting from virtual tables using the table-valued function syntax.
  • Keep import alias when referencing existing elements in generated code (#2845).

Improvements to drift_postgres

  • Drift's comparable expression operators are now available for expressions using postgres-specific date or timestamp types.
drift - Drift 2.15.0

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):

  • Better support for custom SQL types:
    • Custom types are now applied consistently in the query builder API.
    • Add 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.
  • Initial JSONB support: sqlite 3.45 supports a binary JSON format aiming at reducing size and improving performance for JSON operations in SQL. Drift 2.15.0 supports jsonb functions in the query builder through package:drift/extensions/json1.dart. jsonb functions are also supported by sqlparser when analyzing drift files.
  • Runtime improvements:
    • Wasm databases hosted in workers are closed after the last client disconnects.
    • Add enableMigrations parameter to NativeDatabase to disable migrations, a flag useful for existing databases managed with an external schema tool.
  • Add analysis errors for illegal unqualified references to 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:

  1. To remove NULL constraints from column declarations in drift files. You don't need a migration for this since they don't affect semantics.
  2. To keep 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.

drift - Drift 2.14.1

Published by simolus3 11 months ago

This minor release fixes bugs in the drift and the drift_dev packages:

  • Fix WasmProbeResult.open ignoring the ìnitializeDatabase callback.
  • Fix inconsistencies when generating Variable instances for columns with custom types.
  • Fix a build performance regression introduced in version 2.14.0 related to analyzing imports in drift files.
drift - Drift 2.14

Published by simolus3 11 months ago

New features in drift:

  • Add the QueryInterceptor API to easily monitor or transform all database calls made by drift.
  • Add the count() extension on tables to easily count rows in tables or views.
  • For updates made in drift files, we now support the column-name-list syntax.

Changes to the generator:

  • Breaking change: The name of the generated row class derived from the name of the Dart table name now supports more forms of plurals. For instance, a table without a @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.
  • Make versioned schema snapshots generated by drift_dev schema steps public.
  • Don't generate const row classes when they are extending a class which isn't const.
  • Fix indices attached to tables not generating reliably.
drift - Drift 2.13

Published by simolus3 about 1 year ago

Core Library

  • Add support for custom types, which are useful when extending drift to support other database engines.
  • Add Expression.and and Expression.or to create disjunctions and conjunctions of sub-predicates.
  • Step-by-step migrations now save the intermediate schema version after each step.
  • The TypeConverter.json factory reduces the boilerplate needed to define type converters doing JSON conversions.

Backends

  • Add APIs to setup Wasm databases with custom drift workers.
  • The drift_postgres package is now available on pub.dev.

Utilities

  • Drift now provides a DevTools extension embedding the drift inspector written by Koen Van Looveren. When opening DevTools from Flutter's beta channel, a Drift tab is available to inspect open databases.
drift - Drift 2.12.1

Published by simolus3 about 1 year ago

This minor release fixes the following issues:

  • Fix readWithConverter throwing an exception for null values in non-nullable columns (#2640).
  • Fix * columns in analyzed SQL queries expanding to more columns than what would be correct (#2641).
  • Fix invalid types listed in views crashing the generator (#2636).
  • Fix a generator crash when seeing an index referencing expressions instead of columns (#2643).
drift - Drift 2.12.0

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:

  • Add support for table-valued functions in the Dart query builder.
  • Support the json_each and json_tree table-valued functions.
  • Add the @TableIndex annotation for table classes to add an index to the table.
  • Add the TypeConverter.json method to define type converters storing JSON values more easily.
  • Add TypedResult.readWithConverter to read a column with a type converter from a join result row.
drift - Drift 2.11.1

Published by simolus3 about 1 year ago

This minor drift release contains bug fixes and performance improvements for the builder:

  • Allow references to sqlite_schema in drift files.
  • Support the timediff and octet_length functions from sqlite 3.43.0.
  • Reduce the amount of assets read by drift, improving build performance and enabling faster incremental rebuilds.
  • Fix missing import references around @UseRowClass with generateInsertable: true when modular code generation is enabled.
  • Allow using .read() for a column added to a join from the table, fixing a regression in drift 2.11.0.
  • Make step-by-step migrations easier to customize with Migrator.runMigrationSteps.
drift - Drift 2.11.0

Published by simolus3 about 1 year ago

This release adds new features to the Dart query builder API:

  • Add support for subqueries in the Dart query builder.
  • Add isInExp and isNotInExp to construct IS IN expressions with arbitrary expressions.
  • Add the substr extension on Expression<String> to call the sqlite3 function from the Dart API.

Other new additions to drift:

  • Add isolateSetup to NativeDatabase.createInBackground() to override native libraries or perform other database-unrelated setup work.
  • Add 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:

  • Nested result columns in drift files can now refer to any result set (e.g. a table-valued function or a subquery). They were restricted to direct table references before.
  • Add the dialects builder option to generate code supporting multiple SQL dialects.
  • Add the preamble option for non-shared or modular build setups to mirror the preamble option from source_gen:combining_builder.
drift - Drift 2.10.0

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.

drift - Drift 2.9.0

Published by simolus3 over 1 year ago

Drift 2.9.0

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

  • introduces the fatal_warnings builder option, causing the build to fail when drift_dev reports warnings.
  • forbids returning 0 from the schemaVersion getter. This has always been broken, so the explicit check leads to a better error message.
drift - Drift 2.8.1

Published by simolus3 over 1 year ago

This patch release fixes the following issues in the core drift package:

  • Fix a deadlock after rolling back a transaction in a remote isolate.
  • Remove unintended log messages when using connectToDriftWorker.

Also, drift_dev: 2.8.3 and sqlparser: 0.30.1 have been released with these changes:

  • Allow Dart-defined tables to reference imported tables through SQL #2433.
  • Report syntax error for WITH clauses in triggers.
drift - Drift 2.8.0

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:

  • Don't keep databases in an unusable state if the setup callback throws an exception. Instead, drift will retry the next time the database is used.
  • Fix deadlocks when computeWithDatabase is called inside a transaction().
  • Fix compilation issues with analyzer: 5.12.0.
drift - Drift 2.7.0

Published by simolus3 over 1 year ago

  • Add support for CASE expressions without a base in the Dart API with the CaseWhenExpression class.
  • Add the new package:drift/web/workers.dart library which makes it easier to create web workers for drift.
  • Make validateDatabaseSchema() work in migration tests.
  • Fix queries from transitive imports in drift files not being analyzed reliably.
  • Fix false-positive warnings about AS aliases in subqueries used in triggers.
  • Fix false-positive warnings about referencing a result column in a GROUP BY or HAVING clause.
drift - Drift 2.5.0

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.

Query builder

  • Add isExp, isValue, isNotExp and isNotValue methods to Expression to generate the IS operator in SQL.
  • Add all() extension on tables and views to quickly query all rows.

Isolate improvements

  • Add 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.
  • The DatabaseConnection class now implements QueryExecutor, meaning that you no longer need a special .connect() constructor to use it.
  • The generate_connect_constructor option is now deprecated, as a DatabaseConnection can be passed whereever a QueryExecutor is used too.

Drift files

  • Support MAPPED BY for individual columns in queries or in views defined with SQL.
  • Support a CAST to an enum type in drift files.
  • Consistently interpret CAST (x AS DATETIME) and CAST(x AS TEXT) in drift files.
  • Support two different queries using LIST() columns having the same result class name.

Miscellaneous changes and fixes

  • Fix table classes not extending defining Dart classes with modular generation.
  • Fix @UseDataClass with extending not working with modular generation.
  • Fix generating invalid code when using a type converter with a nullable JSON type.
  • Avoid unecessary async modifier when mapping queries to existing row classes.
drift - Drift 2.4.2

Published by simolus3 almost 2 years ago

drift 2.4.2

  • Fix an exception when a client disconnects from a drift remote server while processing a pending table update.

drift_dev 2.4.1

  • Improvements and fixes for schema files:
    • Fix views with an existing row type generating invalid SQL in schema files.
    • Fix schema generate --companions implicitly requiring --data-classes as well.
    • Fix toColumns() not being generated correctly.
    • Fix conflicting names being generated by schema generate when using existing row types on views.

sqlparser 0.26.0

  • Remove token parameter from constructor in Literal subclasses and NumberedVariable.
Package Rankings
Top 1.13% on Pub.dev
Badges
Extracted from project README
Build Status Using melos Main version Generator version sqlparser
Related Projects