Skip to content

Commit 340d60c

Browse files
cleanup docs and examples
1 parent 9297564 commit 340d60c

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

packages/common/src/client/triggers/TriggerManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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']>(`

packages/common/src/client/triggers/whenClause.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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`.

packages/node/tests/trigger.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)