mirror of https://github.com/AMT-Cheif/drift.git
Include views in generated accessors
This commit is contained in:
parent
de6a083c69
commit
83deb5bb4d
|
@ -181,6 +181,7 @@ class TodoDb extends _$TodoDb {
|
|||
|
||||
@DriftAccessor(
|
||||
tables: [Users, SharedTodos, TodosTable],
|
||||
views: [TodoWithCategoryView],
|
||||
queries: {
|
||||
'todosForUser': 'SELECT t.* FROM todos t '
|
||||
'INNER JOIN shared_todos st ON st.todo = t.id '
|
||||
|
|
|
@ -1720,6 +1720,8 @@ mixin _$SomeDaoMixin on DatabaseAccessor<TodoDb> {
|
|||
$SharedTodosTable get sharedTodos => attachedDatabase.sharedTodos;
|
||||
$CategoriesTable get categories => attachedDatabase.categories;
|
||||
$TodosTableTable get todosTable => attachedDatabase.todosTable;
|
||||
$TodoWithCategoryViewView get todoWithCategoryView =>
|
||||
attachedDatabase.todoWithCategoryView;
|
||||
Selectable<TodoEntry> todosForUser({required int user}) {
|
||||
return customSelect(
|
||||
'SELECT t.* FROM todos AS t INNER JOIN shared_todos AS st ON st.todo = t.id INNER JOIN users AS u ON u.id = st.user WHERE u.id = ?1',
|
||||
|
|
|
@ -4,6 +4,8 @@ import 'package:drift_dev/src/utils/type_utils.dart';
|
|||
import 'package:drift_dev/writer.dart';
|
||||
import 'package:source_gen/source_gen.dart';
|
||||
|
||||
import '../../../model/base_entity.dart';
|
||||
|
||||
class DaoGenerator extends Generator implements BaseGenerator {
|
||||
@override
|
||||
late MoorBuilder builder;
|
||||
|
@ -24,9 +26,9 @@ class DaoGenerator extends Generator implements BaseGenerator {
|
|||
classScope.leaf().write('mixin _\$${daoName}Mixin on '
|
||||
'DatabaseAccessor<$dbTypeName> {\n');
|
||||
|
||||
for (final table in dao.tables) {
|
||||
final infoType = table.entityInfoName;
|
||||
final getterName = table.dbGetterName;
|
||||
for (final entity in dao.entities.whereType<MoorEntityWithResultSet>()) {
|
||||
final infoType = entity.entityInfoName;
|
||||
final getterName = entity.dbGetterName;
|
||||
classScope.leaf().write(
|
||||
'$infoType get $getterName => attachedDatabase.$getterName;\n');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue