Migrate example to 1.6, update readme

This commit is contained in:
Simon Binder 2019-07-10 17:55:57 +02:00
parent d01b5c750f
commit df05e643e0
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 72 additions and 36 deletions

View File

@ -1,10 +1,30 @@
## 1.6 (unreleased)
- 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, methods called on your
database object in a transaction callback will automatically be called on the transaction object.
- Syntax sugar for list parameters in compiled custom queries (`SELECT * FROM entries WHERE id IN ?`)
- Experimental web support! See [the documentation](https://moor.simonbinder.eu/web) for details.
- Make transactions easier to use: Thanks to some Dart async magic, you no longer need to run
queries on the transaction explicitly. This
```dart
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.
- 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
- Fixed an issue where transformed streams would not always update

View File

@ -1199,7 +1199,8 @@ abstract class _$TodoDb extends GeneratedDatabase {
}
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(
'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());
@ -1215,7 +1216,10 @@ abstract class _$TodoDb extends GeneratedDatabase {
}).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(
'DELETE FROM todos WHERE id = ?',
variables: [
@ -1235,8 +1239,12 @@ abstract class _$TodoDb extends GeneratedDatabase {
);
}
Future<List<TodoEntry>> withIn(String var1, String var2, List<int> var3,
{QueryEngine operateOn}) {
Future<List<TodoEntry>> withIn(
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(',');
return (operateOn ?? this).customSelect(
'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(
'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: [

View File

@ -66,24 +66,23 @@ class Database extends _$Database {
beforeOpen: (db, details) async {
if (details.wasCreated) {
// create default categories and entries
final workId = await db
.into(categories)
final workId = await into(categories)
.insert(const CategoriesCompanion(description: Value('Work')));
await db.into(todos).insert(TodosCompanion(
content: const Value('A first todo entry'),
targetDate: Value(DateTime.now()),
));
await into(todos).insert(TodosCompanion(
content: const Value('A first todo entry'),
targetDate: Value(DateTime.now()),
));
await db.into(todos).insert(
TodosCompanion(
content: const Value('Rework persistence code'),
category: Value(workId),
targetDate: Value(
DateTime.now().add(const Duration(days: 4)),
),
),
);
await into(todos).insert(
TodosCompanion(
content: const Value('Rework persistence code'),
category: Value(workId),
targetDate: Value(
DateTime.now().add(const Duration(days: 4)),
),
),
);
}
},
);
@ -156,8 +155,8 @@ class Database extends _$Database {
Future deleteCategory(Category category) {
return transaction((t) async {
await _resetCategory(category.id, operateOn: t);
await t.delete(categories).delete(category);
await _resetCategory(category.id);
await delete(categories).delete(category);
});
}
}

View File

@ -388,15 +388,17 @@ abstract class _$Database extends GeneratedDatabase {
$TodosTable get todos => _todos ??= $TodosTable(this);
$CategoriesTable _categories;
$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(
'UPDATE todos SET category = NULL WHERE category = ?',
variables: [
Variable.withInt(var1),
],
updates: {
todos
});
'UPDATE todos SET category = NULL WHERE category = ?',
variables: [
Variable.withInt(var1),
],
updates: {todos},
);
}
@override

View File

@ -4,6 +4,9 @@ import 'package:moor_generator/src/utils/string_escaper.dart';
import 'package:recase/recase.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
/// should be included in a generated database or dao class.
class QueryWriter {
@ -137,7 +140,8 @@ class QueryWriter {
// execute the statement,
if (!dontOverrideEngine) {
if (query.variables.isNotEmpty) buffer.write(', ');
buffer.write('{QueryEngine operateOn}');
buffer.write('{@Deprecated(${asDartLiteral(queryEngineWarningDesc)}) '
'QueryEngine operateOn}');
}
}