mirror of https://github.com/AMT-Cheif/drift.git
add new table with every type of column for tests
This commit is contained in:
parent
3bd837517c
commit
14335b5d3d
|
@ -24,9 +24,6 @@ class TodosTable extends Table with AutoIncrement {
|
|||
@JsonKey('target_date')
|
||||
DateTimeColumn get targetDate => dateTime().nullable().unique()();
|
||||
|
||||
RealColumn get someFloat => real().nullable()();
|
||||
Int64Column get someInt64 => int64().nullable()();
|
||||
|
||||
IntColumn get category => integer().references(Categories, #id).nullable()();
|
||||
|
||||
TextColumn get status => textEnum<TodoStatus>().nullable()();
|
||||
|
@ -90,6 +87,22 @@ class TableWithoutPK extends Table {
|
|||
text().map(const CustomConverter()).clientDefault(_uuid.v4)();
|
||||
}
|
||||
|
||||
class TableWithEveryColumnType extends Table with AutoIncrement {
|
||||
BoolColumn get aBool => boolean().nullable()();
|
||||
DateTimeColumn get aDateTime => dateTime().nullable()();
|
||||
TextColumn get aText => text().nullable()();
|
||||
IntColumn get anInt => integer().nullable()();
|
||||
Int64Column get anInt64 => int64().nullable()();
|
||||
RealColumn get aReal => real().nullable()();
|
||||
BlobColumn get aBlob => blob().nullable()();
|
||||
IntColumn get anIntEnum => intEnum<TodoStatus>().nullable()();
|
||||
TextColumn get aTextWithConverter => text()
|
||||
.named('insert')
|
||||
.map(const CustomJsonConverter())
|
||||
.nullable()
|
||||
.nullable()();
|
||||
}
|
||||
|
||||
class CustomRowClass {
|
||||
final int notReallyAnId;
|
||||
final double anotherName;
|
||||
|
@ -251,6 +264,7 @@ const uuidType = DialectAwareSqlType<UuidValue>.via(
|
|||
TableWithoutPK,
|
||||
PureDefaults,
|
||||
WithCustomType,
|
||||
TableWithEveryColumnType
|
||||
],
|
||||
views: [
|
||||
CategoryTodoCountView,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,246 +23,256 @@ void main() {
|
|||
// (o) => o(priority: Value(CategoryPriority.high), description: "Other"));
|
||||
|
||||
// // School
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Get that math homework done",
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: Value("Get that math homework done"),
|
||||
// title: Value("Math Homework"),
|
||||
// category: Value(schoolId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1,seconds: 10)))));
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Finish that report",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1,seconds: 10)))));
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Finish that report",
|
||||
// title: Value("Report"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.workInProgress),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 2,seconds: 10)))));
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Get that english homework done",
|
||||
// anIntEnum: Value(TodoStatus.workInProgress),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 2,seconds: 10)))));
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Get that english homework done",
|
||||
// title: Value("English Homework"),
|
||||
// category: Value(schoolId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1,seconds: 15)))));
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Finish that Book report",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1,seconds: 15)))));
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Finish that Book report",
|
||||
// title: Value("Book Report"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.done),
|
||||
// targetDate: Value(DateTime.now().subtract(Duration(days: 2,seconds: 15)))));
|
||||
// anIntEnum: Value(TodoStatus.done),
|
||||
// aDateTime: Value(DateTime.now().subtract(Duration(days: 2,seconds: 15)))));
|
||||
|
||||
// // Work
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "File those reports",
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "File those reports",
|
||||
// title: Value("File Reports"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 20)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Clean the office",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 20)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Clean the office",
|
||||
// title: Value("Clean Office"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.workInProgress),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 2, seconds: 20)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Nail that presentation",
|
||||
// anIntEnum: Value(TodoStatus.workInProgress),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 2, seconds: 20)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Nail that presentation",
|
||||
// title: Value("Presentation"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 25)))));
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Take a break",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 25)))));
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Take a break",
|
||||
// title: Value("Break"),
|
||||
// category: Value(workId),
|
||||
// status: Value(TodoStatus.done),
|
||||
// targetDate: Value(DateTime.now().subtract(Duration(days: 2, seconds: 25)))));
|
||||
// anIntEnum: Value(TodoStatus.done),
|
||||
// aDateTime: Value(DateTime.now().subtract(Duration(days: 2, seconds: 25)))));
|
||||
|
||||
// // Work
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Take out the trash",
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Take out the trash",
|
||||
// title: Value("Trash"),
|
||||
// category: Value(homeId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 30)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Mow the lawn",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 30)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Mow the lawn",
|
||||
// title: Value("Lawn"),
|
||||
// category: Value(homeId),
|
||||
// status: Value(TodoStatus.workInProgress),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 2, seconds: 30)))));
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Fix the sink",
|
||||
// anIntEnum: Value(TodoStatus.workInProgress),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 2, seconds: 30)))));
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Fix the sink",
|
||||
// title: Value("Sink"),
|
||||
// category: Value(homeId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 35)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Paint the walls",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 35)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Paint the walls",
|
||||
// title: Value("Paint"),
|
||||
// category: Value(homeId),
|
||||
// status: Value(TodoStatus.done),
|
||||
// targetDate: Value(DateTime.now().subtract(Duration(days: 2, seconds: 35)))));
|
||||
// anIntEnum: Value(TodoStatus.done),
|
||||
// aDateTime: Value(DateTime.now().subtract(Duration(days: 2, seconds: 35)))));
|
||||
|
||||
// // Other
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Get groceries",
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Get groceries",
|
||||
// title: Value("Groceries"),
|
||||
// category: Value(otherId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 40)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Pick up the kids",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 40)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Pick up the kids",
|
||||
// title: Value("Kids"),
|
||||
// category: Value(otherId),
|
||||
// status: Value(TodoStatus.workInProgress),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 2, seconds: 40)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Take the dog for a walk",
|
||||
// anIntEnum: Value(TodoStatus.workInProgress),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 2, seconds: 40)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Take the dog for a walk",
|
||||
// title: Value("Dog"),
|
||||
// category: Value(otherId),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 45)))));
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 45)))));
|
||||
|
||||
// // Items with no category
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Get Whiteboard",
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Get Whiteboard",
|
||||
// title: Value("Whiteboard"),
|
||||
// status: Value(TodoStatus.open),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 1, seconds: 50)))););
|
||||
// await db.managers.todosTable.create((o) => o(
|
||||
// content: "Drink Water",
|
||||
// anIntEnum: Value(TodoStatus.open),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 1, seconds: 50)))););
|
||||
// await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
// aText: "Drink Water",
|
||||
// title: Value("Water"),
|
||||
// status: Value(TodoStatus.workInProgress),
|
||||
// targetDate: Value(DateTime.now().add(Duration(days: 2, seconds: 50)))));
|
||||
// anIntEnum: Value(TodoStatus.workInProgress),
|
||||
// aDateTime: Value(DateTime.now().add(Duration(days: 2, seconds: 50)))));
|
||||
// });
|
||||
|
||||
tearDown(() => db.close());
|
||||
|
||||
test('manager - query generic', () async {
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(5.0),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(3.0),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(5.0),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(3.0),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
|
||||
// Equals
|
||||
expect(
|
||||
db.managers.todosTable.filter((f) => f.someFloat.equals(5.0)).count(),
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.equals(5.0))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(db.managers.todosTable.filter((f) => f.someFloat(3.0)).count(),
|
||||
expect(
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal(3.0))
|
||||
.count(),
|
||||
completion(1));
|
||||
// In
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isIn([3.0, 5.0]))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isIn([3.0, 5.0]))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Not In
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isNotIn([3.0, 5.0]))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isNotIn([3.0, 5.0]))
|
||||
.count(),
|
||||
completion(0));
|
||||
|
||||
// Null check
|
||||
expect(db.managers.todosTable.filter((f) => f.someFloat.isNull()).count(),
|
||||
expect(
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isNull())
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable.filter((f) => f.someFloat.isNotNull()).count(),
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isNotNull())
|
||||
.count(),
|
||||
completion(2));
|
||||
});
|
||||
|
||||
test('manager - query number', () async {
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(5.0),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(3.0),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(5.0),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(3.0),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
|
||||
// More than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isBiggerThan(3.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isBiggerThan(3.0))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isBiggerOrEqualTo(3.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isBiggerOrEqualTo(3.0))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Less than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isSmallerThan(5.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isSmallerThan(5.0))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isSmallerOrEqualTo(5.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isSmallerOrEqualTo(5.0))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Between
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isBetween(3.0, 5.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isBetween(3.0, 5.0))
|
||||
.count(),
|
||||
completion(2));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someFloat.isNotBetween(3.0, 5.0))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aReal.isNotBetween(3.0, 5.0))
|
||||
.count(),
|
||||
completion(0));
|
||||
});
|
||||
|
||||
test('manager - query string', () async {
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "That homework Done",
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("That homework Done"),
|
||||
));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "that MATH homework",
|
||||
status: Value(TodoStatus.open),
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("that MATH homework"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
));
|
||||
|
||||
// StartsWith
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.startsWith("that"))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.startsWith("that"))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// EndsWith
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.endsWith("done"))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.endsWith("done"))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Contains
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.contains("math"))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.contains("math"))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
|
@ -271,77 +281,77 @@ void main() {
|
|||
|
||||
// StartsWith
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.startsWith("that", caseInsensitive: false))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.startsWith("that", caseInsensitive: false))
|
||||
.count(),
|
||||
completion(1));
|
||||
|
||||
// EndsWith
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.endsWith("done", caseInsensitive: false))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.endsWith("done", caseInsensitive: false))
|
||||
.count(),
|
||||
completion(1));
|
||||
|
||||
// Contains
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.content.contains("math", caseInsensitive: false))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aText.contains("math", caseInsensitive: false))
|
||||
.count(),
|
||||
completion(1));
|
||||
});
|
||||
|
||||
test('manager - query int64', () async {
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someInt64: Value(BigInt.from(5.0)),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someInt64: Value(BigInt.from(3.0)),
|
||||
targetDate: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
anInt64: Value(BigInt.from(5.0)),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 1)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 2)))));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
anInt64: Value(BigInt.from(3.0)),
|
||||
aDateTime: Value(DateTime.now().add(Duration(days: 3)))));
|
||||
|
||||
// More than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someInt64.isBiggerThan(BigInt.from(3.0)))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anInt64.isBiggerThan(BigInt.from(3.0)))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someInt64.isBiggerOrEqualTo(BigInt.from(3.0)))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anInt64.isBiggerOrEqualTo(BigInt.from(3.0)))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Less than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someInt64.isSmallerThan(BigInt.from(5.0)))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anInt64.isSmallerThan(BigInt.from(5.0)))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.someInt64.isSmallerOrEqualTo(BigInt.from(5.0)))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anInt64.isSmallerOrEqualTo(BigInt.from(5.0)))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Between
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) =>
|
||||
f.someInt64.isBetween(BigInt.from(3.0), BigInt.from(5.0)))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter(
|
||||
(f) => f.anInt64.isBetween(BigInt.from(3.0), BigInt.from(5.0)))
|
||||
.count(),
|
||||
completion(2));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) =>
|
||||
f.someInt64.isNotBetween(BigInt.from(3.0), BigInt.from(5.0)))
|
||||
f.anInt64.isNotBetween(BigInt.from(3.0), BigInt.from(5.0)))
|
||||
.count(),
|
||||
completion(0));
|
||||
});
|
||||
|
@ -375,95 +385,97 @@ void main() {
|
|||
final day1 = DateTime.now().add(Duration(days: 1));
|
||||
final day2 = DateTime.now().add(Duration(days: 2));
|
||||
final day3 = DateTime.now().add(Duration(days: 3));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(5.0),
|
||||
targetDate: Value(day1)));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
targetDate: Value(day2)));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open),
|
||||
someFloat: Value(3.0),
|
||||
targetDate: Value(day3)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(5.0),
|
||||
aDateTime: Value(day1)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aDateTime: Value(day2)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open),
|
||||
aReal: Value(3.0),
|
||||
aDateTime: Value(day3)));
|
||||
|
||||
// More than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isAfter(day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isAfter(day2))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isAfterOrOn(day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isAfterOrOn(day2))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Less than
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isBefore(day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isBefore(day2))
|
||||
.count(),
|
||||
completion(1));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isBeforeOrOn(day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isBeforeOrOn(day2))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// Between
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isBetween(day1, day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isBetween(day1, day2))
|
||||
.count(),
|
||||
completion(2));
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.targetDate.isNotBetween(day1, day2))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.aDateTime.isNotBetween(day1, day2))
|
||||
.count(),
|
||||
completion(1));
|
||||
});
|
||||
|
||||
test('manager - query custom column', () async {
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open)));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.open)));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.workInProgress)));
|
||||
await db.managers.todosTable.create((o) => o(
|
||||
content: "Get that math homework done",
|
||||
status: Value(TodoStatus.done)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.open)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.workInProgress)));
|
||||
await db.managers.tableWithEveryColumnType.create((o) => o(
|
||||
aText: Value("Get that math homework done"),
|
||||
anIntEnum: Value(TodoStatus.done)));
|
||||
|
||||
// Equals
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) => f.status.equals(TodoStatus.open))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anIntEnum.equals(TodoStatus.open))
|
||||
.count(),
|
||||
completion(2));
|
||||
expect(
|
||||
db.managers.todosTable.filter((f) => f.status(TodoStatus.open)).count(),
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anIntEnum(TodoStatus.open))
|
||||
.count(),
|
||||
completion(2));
|
||||
|
||||
// In
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) =>
|
||||
f.status.isIn([TodoStatus.open, TodoStatus.workInProgress]))
|
||||
f.anIntEnum.isIn([TodoStatus.open, TodoStatus.workInProgress]))
|
||||
.count(),
|
||||
completion(3));
|
||||
|
||||
// Not In
|
||||
expect(
|
||||
db.managers.todosTable
|
||||
.filter((f) =>
|
||||
f.status.isNotIn([TodoStatus.open, TodoStatus.workInProgress]))
|
||||
db.managers.tableWithEveryColumnType
|
||||
.filter((f) => f.anIntEnum
|
||||
.isNotIn([TodoStatus.open, TodoStatus.workInProgress]))
|
||||
.count(),
|
||||
completion(1));
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue