@@ -10,7 +10,48 @@ abstract class TimestampedCrdt extends BaseCrdt {
10
10
@override
11
11
Future <void > _insert (InsertStatement statement, List <Object ?>? args,
12
12
[Hlc ? hlc]) async {
13
+ // Force explicit column description in insert statements
14
+ assert (statement.targetColumns.isNotEmpty,
15
+ 'Unsupported statement: target columns must be explicitly stated.\n ${statement .toSql ()}' );
16
+ // Disallow star select statements
17
+ assert (
18
+ statement.source is ! SelectInsertSource ||
19
+ ((statement.source as SelectInsertSource ).stmt as SelectStatement )
20
+ .columns
21
+ .whereType <StarResultColumn >()
22
+ .isEmpty,
23
+ 'Unsupported statement: select columns must be explicitly stated.\n ${statement .toSql ()}' );
24
+
13
25
final argCount = args? .length ?? 0 ;
26
+ final source = switch (statement.source) {
27
+ ValuesSource s => ValuesSource ([
28
+ Tuple (expressions: [
29
+ ...s.values.first.expressions,
30
+ NumberedVariable (argCount + 1 ),
31
+ NumberedVariable (argCount + 2 ),
32
+ NumberedVariable (argCount + 3 ),
33
+ ])
34
+ ]),
35
+ SelectInsertSource s => SelectInsertSource (SelectStatement (
36
+ withClause: (s.stmt as SelectStatement ).withClause,
37
+ distinct: (s.stmt as SelectStatement ).distinct,
38
+ columns: [
39
+ ...(s.stmt as SelectStatement ).columns,
40
+ ExpressionResultColumn (expression: NumberedVariable (argCount + 1 )),
41
+ ExpressionResultColumn (expression: NumberedVariable (argCount + 2 )),
42
+ ExpressionResultColumn (expression: NumberedVariable (argCount + 3 )),
43
+ ],
44
+ from: (s.stmt as SelectStatement ).from,
45
+ where: (s.stmt as SelectStatement ).where,
46
+ groupBy: (s.stmt as SelectStatement ).groupBy,
47
+ windowDeclarations: (s.stmt as SelectStatement ).windowDeclarations,
48
+ orderBy: (s.stmt as SelectStatement ).orderBy,
49
+ limit: (s.stmt as SelectStatement ).limit,
50
+ )),
51
+ _ => throw UnimplementedError (
52
+ 'Unsupported data source: ${statement .source .runtimeType }, please file an issue in the sql_crdt project.' )
53
+ };
54
+
14
55
final newStatement = InsertStatement (
15
56
mode: statement.mode,
16
57
upsert: statement.upsert,
@@ -23,14 +64,7 @@ abstract class TimestampedCrdt extends BaseCrdt {
23
64
Reference (columnName: 'node_id' ),
24
65
Reference (columnName: 'modified' ),
25
66
],
26
- source: ValuesSource ([
27
- Tuple (expressions: [
28
- ...(statement.source as ValuesSource ).values.first.expressions,
29
- NumberedVariable (argCount + 1 ),
30
- NumberedVariable (argCount + 2 ),
31
- NumberedVariable (argCount + 3 ),
32
- ])
33
- ]),
67
+ source: source,
34
68
);
35
69
36
70
// Touch
0 commit comments