NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
pub.dev
pub.dev, #2531 most downloaded on pub.dev
A Flutter-only implementation of a drift database, based on the `sqflite` package.
Latest stable
2.0.1
Last release 3 years ago
no release in 18 months
Ships on a steady schedule
a new release about every 8 months
Nearly every release is documented
notes for 3 of 3 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
3 releases · first in 2022
Drag across the ruler to compare, or tap a release to open it.
Introduced isBetween and isBetweenValues methods for comparable expressions (int, double, datetime) to check values for both an upper and lower bound
isBetween and isBetweenValues methods for comparable expressions (int, double, datetime)
to check values for both an upper and lower boundBOOLEAN and DATETIME columns declared in a sql file to the appropriate type
(both used to be double before).\r as whitespace in moor files and compiled queriesInsertable.createCompanion (it was declared as an
internal method, but you will have to re-run the build)Finally, we also removed a variety of deprecated features. See the breaking changes section to learn what components are affected and what alternative…
Your coding agent can read these notes before it upgrades. Set up the MCP server →
This is the first major update after the initial release and moor and we have a lot to cover:
.moor files can now have their own imports and queries, you can embed Dart in sql queries
using the new templates feature and we have a prototype of a pure-Dart SQL IDE ready.
Finally, we also removed a variety of deprecated features. See the breaking changes
section to learn what components are affected and what alternatives are available.
.moor files were introduced in moor 1.7 as an experimental way to declare tables by using
CREATE TABLE statements. In this version, they become stable and support their own import
and query system. This allows you to write queries in their own file:
CREATE TABLE users (
id INT NOT NULL PRIMARY KEY AUTOINCREMENT,
name VARCHAR NOT NULL
);
findByName: SELECT * FROM users WHERE name LIKE :query;
When this file is included from a @UseMoor annotation, moor will generate methods to run the
query. Of course, you can also write Dart queries for tables declared in sql:
Stream<User> loadUserById(int id) {
return (select(users)..where((u) => u.id.equals(2))).watchSingle();
}
Moor files can also import other moor files by using an import 'other.moor'; statement at the
top. Then, all tables defined in other.moor will also be available to the current file.
Moor takes Dart and SQL interop even further with the new "Dart in SQL templates". You can define a query like this:
findDynamic: SELECT * FROM users WHERE $condition;
And moor will generate a method findDynamic(Expression<bool, BoolType> condition) for you. This
allows you to bind the template with a predicate as complex as you'd like. At the moment, Dart
templates are supported for expressions, OrderBy, OrderingTerm and Limit.
INSERT statements can now be used as a compiled statement - both in moor files and
in a @UseMoor or @UseDao annotation. A new builtin linter will even warn you when you forget
to provide a value for a non-nullable column - right at compile time!
And finally, we now generate better query code when queries only return a single column. Instead of generating a whole new class for that, we simply return the value directly.
We released an experimental version of moor built on top of dart:ffi. It works
cross-platform and is much, much faster than moor_flutter. It you want to try
it out, read the docs here.
Constant<String> can now be written to SQL, it used to throw before. This is useful
if you need default values for strings columns. This also works for BLOBS
(Constant<Uint8List>).LazyDatabase for when you want to construct a database asynchronously (for instance, if
you first need to find a file before you can open a database).THIS LIKELY AFFECTS YOUR APP: Removed the transaction parameter for callbacks
in transactions and beforeOpen callbacks. So, instead of writing
transaction((t) async {
await t.update(table)...;
});
simply write
transaction(() async {
await update(table)...;
});
Similarly, instead of using onOpen: (db, details) async {...}, use
onOpen: (details) async {...}. You don't have to worry about calling methods on
your database instead of a transaction objects. They will be delegated automatically.
On a similar note, we also removed the operateOn parameter from compiled queries.
Compiled queries that return only a single column (e.g. SELECT COUNT(*) FROM users)
will just return their value (in this case, an int) now. Moor no longer generates a
new class in that case.
Removed MigrationStrategy.onFinished. Use beforeOpen instead.
Compiled sql queries starting with an underscore will now generate private match queries.
Previously, the query _allUsers would generate a watchAllUsers method, that has been
adopted to _watchAllUsers. The generate_private_watch_methods builder option, which
backported this fix to older versions, has thus been removed.
Removed InsertStatement.insertOrReplace. Use insert(data, orReplace: true) instead.
Removed the diff util and MoorAnimatedList. Use a third party library for that.
Initial release, replacing the moor_flutter package.
moor_flutter package.One column per quarter.