File tree Expand file tree Collapse file tree 3 files changed +5
-11
lines changed
common/src/client/triggers Expand file tree Collapse file tree 3 files changed +5
-11
lines changed Original file line number Diff line number Diff line change @@ -314,10 +314,10 @@ export interface TriggerManager {
314314 * const dispose = database.triggers.trackTableDiff({
315315 * source: 'todos',
316316 * columns: ['list_id'],
317+ * operations: [DiffTriggerOperation.INSERT],
317318 * when: {
318- * [DiffTriggerOperation.INSERT]: whenClause`json_extract(NEW.data, '$.list_id') = '123' `
319+ * [DiffTriggerOperation.INSERT]: whenClause`json_extract(NEW.data, '$.list_id') = ${sanitizeUUID(someIdVariable)} `
319320 * },
320- * operations: [DiffTriggerOperation.INSERT],
321321 * onChange: async (context) => {
322322 * // Fetches the todo records that were inserted during this diff
323323 * const newTodos = await context.getAll<Database['todos']>(`
Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ export function sanitizeUUID(uuid: string): string {
2121 *
2222 * **String placeholders:**
2323 * - All string values passed as placeholders are automatically wrapped in single quotes (`'`).
24- * - Any single quotes within the string value are escaped by doubling them (`''`), as required by SQL syntax.
2524 * - Do not manually wrap placeholders in single quotes in your template string; the function will handle quoting and escaping for you.
25+ * - Any single quotes within the string value are escaped by doubling them (`''`), as required by SQL syntax.
2626 *
2727 * **Other types:**
2828 * - `null` and `undefined` are converted to SQL `NULL`.
Original file line number Diff line number Diff line change @@ -31,19 +31,13 @@ describe('Triggers', () => {
3131 // This callback async processed. Invocations are sequential.
3232 onChange : async ( ) => {
3333 await database . writeLock ( async ( tx ) => {
34- // TODO
35- // API exposes a context to run things here.
36- // using execute seems to be important on Node.js
37- // the temp table is not present if using getAll
38- const changes = await tx . execute ( /* sql */ `
34+ const changes = await tx . getAll < TriggerDiffRecord > ( /* sql */ `
3935 SELECT
4036 *
4137 FROM
4238 ${ tempTable }
4339 ` ) ;
44-
45- results . push ( ...( changes . rows ?. _array || [ ] ) ) ;
46-
40+ results . push ( ...changes ) ;
4741 // Clear the temp table after processing
4842 await tx . execute ( /* sql */ ` DELETE FROM ${ tempTable } ; ` ) ;
4943 } ) ;
You can’t perform that action at this time.
0 commit comments