Skip to main content

CreateDiffTriggerOptions

Experimental Alpha

Options for TriggerManager#createDiffTrigger.

Extends

Properties

PropertyTypeDescriptionInherited from
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.BaseCreateDiffTriggerOptions.columns
destinationstringAlpha Destination table to send changes to. This table is created internally as a SQLite temporary table. This table will be dropped once the trigger is removed.-
hooks?TriggerCreationHooksAlpha Hooks which allow execution during the trigger creation process.BaseCreateDiffTriggerOptions.hooks
setupContext?LockContextAlpha Context to use for the setup operation. This is useful for when the setup operation needs to be executed in a specific context.-
sourcestringAlpha PowerSync source table/view to trigger and track changes from. This should be present in the PowerSync database's schema.BaseCreateDiffTriggerOptions.source
useStorage?booleanAlpha Use storage-backed (non-TEMP) tables and triggers that persist across sessions. These resources are still automatically disposed when no longer claimed.BaseCreateDiffTriggerOptions.useStorage
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' }BaseCreateDiffTriggerOptions.when