Extra watch tables in select with join #1094
-
Hello! The use case is using the Dart query API but I need to specify some extra tables as "watchable" so that they work with stream queries. Those need to be specified explicitly because I use them in a custom expression as shown below. Does it make sense to include an extra argument to the moor API, or is there another way to do it? Here is the example: final extraExpr = CustomExpression<String>("""
(
SELECT something
FROM otherTable
)""");
final results = withCustomWatch(
select(table),
extraWatchTables: [otherTable],
joins: [
someJoins
],
)..addColumns([
extraExpr,
]); My wrapper implementation: import 'package:moor/moor.dart';
class ExtraWatchTableSelectable<FirstT extends Table, FirstD extends DataClass>
extends JoinedSelectStatement<FirstT, FirstD> {
final List<TableInfo> extraWatchTables;
ExtraWatchTableSelectable(
DatabaseConnectionUser database,
TableInfo<FirstT, FirstD> table,
List<Join<Table, DataClass>> joins,
this.extraWatchTables,
) : super(database, table, joins);
@override
Set<TableInfo> get watchedTables =>
super.watchedTables..addAll(extraWatchTables);
}
ExtraWatchTableSelectable<T, D>
withCustomWatch<T extends Table, D extends DataClass>(
SimpleSelectStatement<T, D> select, {
List<TableInfo> extraWatchTables,
List<Join<Table, DataClass>> joins = const [],
}) {
final statement = ExtraWatchTableSelectable(
// ignore:invalid_use_of_protected_member
select.database,
select.table,
joins,
extraWatchTables,
);
return statement;
}
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In moor 4.1, there's I think the best solution (for moor) is to add a method to report watched tables to the |
Beta Was this translation helpful? Give feedback.
In moor 4.1, there's
subqueryExpression
but I've just realized that doesn't properly add extra tables either 🤦I think the best solution (for moor) is to add a method to report watched tables to the
GenerationContext
. I've opened #1095 to track that. I think we could add a parameter toCustomExpression
to describe added tables then.