Skip to content

Commit c299225

Browse files
committed
simplify raw table triggers
1 parent 4977420 commit c299225

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

demos/supabase-todolist/lib/raw_tables_helper.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,13 @@ Future<void> _createUpdateListTrigger(SqliteWriteContext ctx) async {
105105
CREATE TRIGGER ${table}_update
106106
AFTER UPDATE ON $table
107107
FOR EACH ROW
108-
WHEN NOT powersync_in_sync_operation()
109108
BEGIN
110109
SELECT CASE
111110
WHEN (OLD.id != NEW.id)
112111
THEN RAISE (FAIL, 'Cannot update id')
113112
END;
114-
INSERT INTO powersync_crud_(data, options)
115-
VALUES(json_object('op', 'PATCH', 'type', '$table', 'id', NEW.id, 'data', json(powersync_diff($oldRowJsonObj, $newRowJsonObj))), 0);
116-
INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES('$table', NEW.id);
117-
INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('\$local', 0, 9223372036854775807);
113+
INSERT INTO powersync_crud (op, id, type, data)
114+
VALUES('PATCH', NEW.id, '$table', powersync_diff($oldRowJsonObj, $newRowJsonObj));
118115
END
119116
''');
120117
}
@@ -125,11 +122,8 @@ Future<void> _createDeleteListTrigger(SqliteWriteContext ctx) async {
125122
CREATE TRIGGER ${table}_delete
126123
AFTER DELETE ON $table
127124
FOR EACH ROW
128-
WHEN NOT powersync_in_sync_operation()
129125
BEGIN
130-
INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'DELETE', 'type', '$table', 'id', OLD.id));
131-
INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES('$table', OLD.id);
132-
INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('\$local', 0, 9223372036854775807);
126+
INSERT INTO powersync_crud (op, type, id) VALUES('DELETE', '$table', OLD.id);
133127
END
134128
''');
135129
}

0 commit comments

Comments
 (0)