2026-01-21 00:53:59 -03:00
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
|
|
|
|
|
|
import 'tables.dart';
|
|
|
|
|
|
|
|
|
|
abstract class CategoryTodoCountView extends View {
|
|
|
|
|
TodosTable get todos;
|
|
|
|
|
Categories get categories;
|
|
|
|
|
|
|
|
|
|
Expression<int> get categoryId => categories.id;
|
|
|
|
|
Expression<String> get description => categories.description + const Variable('!');
|
|
|
|
|
Expression<int> get itemCount => todos.id.count();
|
|
|
|
|
|
|
|
|
|
@override
|
2026-01-25 23:23:47 -03:00
|
|
|
Query as() =>
|
|
|
|
|
select(
|
|
|
|
|
[categoryId, description, itemCount],
|
|
|
|
|
).from(categories).join([
|
|
|
|
|
innerJoin(todos, todos.category.equalsExp(categories.id)),
|
|
|
|
|
])
|
|
|
|
|
..groupBy([categories.id]);
|
2026-01-21 00:53:59 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract class TodoWithCategoryView extends View {
|
|
|
|
|
TodosTable get todos;
|
|
|
|
|
Categories get categories;
|
|
|
|
|
|
|
|
|
|
@override
|
2026-01-25 23:23:47 -03:00
|
|
|
Query as() =>
|
|
|
|
|
select(
|
|
|
|
|
[todos.title, categories.description],
|
|
|
|
|
).from(todos).join([
|
|
|
|
|
innerJoin(categories, categories.id.equalsExp(todos.category)),
|
|
|
|
|
]);
|
2026-01-21 00:53:59 -03:00
|
|
|
}
|