Skip to main content

BaseCreateDiffTriggerOptions

Alpha Experimental

Common interface for options used in creating a diff trigger.

Extended by

Properties

PropertyTypeDescription
columns?string[]Alpha Columns to track and report changes for. Defaults to all columns in the source table. Use an empty array to track only the ID and operation.
hooks?TriggerCreationHooksAlpha Hooks which allow execution during the trigger creation process.
sourcestringAlpha PowerSync source table/view to trigger and track changes from. This should be present in the PowerSync database's schema.
useStorage?booleanAlpha Use storage-backed (non-TEMP) tables and triggers that persist across sessions. These resources are still automatically disposed when no longer claimed.
whenPartial<Record<DiffTriggerOperation, string>>Alpha Condition to filter when the triggers should fire. This corresponds to a SQLite WHEN clause in the trigger body. This is useful for only triggering on specific conditions. For example, you can use it to only trigger on certain values in the NEW row. Note that for PowerSync the row data is stored in a JSON column named data. The row id is available in the id column. NB! The WHEN clauses here are added directly to the SQLite trigger creation SQL. Any user input strings here should be sanitized externally. The BaseCreateDiffTriggerOptions.when string template function performs some basic sanitization, extra external sanitization is recommended. Example { 'INSERT': sanitizeSQLjson_extract(NEW.data, '$.list_id') = ${sanitizeUUID(list.id)}, 'INSERT': TRUE, 'UPDATE': sanitizeSQLNEW.id = 'abcd' AND json_extract(NEW.data, '$.status') = 'active', 'DELETE': sanitizeSQLjson_extract(OLD.data, '$.list_id') = 'abcd' }