mirror of https://github.com/AMT-Cheif/drift.git
parent
2de76c65ac
commit
3b09d819f9
|
@ -22,7 +22,8 @@ abstract class TextColumn extends Column<String, StringType> {
|
|||
|
||||
/// A column that stores a [DateTime]. Times will be stored as unix timestamp
|
||||
/// and will thus have a second accuracy.
|
||||
abstract class DateTimeColumn extends Column<DateTime, DateTimeType> {}
|
||||
abstract class DateTimeColumn extends Column<DateTime, DateTimeType>
|
||||
implements DateTimeExpression {}
|
||||
|
||||
/// A column that stores arbitrary blobs of data as a [Uint8List].
|
||||
abstract class BlobColumn extends Column<Uint8List, BlobType> {}
|
||||
|
|
|
@ -7,6 +7,9 @@ abstract class IntExpression extends Expression<int, IntType>
|
|||
abstract class DoubleExpression extends Expression<double, RealType>
|
||||
implements ComparableExpr<double, RealType> {}
|
||||
|
||||
abstract class DateTimeExpression extends Expression<DateTime, DateTimeType>
|
||||
implements ComparableExpr<DateTime, DateTimeType> {}
|
||||
|
||||
mixin ComparableExpr<DT, ST extends SqlType<DT>> on Expression<DT, ST> {
|
||||
/// Returns an expression that is true if this expression is strictly bigger
|
||||
/// than the other expression.
|
||||
|
|
|
@ -35,13 +35,19 @@ Expression<int, IntType> second(Expression<DateTime, DateTimeType> date) =>
|
|||
|
||||
/// 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 =
|
||||
CustomExpression("strftime('%s', CURRENT_DATE)");
|
||||
const DateTimeExpression currentDate =
|
||||
_CustomDateTimeExpression("strftime('%s', CURRENT_DATE)");
|
||||
|
||||
/// A sql expression that evaluates to the current date and time, similar to
|
||||
/// [DateTime.now]. Timestamps are stored with a second accuracy.
|
||||
const Expression<DateTime, DateTimeType> currentDateAndTime =
|
||||
CustomExpression("strftime('%s', CURRENT_TIMESTAMP)");
|
||||
const DateTimeExpression currentDateAndTime =
|
||||
_CustomDateTimeExpression("strftime('%s', CURRENT_TIMESTAMP)");
|
||||
|
||||
class _CustomDateTimeExpression extends CustomExpression<DateTime, DateTimeType>
|
||||
with ComparableExpr
|
||||
implements DateTimeExpression {
|
||||
const _CustomDateTimeExpression(String content) : super(content);
|
||||
}
|
||||
|
||||
/// Expression that extracts components out of a date time by using the builtin
|
||||
/// sqlite function "strftime" and casting the result to an integer.
|
||||
|
|
|
@ -201,6 +201,7 @@ class GeneratedIntColumn extends GeneratedColumn<int, IntType>
|
|||
}
|
||||
|
||||
class GeneratedDateTimeColumn extends GeneratedColumn<DateTime, DateTimeType>
|
||||
with ComparableExpr
|
||||
implements DateTimeColumn {
|
||||
GeneratedDateTimeColumn(
|
||||
String $name,
|
||||
|
|
|
@ -15,4 +15,11 @@ void main() {
|
|||
expect(nullableQuery.sql, equals('name INTEGER NULL'));
|
||||
expect(nonNullQuery.sql, equals('name INTEGER NOT NULL'));
|
||||
});
|
||||
|
||||
test('can compare', () {
|
||||
final ctx = GenerationContext(null, null);
|
||||
nonNull.isSmallerThan(currentDateAndTime).writeInto(ctx);
|
||||
|
||||
expect(ctx.sql, 'name < strftime(\'%s\', CURRENT_TIMESTAMP)');
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue