-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableUpdateConfig.ts
More file actions
76 lines (70 loc) · 1.93 KB
/
TableUpdateConfig.ts
File metadata and controls
76 lines (70 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type { UpdateHookOperation } from '@op-engineering/op-sqlite';
/**
* Row-level update event data from op-sqlite's updateHook
*
* Provides details about individual row changes (INSERT, UPDATE, DELETE)
* for fine-grained change tracking and notifications.
*
* The hook automatically queries for the row data using SQLite's internal rowid,
* so you receive the complete row object in the callback.
*
* @template T - The type of the row data
*/
export interface TableUpdateData<T = any> {
/**
* The table that was modified
*/
table: string;
/**
* The type of operation that occurred
*
* Possible values:
* - `'DELETE'` - Row was deleted
* - `'INSERT'` - Row was inserted
* - `'UPDATE'` - Row was updated
*/
operation: UpdateHookOperation;
/**
* SQLite's internal rowid (NOT your table's primary key)
*/
rowId: number;
/**
* The row data retrieved from the database
*
* The hook automatically queries the database to fetch the row data.
* For DELETE operations, this will be `null` since the row no longer exists.
*/
row: T | null;
}
/**
* Configuration for row-level table update listeners
*
* Used by `useOnTableUpdate` to subscribe to individual row changes
* on specific tables for notifications, cache invalidation, and analytics.
*
* @template T - The type of the row data
*/
export interface TableUpdateConfig<T = any> {
/**
* List of table names to monitor for changes
*/
tables: string[];
/**
* Callback function executed when a monitored table is updated
*
* Receives detailed information about the row-level change
* including the operation type (INSERT/UPDATE/DELETE) and row ID
*
* @param data - Row update event data
*
* @example
* ```typescript
* onUpdate: (data) => {
* if (data.operation === 18) {
* Toast.show(`New ${data.table} added!`);
* }
* }
* ```
*/
onUpdate: (data: TableUpdateData<T>) => void;
}