mirror of https://github.com/AMT-Cheif/drift.git
Migrate example to 1.6, update readme
This commit is contained in:
parent
d01b5c750f
commit
df05e643e0
|
@ -1,10 +1,30 @@
|
||||||
## 1.6 (unreleased)
|
## 1.6 (unreleased)
|
||||||
- Web support! See [the documentation](https://moor.simonbinder.eu/web) for details.
|
- Experimental web support! See [the documentation](https://moor.simonbinder.eu/web) for details.
|
||||||
- Date time columns are now comparable
|
- Make transactions easier to use: Thanks to some Dart async magic, you no longer need to run
|
||||||
- Make transactions easier to use: Thanks to some Dart async magic, methods called on your
|
queries on the transaction explicitly. This
|
||||||
database object in a transaction callback will automatically be called on the transaction object.
|
```dart
|
||||||
- Syntax sugar for list parameters in compiled custom queries (`SELECT * FROM entries WHERE id IN ?`)
|
Future deleteCategory(Category category) {
|
||||||
|
return transaction((t) async {
|
||||||
|
await t.delete(categories).delete(category);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
is now the same as this (notice how we don't have to use the `t.` in front of the delete)
|
||||||
|
```dart
|
||||||
|
Future deleteCategory(Category category) {
|
||||||
|
return transaction((t) async {
|
||||||
|
await delete(categories).delete(category);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
```
|
||||||
|
This makes it much easier to compose operations by extracting them into methods, as you don't
|
||||||
|
have to worry about not using the `t` parameter.
|
||||||
|
- Moor now provides syntax sugar for list parameters in compiled custom queries
|
||||||
|
(`SELECT * FROM entries WHERE id IN ?`)
|
||||||
- Support `COLLATE` expressions.
|
- Support `COLLATE` expressions.
|
||||||
|
- Date time columns are now comparable
|
||||||
|
- The `StringType` now supports arbitrary data from sqlite ([#70](https://github.com/simolus3/moor/pull/70)).
|
||||||
|
Thanks, [knaeckeKami](https://github.com/knaeckeKami)!
|
||||||
|
|
||||||
## 1.5.1
|
## 1.5.1
|
||||||
- Fixed an issue where transformed streams would not always update
|
- Fixed an issue where transformed streams would not always update
|
||||||
|
|
|
@ -1199,7 +1199,8 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<AllTodosWithCategoryResult>> allTodosWithCategory(
|
Future<List<AllTodosWithCategoryResult>> allTodosWithCategory(
|
||||||
{QueryEngine operateOn}) {
|
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||||
|
QueryEngine operateOn}) {
|
||||||
return (operateOn ?? this).customSelect(
|
return (operateOn ?? this).customSelect(
|
||||||
'SELECT t.*, c.id as catId, c."desc" as catDesc FROM todos t INNER JOIN categories c ON c.id = t.category',
|
'SELECT t.*, c.id as catId, c."desc" as catDesc FROM todos t INNER JOIN categories c ON c.id = t.category',
|
||||||
variables: []).then((rows) => rows.map(_rowToAllTodosWithCategoryResult).toList());
|
variables: []).then((rows) => rows.map(_rowToAllTodosWithCategoryResult).toList());
|
||||||
|
@ -1215,7 +1216,10 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
}).map((rows) => rows.map(_rowToAllTodosWithCategoryResult).toList());
|
}).map((rows) => rows.map(_rowToAllTodosWithCategoryResult).toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<int> deleteTodoById(int var1, {QueryEngine operateOn}) {
|
Future<int> deleteTodoById(
|
||||||
|
int var1,
|
||||||
|
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||||
|
QueryEngine operateOn}) {
|
||||||
return (operateOn ?? this).customUpdate(
|
return (operateOn ?? this).customUpdate(
|
||||||
'DELETE FROM todos WHERE id = ?',
|
'DELETE FROM todos WHERE id = ?',
|
||||||
variables: [
|
variables: [
|
||||||
|
@ -1235,8 +1239,12 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<TodoEntry>> withIn(String var1, String var2, List<int> var3,
|
Future<List<TodoEntry>> withIn(
|
||||||
{QueryEngine operateOn}) {
|
String var1,
|
||||||
|
String var2,
|
||||||
|
List<int> var3,
|
||||||
|
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||||
|
QueryEngine operateOn}) {
|
||||||
final expandedvar3 = List.filled(var3.length, '?').join(',');
|
final expandedvar3 = List.filled(var3.length, '?').join(',');
|
||||||
return (operateOn ?? this).customSelect(
|
return (operateOn ?? this).customSelect(
|
||||||
'SELECT * FROM todos WHERE title = ?2 OR id IN ($expandedvar3) OR title = ?1',
|
'SELECT * FROM todos WHERE title = ?2 OR id IN ($expandedvar3) OR title = ?1',
|
||||||
|
@ -1291,7 +1299,10 @@ mixin _$SomeDaoMixin on DatabaseAccessor<TodoDb> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<TodoEntry>> todosForUser(int user, {QueryEngine operateOn}) {
|
Future<List<TodoEntry>> todosForUser(
|
||||||
|
int user,
|
||||||
|
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||||
|
QueryEngine operateOn}) {
|
||||||
return (operateOn ?? this).customSelect(
|
return (operateOn ?? this).customSelect(
|
||||||
'SELECT t.* FROM todos t INNER JOIN shared_todos st ON st.todo = t.id INNER JOIN users u ON u.id = st.user WHERE u.id = :user',
|
'SELECT t.* FROM todos t INNER JOIN shared_todos st ON st.todo = t.id INNER JOIN users u ON u.id = st.user WHERE u.id = :user',
|
||||||
variables: [
|
variables: [
|
||||||
|
|
|
@ -66,24 +66,23 @@ class Database extends _$Database {
|
||||||
beforeOpen: (db, details) async {
|
beforeOpen: (db, details) async {
|
||||||
if (details.wasCreated) {
|
if (details.wasCreated) {
|
||||||
// create default categories and entries
|
// create default categories and entries
|
||||||
final workId = await db
|
final workId = await into(categories)
|
||||||
.into(categories)
|
|
||||||
.insert(const CategoriesCompanion(description: Value('Work')));
|
.insert(const CategoriesCompanion(description: Value('Work')));
|
||||||
|
|
||||||
await db.into(todos).insert(TodosCompanion(
|
await into(todos).insert(TodosCompanion(
|
||||||
content: const Value('A first todo entry'),
|
content: const Value('A first todo entry'),
|
||||||
targetDate: Value(DateTime.now()),
|
targetDate: Value(DateTime.now()),
|
||||||
));
|
));
|
||||||
|
|
||||||
await db.into(todos).insert(
|
await into(todos).insert(
|
||||||
TodosCompanion(
|
TodosCompanion(
|
||||||
content: const Value('Rework persistence code'),
|
content: const Value('Rework persistence code'),
|
||||||
category: Value(workId),
|
category: Value(workId),
|
||||||
targetDate: Value(
|
targetDate: Value(
|
||||||
DateTime.now().add(const Duration(days: 4)),
|
DateTime.now().add(const Duration(days: 4)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -156,8 +155,8 @@ class Database extends _$Database {
|
||||||
|
|
||||||
Future deleteCategory(Category category) {
|
Future deleteCategory(Category category) {
|
||||||
return transaction((t) async {
|
return transaction((t) async {
|
||||||
await _resetCategory(category.id, operateOn: t);
|
await _resetCategory(category.id);
|
||||||
await t.delete(categories).delete(category);
|
await delete(categories).delete(category);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,15 +388,17 @@ abstract class _$Database extends GeneratedDatabase {
|
||||||
$TodosTable get todos => _todos ??= $TodosTable(this);
|
$TodosTable get todos => _todos ??= $TodosTable(this);
|
||||||
$CategoriesTable _categories;
|
$CategoriesTable _categories;
|
||||||
$CategoriesTable get categories => _categories ??= $CategoriesTable(this);
|
$CategoriesTable get categories => _categories ??= $CategoriesTable(this);
|
||||||
Future<int> _resetCategory(int var1, {QueryEngine operateOn}) {
|
Future<int> _resetCategory(
|
||||||
|
int var1,
|
||||||
|
{@Deprecated('No longer needed with Moor 1.6 - see the changelog for details')
|
||||||
|
QueryEngine operateOn}) {
|
||||||
return (operateOn ?? this).customUpdate(
|
return (operateOn ?? this).customUpdate(
|
||||||
'UPDATE todos SET category = NULL WHERE category = ?',
|
'UPDATE todos SET category = NULL WHERE category = ?',
|
||||||
variables: [
|
variables: [
|
||||||
Variable.withInt(var1),
|
Variable.withInt(var1),
|
||||||
],
|
],
|
||||||
updates: {
|
updates: {todos},
|
||||||
todos
|
);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -4,6 +4,9 @@ import 'package:moor_generator/src/utils/string_escaper.dart';
|
||||||
import 'package:recase/recase.dart';
|
import 'package:recase/recase.dart';
|
||||||
import 'package:sqlparser/sqlparser.dart';
|
import 'package:sqlparser/sqlparser.dart';
|
||||||
|
|
||||||
|
const queryEngineWarningDesc =
|
||||||
|
'No longer needed with Moor 1.6 - see the changelog for details';
|
||||||
|
|
||||||
/// Writes the handling code for a query. The code emitted will be a method that
|
/// Writes the handling code for a query. The code emitted will be a method that
|
||||||
/// should be included in a generated database or dao class.
|
/// should be included in a generated database or dao class.
|
||||||
class QueryWriter {
|
class QueryWriter {
|
||||||
|
@ -137,7 +140,8 @@ class QueryWriter {
|
||||||
// execute the statement,
|
// execute the statement,
|
||||||
if (!dontOverrideEngine) {
|
if (!dontOverrideEngine) {
|
||||||
if (query.variables.isNotEmpty) buffer.write(', ');
|
if (query.variables.isNotEmpty) buffer.write(', ');
|
||||||
buffer.write('{QueryEngine operateOn}');
|
buffer.write('{@Deprecated(${asDartLiteral(queryEngineWarningDesc)}) '
|
||||||
|
'QueryEngine operateOn}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue