Skip to main content

TrackDiffOptions

Experimental Alpha

Options for tracking changes to a table with TriggerManager#trackTableDiff.

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
hooks?TriggerCreationHooksAlpha Hooks which allow execution during the trigger creation process.BaseCreateDiffTriggerOptions.hooks
onChange(context) => Promise<void>Alpha Handler for processing diff operations. Automatically invoked once diff items are present. Diff items are automatically cleared after the handler is invoked.-
sourcestringAlpha PowerSync source table/view to trigger and track changes from. This should be present in the PowerSync database's schema.BaseCreateDiffTriggerOptions.source
throttleMs?numberAlpha The minimum interval, in milliseconds, between TrackDiffOptions.onChange invocations.-
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