Remove top-level isIn and isNotIn methods

This commit is contained in:
Simon Binder 2020-02-17 21:15:31 +01:00
parent d43e227757
commit ad5ef7e66b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 8 additions and 27 deletions

View File

@ -5,9 +5,11 @@
- top-level `and`, `or` and `not` methods. Use the `&`, `|` and `.not()` instead.
- top-level `year`, `month`, `day`, `hour`, `minute`, `second` methods.
Use the extension member on `Expression<DateTime>` instead.
- `InsertStatement.insertAll` (use batches instead)
- the `orReplace` boolean parameter on inserts (use `mode: InsertMode.orReplace` instead)
- remove the top-level `isIn` and `isNotIn` functions
(use the `.isIn` and `.isNotIn` instance methods instead)
- __Breaking__: Remove the second type variable on `Expression` and subclasses.
- __Breaking__: Remove `InsertStatement.insertAll` (use batches instead) and `insert(orReplace: true)`
(use `mode: InsertMode.orReplace` instead).
- __Breaking__: Remove `customSelectStream` from `QueryEngine`. The `customSelect`
method now returns an `Selectable` (like `customSelectQuery`, which in turn has been deprecated).
- Experimentally support IndexedDB to store sqlite data on the web

View File

@ -42,7 +42,7 @@ class IngredientInRecipes extends Table {
queries: {
// query to load the total weight for each recipe by loading all ingredients
// and taking the sum of their amountInGrams.
'_totalWeight': '''
'totalWeight': '''
SELECT r.title, SUM(ir.amount) AS total_weight
FROM recipes r
INNER JOIN recipe_ingredients ir ON ir.recipe = r.id

View File

@ -862,7 +862,7 @@ abstract class _$Database extends GeneratedDatabase {
);
}
Selectable<TotalWeightResult> _totalWeight() {
Selectable<TotalWeightResult> totalWeight() {
return customSelect(
'SELECT r.title, SUM(ir.amount) AS total_weight\n FROM recipes r\n INNER JOIN recipe_ingredients ir ON ir.recipe = r.id\n GROUP BY r.id',
variables: [],

View File

@ -1,23 +1,5 @@
part of '../query_builder.dart';
/// An expression that is true if the given [expression] resolves to any of the
/// values in [values].
@Deprecated('Use Expression.isIn instead')
Expression<bool> isIn<T>(Expression<T> expression, Iterable<T> values,
{bool not = false}) {
if (not == true) {
return expression.isNotIn(values);
} else {
return expression.isIn(values);
}
}
/// An expression that is true if the given [expression] does not resolve to any
/// of the values in [values].
@Deprecated('Use Expression.isNotIn instead')
Expression<bool> isNotIn<T>(Expression<T> expression, Iterable<T> values) =>
isIn(expression, values, not: true);
class _InExpression<T> extends Expression<bool> {
final Expression<T> _expression;
final List<T> _values;

View File

@ -1,6 +1,5 @@
import 'package:test/test.dart';
import 'package:moor/moor.dart';
import 'package:moor/moor.dart' as moor;
import '../data/tables/todos.dart';
import '../data/utils/expect_generated.dart';
@ -8,8 +7,7 @@ import '../data/utils/expect_generated.dart';
void main() {
test('in expressions are generated', () {
final innerExpression = GeneratedTextColumn('name', null, true);
// ignore: deprecated_member_use_from_same_package
final isInExpression = moor.isIn(innerExpression, ['Max', 'Tobias']);
final isInExpression = innerExpression.isIn(['Max', 'Tobias']);
final context = GenerationContext.fromDb(TodoDb(null));
isInExpression.writeInto(context);
@ -20,8 +18,7 @@ void main() {
test('not in expressions are generated', () {
final innerExpression = GeneratedTextColumn('name', null, true);
// ignore: deprecated_member_use_from_same_package
final isNotIn = moor.isNotIn(innerExpression, ['Foo', 'Bar']);
final isNotIn = innerExpression.isNotIn(['Max', 'Tobias']);
expect(isNotIn, generates('name NOT IN (?, ?)', ['Foo', 'Bar']));
});