TrackDiffOptions
Experimental Alpha
Options for tracking changes to a table with TriggerManager#trackTableDiff.
Extends
Properties
| Property | Type | Description | Inherited 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? | TriggerCreationHooks | Alpha 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. | - |
source | string | Alpha PowerSync source table/view to trigger and track changes from. This should be present in the PowerSync database's schema. | BaseCreateDiffTriggerOptions.source |
throttleMs? | number | Alpha The minimum interval, in milliseconds, between TrackDiffOptions.onChange invocations. | - |
useStorage? | boolean | Alpha Use storage-backed (non-TEMP) tables and triggers that persist across sessions. These resources are still automatically disposed when no longer claimed. | BaseCreateDiffTriggerOptions.useStorage |
when | Partial<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 |