@@ -176,10 +176,10 @@ fn powersync_trigger_insert_sql_impl(
176
176
177
177
let json_fragment = json_object_fragment ( "NEW" , & mut table_info. column_names ( ) ) ?;
178
178
179
- let metadata_fragment = if table_info. flags . include_metadata ( ) {
180
- ", ' metadata', NEW._metadata"
179
+ let ( metadata_key , metadata_value ) = if table_info. flags . include_metadata ( ) {
180
+ ( ", metadata" , ", NEW._metadata")
181
181
} else {
182
- ""
182
+ ( "" , "" )
183
183
} ;
184
184
185
185
return if !local_only && !insert_only {
@@ -194,12 +194,9 @@ fn powersync_trigger_insert_sql_impl(
194
194
WHEN (typeof(NEW.id) != 'text')
195
195
THEN RAISE (FAIL, 'id should be text')
196
196
END;
197
- INSERT INTO {internal_name}
198
- SELECT NEW.id, {json_fragment};
199
- INSERT INTO powersync_crud_(data) VALUES(json_object('op', 'PUT', 'type', {:}, 'id', NEW.id, 'data', json(powersync_diff('{{}}', {:})){metadata_fragment}));
200
- INSERT OR IGNORE INTO ps_updated_rows(row_type, row_id) VALUES({type_string}, NEW.id);
201
- INSERT OR REPLACE INTO ps_buckets(name, last_op, target_op) VALUES('$local', 0, {MAX_OP_ID});
202
- END" , type_string, json_fragment) ;
197
+ INSERT INTO {internal_name} SELECT NEW.id, {json_fragment};
198
+ INSERT INTO powersync_crud(op,id,type,data{metadata_key}) VALUES ('PUT',NEW.id,{type_string},json(powersync_diff('{{}}', {:})){metadata_value});
199
+ END" , json_fragment) ;
203
200
Ok ( trigger)
204
201
} else if local_only {
205
202
let trigger = format ! (
@@ -213,6 +210,8 @@ fn powersync_trigger_insert_sql_impl(
213
210
) ;
214
211
Ok ( trigger)
215
212
} else if insert_only {
213
+ // This is using the manual powersync_crud_ instead of powersync_crud because insert-only
214
+ // writes shouldn't prevent us from receiving new data.
216
215
let trigger = format ! ( "\
217
216
CREATE TRIGGER {trigger_name}
218
217
INSTEAD OF INSERT ON {quoted_name}
0 commit comments