Include views in generated accessors

This commit is contained in:
Simon Binder 2022-02-17 16:23:02 +01:00
parent de6a083c69
commit 83deb5bb4d
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 8 additions and 3 deletions

View File

@ -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 '

View File

@ -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',

View File

@ -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');
}

View File