Remove top-level boolean and datetime functions

This commit is contained in:
Simon Binder 2020-02-17 17:17:46 +01:00
parent 9e1a12432a
commit f15f004ba8
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 10 additions and 81 deletions

View File

@ -1,6 +1,10 @@
## 3.0.0-dev
- __Breaking__: `package:moor/moor_web.dart` no longer exports `package:moor/moor.dart`.
- __Breaking__: Remove deprecated members:
- 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.
- Experimentally support IndexedDB to store sqlite data on the web

View File

@ -1,30 +1,5 @@
part of '../query_builder.dart';
/// Returns an expression that is true iff both [a] and [b] are true.
///
/// This is now deprecated. Instead of `and(a, b)`, use `a & b`.
@Deprecated('Use the operator on BooleanExpressionOperators instead')
Expression<bool, BoolType> and(
Expression<bool, BoolType> a, Expression<bool, BoolType> b) {
return a & b;
}
/// Returns an expression that is true iff [a], [b] or both are true.
///
/// This is now deprecated. Instead of `or(a, b)`, use `a | b`;
@Deprecated('Use the operator on BooleanExpressionOperators instead')
Expression<bool, BoolType> or(
Expression<bool, BoolType> a, Expression<bool, BoolType> b) {
return a | b;
}
/// Returns an expression that is true iff [a] is not true.
///
/// This is now deprecated. Instead of `not(a)`, prefer to use `a.not()` now.
@Deprecated('Use BooleanExpressionOperators.not() as a extension instead')
Expression<bool, BoolType> not(Expression<bool, BoolType> a) =>
_NotExpression(a);
/// Defines operations on boolean values.
extension BooleanExpressionOperators on Expression<bool, BoolType> {
/// Negates this boolean expression. The returned expression is true if

View File

@ -1,41 +1,5 @@
part of '../query_builder.dart';
/// Extracts the (UTC) year from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.year instead')
Expression<int, IntType> year(Expression<DateTime, DateTimeType> date) =>
date.year;
/// Extracts the (UTC) month from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.month instead')
Expression<int, IntType> month(Expression<DateTime, DateTimeType> date) =>
date.month;
/// Extracts the (UTC) day from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.day instead')
Expression<int, IntType> day(Expression<DateTime, DateTimeType> date) =>
date.day;
/// Extracts the (UTC) hour from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.hour instead')
Expression<int, IntType> hour(Expression<DateTime, DateTimeType> date) =>
date.hour;
/// Extracts the (UTC) minute from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.minute instead')
Expression<int, IntType> minute(Expression<DateTime, DateTimeType> date) =>
date.minute;
/// Extracts the (UTC) second from the given expression that resolves
/// to a datetime.
@Deprecated('Use date.second instead')
Expression<int, IntType> second(Expression<DateTime, DateTimeType> date) =>
date.second;
/// A sql expression that evaluates to the current date represented as a unix
/// timestamp. The hour, minute and second fields will be set to 0.
const Expression<DateTime, DateTimeType> currentDate =

View File

@ -4,8 +4,6 @@ import 'package:test/test.dart';
import '../data/utils/expect_equality.dart';
import '../data/utils/expect_generated.dart';
// ignore_for_file: deprecated_member_use_from_same_package
void main() {
final a = GeneratedBoolColumn('a', 'tbl', false);
final b = GeneratedBoolColumn('b', 'tbl', false);
@ -18,13 +16,4 @@ void main() {
expectEquals(a & b, a & b);
expectNotEquals(a | b, b | a);
});
test('boolean expressions via top-level methods', () {
expect(or(a, b), generates('a OR b'));
expect(and(a, b), generates('a AND b'));
expect(not(a), generates('NOT a'));
expectEquals(not(a), not(a));
expectNotEquals(not(a), not(b));
});
}

View File

@ -3,23 +3,20 @@ import 'package:test/test.dart';
import '../data/utils/expect_equality.dart';
// ignore_for_file: deprecated_member_use_from_same_package
typedef _Extractor = Expression<int, IntType> Function(
Expression<DateTime, DateTimeType> d);
/// Tests the top level [year], [month], ..., [second] methods
void main() {
final column = GeneratedDateTimeColumn('val', null, false);
group('extracting information via top-level method', () {
final expectedResults = <_Extractor, String>{
year: 'CAST(strftime("%Y", val, "unixepoch") AS INTEGER)',
month: 'CAST(strftime("%m", val, "unixepoch") AS INTEGER)',
day: 'CAST(strftime("%d", val, "unixepoch") AS INTEGER)',
hour: 'CAST(strftime("%H", val, "unixepoch") AS INTEGER)',
minute: 'CAST(strftime("%M", val, "unixepoch") AS INTEGER)',
second: 'CAST(strftime("%S", val, "unixepoch") AS INTEGER)',
(d) => d.year: 'CAST(strftime("%Y", val, "unixepoch") AS INTEGER)',
(d) => d.month: 'CAST(strftime("%m", val, "unixepoch") AS INTEGER)',
(d) => d.day: 'CAST(strftime("%d", val, "unixepoch") AS INTEGER)',
(d) => d.hour: 'CAST(strftime("%H", val, "unixepoch") AS INTEGER)',
(d) => d.minute: 'CAST(strftime("%M", val, "unixepoch") AS INTEGER)',
(d) => d.second: 'CAST(strftime("%S", val, "unixepoch") AS INTEGER)',
};
expectedResults.forEach((key, value) {