diff --git a/drift_dev/lib/src/writer/manager/manager_templates.dart b/drift_dev/lib/src/writer/manager/manager_templates.dart index cfab7c7b6..cfacf3939 100644 --- a/drift_dev/lib/src/writer/manager/manager_templates.dart +++ b/drift_dev/lib/src/writer/manager/manager_templates.dart @@ -251,7 +251,9 @@ class _ManagerCodeTemplates { db: db, explicitlyWatchedTables: [ ${reverseRelations.map((relation) { - return "if (${relation.fieldName}) db.${relation.referencedTable.dbGetterName}"; + final table = + leaf.referenceElement(relation.referencedTable, 'db'); + return "if (${relation.fieldName}) ${leaf.dartCode(table)}"; }).join(',')} ], addJoins: ${forwardRelations.isEmpty ? 'null' : """ @@ -436,7 +438,7 @@ class _ManagerCodeTemplates { return """${leaf.drift("ColumnFilters")}<$type> get $filterName => \$composableBuilder( column: \$table.$columnGetter, - builder: (column) => + builder: (column) => ${leaf.drift("ColumnFilters")}(column)); """; } @@ -453,7 +455,7 @@ class _ManagerCodeTemplates { return """ ${leaf.drift("ColumnWithTypeConverterFilters")}<$converterType,$nonNullableConverterType,$type> get $filterName => \$composableBuilder( column: \$table.$columnGetter, - builder: (column) => + builder: (column) => ${leaf.drift("ColumnWithTypeConverterFilters")}(column)); """; } @@ -489,7 +491,7 @@ class _ManagerCodeTemplates { return """${leaf.drift("ColumnOrderings")}<$type> get $filterName => \$composableBuilder( column: \$table.$columnGetter, - builder: (column) => + builder: (column) => ${leaf.drift("ColumnOrderings")}(column)); """; } @@ -517,7 +519,7 @@ class _ManagerCodeTemplates { getCurrentColumn: (t) => t.${relation.currentColumn.nameInDart}, referencedTable: ${_referenceTableFromComposer(relation.referencedTable, leaf)}, getReferencedColumn: (t) => t.${relation.referencedColumn.nameInDart}, - builder: (joinBuilder,{\$addJoinBuilderToRootComposer,\$removeJoinBuilderFromRootComposer }) => + builder: (joinBuilder,{\$addJoinBuilderToRootComposer,\$removeJoinBuilderFromRootComposer }) => $composerName( \$db: \$db, \$table: ${_referenceTableFromComposer(relation.referencedTable, leaf)}, @@ -534,8 +536,12 @@ class _ManagerCodeTemplates { /// as the table manager and is not used outside of the file /// /// E.g. `$UserTableProcessedTableManager` - String processedTableManagerTypedefName(DriftTable table) { - return '\$${table.entityInfoName}ProcessedTableManager'; + String processedTableManagerTypedefName(DriftTable table, TextEmitter leaf, + {bool forDefinition = false}) { + final name = '\$${table.entityInfoName}ProcessedTableManager'; + return forDefinition + ? name + : leaf.dartCode(leaf.generatedElement(table, name)); } /// Code for a processed table manager typedef @@ -545,20 +551,28 @@ class _ManagerCodeTemplates { required TextEmitter leaf, required List<_Relation> relations, }) { - return """typedef ${processedTableManagerTypedefName(table)} = ${leaf.drift("ProcessedTableManager")}${_tableManagerTypeArguments(table, dbClassName, leaf, relations)};"""; + return """typedef ${processedTableManagerTypedefName(table, leaf, forDefinition: true)} = ${leaf.drift("ProcessedTableManager")}${_tableManagerTypeArguments(table, dbClassName, leaf, relations)};"""; } /// Name of the class which is used to represent a rows references /// /// If there are no relations, or if generation is modular, we will generate a base class instead. - String rowReferencesClassName( - {required DriftTable table, - required List<_Relation> relations, - required String dbClassName, - required TextEmitter leaf, - required bool withTypeArgs}) { - if (!_scope.generationOptions.isModular && relations.isNotEmpty) { - return '\$${table.entityInfoName}References'; + String rowReferencesClassName({ + required DriftTable table, + required List<_Relation> relations, + required String dbClassName, + required TextEmitter leaf, + required bool withTypeArgs, + bool forDefinition = false, + }) { + if (relations.isNotEmpty) { + final basename = '\$${table.entityInfoName}References'; + + if (forDefinition) { + return basename; + } else { + return leaf.dartCode(leaf.generatedElement(table, basename)); + } } else { if (withTypeArgs) { return "${leaf.drift('BaseReferences')}<${databaseType(leaf, dbClassName)},${tableClassWithPrefix(table, leaf)},${rowClassWithPrefix(table, leaf)}>"; @@ -590,11 +604,16 @@ class _ManagerCodeTemplates { relations: relations, dbClassName: dbClassName, leaf: leaf, - withTypeArgs: false); + withTypeArgs: false, + forDefinition: true); final body = relations.map( (relation) { final dbName = databaseType(leaf, dbClassName); + final referencedTable = leaf + .dartCode(leaf.referenceElement(relation.referencedTable, 'db')); + final currentTable = + leaf.dartCode(leaf.referenceElement(relation.currentTable, 'db')); if (relation.isReverse) { final aliasedTableMethod = """ @@ -603,19 +622,18 @@ class _ManagerCodeTemplates { List<${rowClassWithPrefix(relation.referencedTable, leaf)}> > _${relation.fieldName}Table($dbName db) => ${leaf.drift("MultiTypedResultKey")}.fromTable( - db.${relation.referencedTable.dbGetterName}, + $referencedTable, aliasName: ${leaf.drift("\$_aliasNameGenerator")}( - db.${relation.currentTable.dbGetterName}.${relation.currentColumn.nameInDart}, - db.${relation.referencedTable.dbGetterName}.${relation.referencedColumn.nameInDart}) + $currentTable.${relation.currentColumn.nameInDart}, + $referencedTable.${relation.referencedColumn.nameInDart}) );"""; return """ - $aliasedTableMethod - ${processedTableManagerTypedefName(relation.referencedTable)} get ${relation.fieldName} { + ${processedTableManagerTypedefName(relation.referencedTable, leaf)} get ${relation.fieldName} { final manager = ${rootTableManagerWithPrefix(relation.referencedTable, leaf)}( - \$_db, \$_db.${relation.referencedTable.dbGetterName} + \$_db, ${leaf.dartCode(leaf.referenceElement(relation.referencedTable, r'$_db'))} ).filter( (f) => f.${relation.referencedColumn.nameInDart}.${relation.currentColumn.nameInDart}( \$_item.${relation.currentColumn.nameInDart} @@ -623,9 +641,7 @@ class _ManagerCodeTemplates { ); final cache = \$_typedResult.readTableOrNull(_${relation.fieldName}Table(\$_db)); - return ProcessedTableManager(manager.\$state.copyWith(prefetchedData: cache)); - - + return ${leaf.drift("ProcessedTableManager")}(manager.\$state.copyWith(prefetchedData: cache)); } """; } else { @@ -633,21 +649,27 @@ class _ManagerCodeTemplates { tableClassWithPrefix(relation.referencedTable, leaf); final aliasedTableMethod = """ - static $referenceTableType _${relation.fieldName}Table($dbName db) => - db.${relation.referencedTable.dbGetterName}.createAlias(${leaf.drift("\$_aliasNameGenerator")}( - db.${relation.currentTable.dbGetterName}.${relation.currentColumn.nameInDart}, - db.${relation.referencedTable.dbGetterName}.${relation.referencedColumn.nameInDart})); + static $referenceTableType _${relation.fieldName}Table($dbName db) => + $referencedTable.createAlias(${leaf.drift("\$_aliasNameGenerator")}( + $currentTable.${relation.currentColumn.nameInDart}, + $referencedTable.${relation.referencedColumn.nameInDart})); """; + var currentColumnOnItem = + '\$_item.${relation.currentColumn.nameInDart}'; + if (relation.currentColumn.nullableInDart) { + currentColumnOnItem += '!'; + } + return """ $aliasedTableMethod - ${processedTableManagerTypedefName(relation.referencedTable)}${relation.currentColumn.nullable ? "?" : ""} get ${relation.fieldName} { + ${processedTableManagerTypedefName(relation.referencedTable, leaf)}${relation.currentColumn.nullable ? "?" : ""} get ${relation.fieldName} { ${relation.currentColumn.nullable ? "if (\$_item.${relation.currentColumn.nameInDart} == null) return null;" : ""} - final manager = ${rootTableManagerWithPrefix(relation.referencedTable, leaf)}(\$_db, \$_db.${relation.referencedTable.dbGetterName}).filter((f) => f.${relation.referencedColumn.nameInDart}(\$_item.${relation.currentColumn.nameInDart}!)); + final manager = ${rootTableManagerWithPrefix(relation.referencedTable, leaf)}(\$_db, ${leaf.dartCode(leaf.referenceElement(relation.referencedTable, r'$_db'))}).filter((f) => f.${relation.referencedColumn.nameInDart}($currentColumnOnItem)); final item = \$_typedResult.readTableOrNull(_${relation.fieldName}Table(\$_db)); if (item == null) return manager; - return ProcessedTableManager(manager.\$state.copyWith(prefetchedData: [item])); + return ${leaf.drift("ProcessedTableManager")}(manager.\$state.copyWith(prefetchedData: [item])); } """; } @@ -660,7 +682,7 @@ class _ManagerCodeTemplates { ${tableClassWithPrefix(table, leaf)}, ${rowClassWithPrefix(table, leaf)}> { $rowClassWithReferencesName(super.\$_db, super.\$_table, super.\$_typedResult); - + $body }"""; diff --git a/drift_dev/lib/src/writer/manager/table_manager_writer.dart b/drift_dev/lib/src/writer/manager/table_manager_writer.dart index 2b68ff57f..542dcb25d 100644 --- a/drift_dev/lib/src/writer/manager/table_manager_writer.dart +++ b/drift_dev/lib/src/writer/manager/table_manager_writer.dart @@ -87,7 +87,7 @@ class _TableManagerWriter { final fieldNameCount = allFieldNames .where((fieldName) => fieldName == relation.fieldName) .length; - if (fieldNameCount != 1) { + if (fieldNameCount != 1 && table.id.isDefinedInDart) { print( "Duplicate orderings/filters detected for field \"${relation.fieldName}\" on table \"${table.entityInfoName}\"." " Filter and orderings for this field wont be generated." @@ -170,7 +170,7 @@ class _TableManagerWriter { .add(_templates.relatedAnnotations(leaf: leaf, relation: relation)); } - if (!scope.generationOptions.isModular && relations.isNotEmpty) { + if (relations.isNotEmpty) { leaf.write(_templates.rowReferencesClass( table: table, relations: relations, diff --git a/examples/modular/lib/src/posts.drift.dart b/examples/modular/lib/src/posts.drift.dart index bf15130a2..3653d9754 100644 --- a/examples/modular/lib/src/posts.drift.dart +++ b/examples/modular/lib/src/posts.drift.dart @@ -16,6 +16,47 @@ typedef $PostsUpdateCompanionBuilder = i1.PostsCompanion Function({ i0.Value content, }); +final class $PostsReferences + extends i0.BaseReferences { + $PostsReferences(super.$_db, super.$_table, super.$_typedResult); + + static i2.Users _authorTable(i0.GeneratedDatabase db) => + i3.ReadDatabaseContainer(db).resultSet('users').createAlias( + i0.$_aliasNameGenerator( + i3.ReadDatabaseContainer(db).resultSet('posts').author, + i3.ReadDatabaseContainer(db).resultSet('users').id)); + + i2.$UsersProcessedTableManager get author { + final manager = i2 + .$UsersTableManager( + $_db, i3.ReadDatabaseContainer($_db).resultSet('users')) + .filter((f) => f.id($_item.author)); + final item = $_typedResult.readTableOrNull(_authorTable($_db)); + if (item == null) return manager; + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } + + static i0.MultiTypedResultKey> _likesRefsTable( + i0.GeneratedDatabase db) => + i0.MultiTypedResultKey.fromTable( + i3.ReadDatabaseContainer(db).resultSet('likes'), + aliasName: i0.$_aliasNameGenerator( + i3.ReadDatabaseContainer(db).resultSet('posts').id, + i3.ReadDatabaseContainer(db).resultSet('likes').post)); + + i1.$LikesProcessedTableManager get likesRefs { + final manager = i1 + .$LikesTableManager( + $_db, i3.ReadDatabaseContainer($_db).resultSet('likes')) + .filter((f) => f.post.id($_item.id)); + + final cache = $_typedResult.readTableOrNull(_likesRefsTable($_db)); + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } +} + class $PostsFilterComposer extends i0.Composer { $PostsFilterComposer({ required super.$db, @@ -184,7 +225,7 @@ class $PostsTableManager extends i0.RootTableManager< i1.$PostsAnnotationComposer, $PostsCreateCompanionBuilder, $PostsUpdateCompanionBuilder, - (i1.Post, i0.BaseReferences), + (i1.Post, i1.$PostsReferences), i1.Post, i0.PrefetchHooks Function({bool author, bool likesRefs})> { $PostsTableManager(i0.GeneratedDatabase db, i1.Posts table) @@ -218,7 +259,8 @@ class $PostsTableManager extends i0.RootTableManager< content: content, ), withReferenceMapper: (p0) => p0 - .map((e) => (e.readTable(table), i0.BaseReferences(db, table, e))) + .map((e) => + (e.readTable(table), i1.$PostsReferences(db, table, e))) .toList(), prefetchHooksCallback: null, )); @@ -233,7 +275,7 @@ typedef $PostsProcessedTableManager = i0.ProcessedTableManager< i1.$PostsAnnotationComposer, $PostsCreateCompanionBuilder, $PostsUpdateCompanionBuilder, - (i1.Post, i0.BaseReferences), + (i1.Post, i1.$PostsReferences), i1.Post, i0.PrefetchHooks Function({bool author, bool likesRefs})>; typedef $LikesCreateCompanionBuilder = i1.LikesCompanion Function({ @@ -247,6 +289,45 @@ typedef $LikesUpdateCompanionBuilder = i1.LikesCompanion Function({ i0.Value rowid, }); +final class $LikesReferences + extends i0.BaseReferences { + $LikesReferences(super.$_db, super.$_table, super.$_typedResult); + + static i1.Posts _postTable(i0.GeneratedDatabase db) => + i3.ReadDatabaseContainer(db).resultSet('posts').createAlias( + i0.$_aliasNameGenerator( + i3.ReadDatabaseContainer(db).resultSet('likes').post, + i3.ReadDatabaseContainer(db).resultSet('posts').id)); + + i1.$PostsProcessedTableManager get post { + final manager = i1 + .$PostsTableManager( + $_db, i3.ReadDatabaseContainer($_db).resultSet('posts')) + .filter((f) => f.id($_item.post)); + final item = $_typedResult.readTableOrNull(_postTable($_db)); + if (item == null) return manager; + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } + + static i2.Users _likedByTable(i0.GeneratedDatabase db) => + i3.ReadDatabaseContainer(db).resultSet('users').createAlias( + i0.$_aliasNameGenerator( + i3.ReadDatabaseContainer(db).resultSet('likes').likedBy, + i3.ReadDatabaseContainer(db).resultSet('users').id)); + + i2.$UsersProcessedTableManager get likedBy { + final manager = i2 + .$UsersTableManager( + $_db, i3.ReadDatabaseContainer($_db).resultSet('users')) + .filter((f) => f.id($_item.likedBy)); + final item = $_typedResult.readTableOrNull(_likedByTable($_db)); + if (item == null) return manager; + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } +} + class $LikesFilterComposer extends i0.Composer { $LikesFilterComposer({ required super.$db, @@ -417,7 +498,7 @@ class $LikesTableManager extends i0.RootTableManager< i1.$LikesAnnotationComposer, $LikesCreateCompanionBuilder, $LikesUpdateCompanionBuilder, - (i1.Like, i0.BaseReferences), + (i1.Like, i1.$LikesReferences), i1.Like, i0.PrefetchHooks Function({bool post, bool likedBy})> { $LikesTableManager(i0.GeneratedDatabase db, i1.Likes table) @@ -451,7 +532,8 @@ class $LikesTableManager extends i0.RootTableManager< rowid: rowid, ), withReferenceMapper: (p0) => p0 - .map((e) => (e.readTable(table), i0.BaseReferences(db, table, e))) + .map((e) => + (e.readTable(table), i1.$LikesReferences(db, table, e))) .toList(), prefetchHooksCallback: null, )); @@ -466,7 +548,7 @@ typedef $LikesProcessedTableManager = i0.ProcessedTableManager< i1.$LikesAnnotationComposer, $LikesCreateCompanionBuilder, $LikesUpdateCompanionBuilder, - (i1.Like, i0.BaseReferences), + (i1.Like, i1.$LikesReferences), i1.Like, i0.PrefetchHooks Function({bool post, bool likedBy})>; diff --git a/examples/modular/lib/src/users.drift.dart b/examples/modular/lib/src/users.drift.dart index 7851adb8b..e00907b76 100644 --- a/examples/modular/lib/src/users.drift.dart +++ b/examples/modular/lib/src/users.drift.dart @@ -21,6 +21,53 @@ typedef $UsersUpdateCompanionBuilder = i1.UsersCompanion Function({ i0.Value profilePicture, }); +final class $UsersReferences + extends i0.BaseReferences { + $UsersReferences(super.$_db, super.$_table, super.$_typedResult); + + static i0.MultiTypedResultKey> _followsRefsTable( + i0.GeneratedDatabase db) => + i0.MultiTypedResultKey.fromTable( + i4.ReadDatabaseContainer(db).resultSet('follows'), + aliasName: i0.$_aliasNameGenerator( + i4.ReadDatabaseContainer(db).resultSet('users').id, + i4.ReadDatabaseContainer(db) + .resultSet('follows') + .followed)); + + i1.$FollowsProcessedTableManager get followsRefs { + final manager = i1 + .$FollowsTableManager($_db, + i4.ReadDatabaseContainer($_db).resultSet('follows')) + .filter((f) => f.followed.id($_item.id)); + + final cache = $_typedResult.readTableOrNull(_followsRefsTable($_db)); + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } + + static i0.MultiTypedResultKey> _followsRefsTable( + i0.GeneratedDatabase db) => + i0.MultiTypedResultKey.fromTable( + i4.ReadDatabaseContainer(db).resultSet('follows'), + aliasName: i0.$_aliasNameGenerator( + i4.ReadDatabaseContainer(db).resultSet('users').id, + i4.ReadDatabaseContainer(db) + .resultSet('follows') + .follower)); + + i1.$FollowsProcessedTableManager get followsRefs { + final manager = i1 + .$FollowsTableManager($_db, + i4.ReadDatabaseContainer($_db).resultSet('follows')) + .filter((f) => f.follower.id($_item.id)); + + final cache = $_typedResult.readTableOrNull(_followsRefsTable($_db)); + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } +} + class $UsersFilterComposer extends i0.Composer { $UsersFilterComposer({ required super.$db, @@ -46,6 +93,52 @@ class $UsersFilterComposer extends i0.Composer { i0.ColumnFilters get profilePicture => $composableBuilder( column: $table.profilePicture, builder: (column) => i0.ColumnFilters(column)); + + i0.Expression followsRefs( + i0.Expression Function(i1.$FollowsFilterComposer f) f) { + final i1.$FollowsFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: + i4.ReadDatabaseContainer($db).resultSet('follows'), + getReferencedColumn: (t) => t.followed, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + i1.$FollowsFilterComposer( + $db: $db, + $table: i4.ReadDatabaseContainer($db) + .resultSet('follows'), + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + i0.Expression followsRefs( + i0.Expression Function(i1.$FollowsFilterComposer f) f) { + final i1.$FollowsFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: + i4.ReadDatabaseContainer($db).resultSet('follows'), + getReferencedColumn: (t) => t.follower, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + i1.$FollowsFilterComposer( + $db: $db, + $table: i4.ReadDatabaseContainer($db) + .resultSet('follows'), + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } } class $UsersOrderingComposer @@ -100,6 +193,52 @@ class $UsersAnnotationComposer i0.GeneratedColumn get profilePicture => $composableBuilder( column: $table.profilePicture, builder: (column) => column); + + i0.Expression followsRefs( + i0.Expression Function(i1.$FollowsAnnotationComposer a) f) { + final i1.$FollowsAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: + i4.ReadDatabaseContainer($db).resultSet('follows'), + getReferencedColumn: (t) => t.followed, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + i1.$FollowsAnnotationComposer( + $db: $db, + $table: i4.ReadDatabaseContainer($db) + .resultSet('follows'), + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + i0.Expression followsRefs( + i0.Expression Function(i1.$FollowsAnnotationComposer a) f) { + final i1.$FollowsAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: + i4.ReadDatabaseContainer($db).resultSet('follows'), + getReferencedColumn: (t) => t.follower, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + i1.$FollowsAnnotationComposer( + $db: $db, + $table: i4.ReadDatabaseContainer($db) + .resultSet('follows'), + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } } class $UsersTableManager extends i0.RootTableManager< @@ -111,9 +250,9 @@ class $UsersTableManager extends i0.RootTableManager< i1.$UsersAnnotationComposer, $UsersCreateCompanionBuilder, $UsersUpdateCompanionBuilder, - (i1.User, i0.BaseReferences), + (i1.User, i1.$UsersReferences), i1.User, - i0.PrefetchHooks Function()> { + i0.PrefetchHooks Function({bool followsRefs, bool followsRefs})> { $UsersTableManager(i0.GeneratedDatabase db, i1.Users table) : super(i0.TableManagerState( db: db, @@ -153,7 +292,8 @@ class $UsersTableManager extends i0.RootTableManager< profilePicture: profilePicture, ), withReferenceMapper: (p0) => p0 - .map((e) => (e.readTable(table), i0.BaseReferences(db, table, e))) + .map((e) => + (e.readTable(table), i1.$UsersReferences(db, table, e))) .toList(), prefetchHooksCallback: null, )); @@ -168,9 +308,9 @@ typedef $UsersProcessedTableManager = i0.ProcessedTableManager< i1.$UsersAnnotationComposer, $UsersCreateCompanionBuilder, $UsersUpdateCompanionBuilder, - (i1.User, i0.BaseReferences), + (i1.User, i1.$UsersReferences), i1.User, - i0.PrefetchHooks Function()>; + i0.PrefetchHooks Function({bool followsRefs, bool followsRefs})>; typedef $FollowsCreateCompanionBuilder = i1.FollowsCompanion Function({ required int followed, required int follower, @@ -182,6 +322,49 @@ typedef $FollowsUpdateCompanionBuilder = i1.FollowsCompanion Function({ i0.Value rowid, }); +final class $FollowsReferences + extends i0.BaseReferences { + $FollowsReferences(super.$_db, super.$_table, super.$_typedResult); + + static i1.Users _followedTable(i0.GeneratedDatabase db) => + i4.ReadDatabaseContainer(db).resultSet('users').createAlias( + i0.$_aliasNameGenerator( + i4.ReadDatabaseContainer(db) + .resultSet('follows') + .followed, + i4.ReadDatabaseContainer(db).resultSet('users').id)); + + i1.$UsersProcessedTableManager get followed { + final manager = i1 + .$UsersTableManager( + $_db, i4.ReadDatabaseContainer($_db).resultSet('users')) + .filter((f) => f.id($_item.followed)); + final item = $_typedResult.readTableOrNull(_followedTable($_db)); + if (item == null) return manager; + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } + + static i1.Users _followerTable(i0.GeneratedDatabase db) => + i4.ReadDatabaseContainer(db).resultSet('users').createAlias( + i0.$_aliasNameGenerator( + i4.ReadDatabaseContainer(db) + .resultSet('follows') + .follower, + i4.ReadDatabaseContainer(db).resultSet('users').id)); + + i1.$UsersProcessedTableManager get follower { + final manager = i1 + .$UsersTableManager( + $_db, i4.ReadDatabaseContainer($_db).resultSet('users')) + .filter((f) => f.id($_item.follower)); + final item = $_typedResult.readTableOrNull(_followerTable($_db)); + if (item == null) return manager; + return i0.ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } +} + class $FollowsFilterComposer extends i0.Composer { $FollowsFilterComposer({ @@ -353,7 +536,7 @@ class $FollowsTableManager extends i0.RootTableManager< i1.$FollowsAnnotationComposer, $FollowsCreateCompanionBuilder, $FollowsUpdateCompanionBuilder, - (i1.Follow, i0.BaseReferences), + (i1.Follow, i1.$FollowsReferences), i1.Follow, i0.PrefetchHooks Function({bool followed, bool follower})> { $FollowsTableManager(i0.GeneratedDatabase db, i1.Follows table) @@ -387,7 +570,8 @@ class $FollowsTableManager extends i0.RootTableManager< rowid: rowid, ), withReferenceMapper: (p0) => p0 - .map((e) => (e.readTable(table), i0.BaseReferences(db, table, e))) + .map((e) => + (e.readTable(table), i1.$FollowsReferences(db, table, e))) .toList(), prefetchHooksCallback: null, )); @@ -402,7 +586,7 @@ typedef $FollowsProcessedTableManager = i0.ProcessedTableManager< i1.$FollowsAnnotationComposer, $FollowsCreateCompanionBuilder, $FollowsUpdateCompanionBuilder, - (i1.Follow, i0.BaseReferences), + (i1.Follow, i1.$FollowsReferences), i1.Follow, i0.PrefetchHooks Function({bool followed, bool follower})>;