@@ -85,19 +85,8 @@ export interface TriggerDiffHandlerContext {
8585 /**
8686 * Allows querying the database with access to the table containing diff records.
8787 * The diff table is accessible via the `diff` accessor.
88- * The `DIFF` table is of the form:
8988 *
90- * ```sql
91- * CREATE TEMP TABLE ${destination} (
92- * id TEXT,
93- * operation TEXT,
94- * change TEXT,
95- * timestamp TEXT
96- * );
97- * ```
98- * The `change` column contains the JSON representation of the change. This column is NULL for
99- * {@link DiffTriggerOperation#DELETE} operations.
100- * For {@link DiffTriggerOperation#UPDATE} operations the `change` column is a JSON object containing both the `new` and `old` values:
89+ * The `DIFF` table is of the form described in {@link TriggerManager#createDiffTrigger}
10190 *
10291 * @example
10392 * ```sql
@@ -112,11 +101,30 @@ export interface TriggerDiffHandlerContext {
112101}
113102
114103export interface TrackDiffOptions {
104+ /**
105+ * A source SQLite table to track changes for.
106+ */
115107 source : string ;
108+ /**
109+ * SQLite Trigger WHEN condition to filter when the trigger should fire.
110+ */
116111 filter ?: string ;
112+ /**
113+ * Table columns to track changes for.
114+ */
117115 columns ?: string [ ] ;
116+ /**
117+ * SQLite operations to track changes for.
118+ */
118119 operations : DiffTriggerOperation [ ] ;
120+ /**
121+ * Handler for processing diff operations.
122+ * Automatically invoked once diff items are present.
123+ */
119124 onChange : ( context : TriggerDiffHandlerContext ) => Promise < void > ;
125+ /**
126+ * Hooks into the trigger creation process.
127+ */
120128 hooks ?: TriggerCreationHooks ;
121129}
122130
@@ -125,6 +133,19 @@ export interface TriggerManager {
125133 * Creates a temporary trigger which tracks changes to a source table
126134 * and writes changes to a destination table.
127135 * The temporary destination table is created internally and will be dropped when the trigger is removed.
136+ * The temporary destination table is created with the structure:
137+ * ```sql
138+ * CREATE TEMP TABLE ${destination} (
139+ * id TEXT,
140+ * operation TEXT,
141+ * change TEXT,
142+ * timestamp TEXT
143+ * );
144+ * ```
145+ * The `change` column contains the JSON representation of the change. This column is NULL for
146+ * {@link DiffTriggerOperation#DELETE} operations.
147+ * For {@link DiffTriggerOperation#UPDATE} operations the `change` column is a JSON object containing both the `new` and `old` values.
148+ *
128149 * @returns A callback to remove the trigger and drop the destination table.
129150 */
130151 createDiffTrigger ( options : CreateDiffTriggerOptions ) : Promise < TriggerRemoveCallback > ;
@@ -139,9 +160,9 @@ export interface TriggerManager {
139160 * database.triggers.trackTableDiff({
140161 * source: 'ps_data__todos',
141162 * columns: ['list_id'],
163+ * filter: "json_extract(NEW.data, '$.list_id') = '123'",
142164 * operations: [DiffTriggerOperation.INSERT],
143165 * onChange: async (context) => {
144- * console.log('Change detected, fetching new todos');
145166 * // Fetches the todo records that were inserted during this diff
146167 * const newTodos = await context.getAll<Database['todos']>("
147168 * SELECT
@@ -166,7 +187,7 @@ export interface TriggerManager {
166187 * WHERE
167188 * list_id = ?
168189 * ",
169- * [firstList.id ]
190+ * ['123' ]
170191 * );
171192 *
172193 * // Example code could process the current todos if necessary
0 commit comments