@powersync/common 0.0.0-dev-20260504100448 → 0.0.0-dev-20260630141119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attachments/AttachmentContext.d.ts +9 -8
- package/lib/attachments/AttachmentContext.js +8 -3
- package/lib/attachments/AttachmentContext.js.map +1 -1
- package/lib/attachments/AttachmentErrorHandler.d.ts +6 -6
- package/lib/attachments/AttachmentQueue.d.ts +85 -36
- package/lib/attachments/AttachmentQueue.js +19 -21
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentService.d.ts +3 -3
- package/lib/attachments/AttachmentService.js +4 -3
- package/lib/attachments/AttachmentService.js.map +1 -1
- package/lib/attachments/LocalStorageAdapter.d.ts +14 -8
- package/lib/attachments/LocalStorageAdapter.js +3 -0
- package/lib/attachments/LocalStorageAdapter.js.map +1 -1
- package/lib/attachments/RemoteStorageAdapter.d.ts +4 -4
- package/lib/attachments/Schema.d.ts +14 -6
- package/lib/attachments/Schema.js +8 -3
- package/lib/attachments/Schema.js.map +1 -1
- package/lib/attachments/SyncingService.d.ts +2 -2
- package/lib/attachments/SyncingService.js +8 -3
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/attachments/WatchedAttachmentItem.d.ts +3 -1
- package/lib/client/{AbstractPowerSyncDatabase.d.ts → CommonPowerSyncDatabase.d.ts} +112 -238
- package/lib/client/CommonPowerSyncDatabase.js +2 -0
- package/lib/client/CommonPowerSyncDatabase.js.map +1 -0
- package/lib/client/Query.d.ts +9 -0
- package/lib/client/SQLOpenFactory.d.ts +44 -10
- package/lib/client/SQLOpenFactory.js +1 -19
- package/lib/client/SQLOpenFactory.js.map +1 -1
- package/lib/client/compilableQueryWatch.d.ts +8 -2
- package/lib/client/compilableQueryWatch.js +4 -2
- package/lib/client/compilableQueryWatch.js.map +1 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +6 -3
- package/lib/client/connection/PowerSyncCredentials.d.ts +3 -0
- package/lib/client/runOnSchemaChange.d.ts +5 -2
- package/lib/client/runOnSchemaChange.js +3 -0
- package/lib/client/runOnSchemaChange.js.map +1 -1
- package/lib/client/sync/bucket/CrudBatch.d.ts +2 -0
- package/lib/client/sync/bucket/CrudBatch.js +2 -0
- package/lib/client/sync/bucket/CrudBatch.js.map +1 -1
- package/lib/client/sync/bucket/CrudEntry.d.ts +9 -31
- package/lib/client/sync/bucket/CrudEntry.js +2 -97
- package/lib/client/sync/bucket/CrudEntry.js.map +1 -1
- package/lib/client/sync/bucket/CrudTransaction.d.ts +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js +3 -0
- package/lib/client/sync/bucket/CrudTransaction.js.map +1 -1
- package/lib/client/sync/options.d.ts +65 -0
- package/lib/client/sync/options.js +25 -0
- package/lib/client/sync/options.js.map +1 -0
- package/lib/client/sync/stream/JsonValue.d.ts +3 -0
- package/lib/client/sync/sync-streams.d.ts +23 -8
- package/lib/client/triggers/TriggerManager.d.ts +28 -56
- package/lib/client/triggers/TriggerManager.js +2 -1
- package/lib/client/triggers/TriggerManager.js.map +1 -1
- package/lib/client/triggers/sanitizeSQL.d.ts +4 -0
- package/lib/client/triggers/sanitizeSQL.js +4 -0
- package/lib/client/triggers/sanitizeSQL.js.map +1 -1
- package/lib/client/watched/GetAllQuery.d.ts +7 -3
- package/lib/client/watched/GetAllQuery.js +3 -1
- package/lib/client/watched/GetAllQuery.js.map +1 -1
- package/lib/client/watched/WatchedQuery.d.ts +20 -6
- package/lib/client/watched/WatchedQuery.js +3 -5
- package/lib/client/watched/WatchedQuery.js.map +1 -1
- package/lib/client/watched/processors/DifferentialQueryProcessor.d.ts +15 -45
- package/lib/client/watched/processors/DifferentialQueryProcessor.js +1 -172
- package/lib/client/watched/processors/DifferentialQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/OnChangeQueryProcessor.d.ts +4 -22
- package/lib/client/watched/processors/OnChangeQueryProcessor.js +1 -82
- package/lib/client/watched/processors/OnChangeQueryProcessor.js.map +1 -1
- package/lib/client/watched/processors/comparators.d.ts +8 -0
- package/lib/client/watched/processors/comparators.js +4 -0
- package/lib/client/watched/processors/comparators.js.map +1 -1
- package/lib/db/DBAdapter.d.ts +90 -113
- package/lib/db/DBAdapter.js +70 -89
- package/lib/db/DBAdapter.js.map +1 -1
- package/lib/db/QueryResult.d.ts +104 -0
- package/lib/db/QueryResult.js +96 -0
- package/lib/db/QueryResult.js.map +1 -0
- package/lib/db/crud/SyncProgress.d.ts +7 -14
- package/lib/db/crud/SyncProgress.js +1 -60
- package/lib/db/crud/SyncProgress.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +54 -91
- package/lib/db/crud/SyncStatus.js +1 -245
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/db/crud/UploadQueueStatus.d.ts +3 -0
- package/lib/db/crud/UploadQueueStatus.js +3 -0
- package/lib/db/crud/UploadQueueStatus.js.map +1 -1
- package/lib/db/schema/Column.d.ts +22 -1
- package/lib/db/schema/Column.js +10 -4
- package/lib/db/schema/Column.js.map +1 -1
- package/lib/db/schema/Index.d.ts +8 -3
- package/lib/db/schema/Index.js +4 -1
- package/lib/db/schema/Index.js.map +1 -1
- package/lib/db/schema/IndexedColumn.d.ts +8 -3
- package/lib/db/schema/IndexedColumn.js +4 -1
- package/lib/db/schema/IndexedColumn.js.map +1 -1
- package/lib/db/schema/RawTable.d.ts +7 -1
- package/lib/db/schema/Schema.d.ts +10 -29
- package/lib/db/schema/Schema.js +3 -1
- package/lib/db/schema/Schema.js.map +1 -1
- package/lib/db/schema/Table.d.ts +69 -91
- package/lib/db/schema/Table.js +88 -87
- package/lib/db/schema/Table.js.map +1 -1
- package/lib/index.d.ts +6 -22
- package/lib/index.js +5 -22
- package/lib/index.js.map +1 -1
- package/lib/types/types.d.ts +6 -0
- package/lib/utils/BaseObserver.d.ts +12 -0
- package/lib/utils/BaseObserver.js +3 -0
- package/lib/utils/BaseObserver.js.map +1 -1
- package/lib/utils/Logger.d.ts +60 -22
- package/lib/utils/Logger.js +38 -30
- package/lib/utils/Logger.js.map +1 -1
- package/lib/utils/MetaBaseObserver.d.ts +11 -11
- package/lib/utils/MetaBaseObserver.js +1 -50
- package/lib/utils/MetaBaseObserver.js.map +1 -1
- package/lib/utils/mutex.d.ts +3 -45
- package/lib/utils/mutex.js +1 -153
- package/lib/utils/mutex.js.map +1 -1
- package/package.json +9 -46
- package/src/attachments/AttachmentContext.ts +15 -13
- package/src/attachments/AttachmentErrorHandler.ts +6 -6
- package/src/attachments/AttachmentQueue.ts +99 -42
- package/src/attachments/AttachmentService.ts +7 -6
- package/src/attachments/LocalStorageAdapter.ts +14 -8
- package/src/attachments/README.md +2 -0
- package/src/attachments/RemoteStorageAdapter.ts +4 -4
- package/src/attachments/Schema.ts +14 -6
- package/src/attachments/SyncingService.ts +10 -6
- package/src/attachments/WatchedAttachmentItem.ts +3 -1
- package/src/client/CommonPowerSyncDatabase.ts +540 -0
- package/src/client/Query.ts +9 -0
- package/src/client/SQLOpenFactory.ts +47 -19
- package/src/client/compilableQueryWatch.ts +9 -4
- package/src/client/connection/PowerSyncBackendConnector.ts +6 -3
- package/src/client/connection/PowerSyncCredentials.ts +3 -0
- package/src/client/runOnSchemaChange.ts +5 -2
- package/src/client/sync/bucket/CrudBatch.ts +2 -0
- package/src/client/sync/bucket/CrudEntry.ts +10 -101
- package/src/client/sync/bucket/CrudTransaction.ts +3 -0
- package/src/client/sync/options.ts +77 -0
- package/src/client/sync/stream/JsonValue.ts +3 -0
- package/src/client/sync/sync-streams.ts +23 -10
- package/src/client/triggers/TriggerManager.ts +29 -59
- package/src/client/triggers/sanitizeSQL.ts +5 -0
- package/src/client/watched/GetAllQuery.ts +8 -4
- package/src/client/watched/WatchedQuery.ts +20 -11
- package/src/client/watched/processors/DifferentialQueryProcessor.ts +19 -219
- package/src/client/watched/processors/OnChangeQueryProcessor.ts +4 -109
- package/src/client/watched/processors/comparators.ts +8 -0
- package/src/db/DBAdapter.ts +160 -175
- package/src/db/QueryResult.ts +195 -0
- package/src/db/crud/SyncProgress.ts +8 -43
- package/src/db/crud/SyncStatus.ts +66 -216
- package/src/db/crud/UploadQueueStatus.ts +3 -0
- package/src/db/schema/Column.ts +22 -5
- package/src/db/schema/Index.ts +9 -3
- package/src/db/schema/IndexedColumn.ts +9 -3
- package/src/db/schema/RawTable.ts +7 -1
- package/src/db/schema/Schema.ts +12 -7
- package/src/db/schema/Table.ts +130 -180
- package/src/index.ts +6 -22
- package/src/types/types.ts +6 -0
- package/src/utils/BaseObserver.ts +12 -0
- package/src/utils/Logger.ts +86 -31
- package/src/utils/MetaBaseObserver.ts +14 -60
- package/src/utils/mutex.ts +4 -189
- package/dist/bundle.cjs +0 -14136
- package/dist/bundle.cjs.map +0 -1
- package/dist/bundle.mjs +0 -14056
- package/dist/bundle.mjs.map +0 -1
- package/dist/bundle.node.cjs +0 -11613
- package/dist/bundle.node.cjs.map +0 -1
- package/dist/bundle.node.mjs +0 -11533
- package/dist/bundle.node.mjs.map +0 -1
- package/dist/index.d.cts +0 -4052
- package/legacy/sync_protocol.d.ts +0 -103
- package/lib/client/AbstractPowerSyncDatabase.js +0 -987
- package/lib/client/AbstractPowerSyncDatabase.js.map +0 -1
- package/lib/client/AbstractPowerSyncOpenFactory.d.ts +0 -22
- package/lib/client/AbstractPowerSyncOpenFactory.js +0 -25
- package/lib/client/AbstractPowerSyncOpenFactory.js.map +0 -1
- package/lib/client/ConnectionManager.d.ts +0 -112
- package/lib/client/ConnectionManager.js +0 -294
- package/lib/client/ConnectionManager.js.map +0 -1
- package/lib/client/CustomQuery.d.ts +0 -22
- package/lib/client/CustomQuery.js +0 -43
- package/lib/client/CustomQuery.js.map +0 -1
- package/lib/client/constants.d.ts +0 -1
- package/lib/client/constants.js +0 -2
- package/lib/client/constants.js.map +0 -1
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +0 -40
- package/lib/client/sync/bucket/BucketStorageAdapter.js +0 -19
- package/lib/client/sync/bucket/BucketStorageAdapter.js.map +0 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +0 -34
- package/lib/client/sync/bucket/SqliteBucketStorage.js +0 -162
- package/lib/client/sync/bucket/SqliteBucketStorage.js.map +0 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +0 -151
- package/lib/client/sync/stream/AbstractRemote.js +0 -473
- package/lib/client/sync/stream/AbstractRemote.js.map +0 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +0 -218
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +0 -663
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +0 -1
- package/lib/client/sync/stream/WebsocketClientTransport.d.ts +0 -15
- package/lib/client/sync/stream/WebsocketClientTransport.js +0 -61
- package/lib/client/sync/stream/WebsocketClientTransport.js.map +0 -1
- package/lib/client/sync/stream/core-instruction.d.ts +0 -71
- package/lib/client/sync/stream/core-instruction.js +0 -27
- package/lib/client/sync/stream/core-instruction.js.map +0 -1
- package/lib/client/triggers/MemoryTriggerClaimManager.d.ts +0 -6
- package/lib/client/triggers/MemoryTriggerClaimManager.js +0 -21
- package/lib/client/triggers/MemoryTriggerClaimManager.js.map +0 -1
- package/lib/client/triggers/TriggerManagerImpl.d.ts +0 -39
- package/lib/client/triggers/TriggerManagerImpl.js +0 -405
- package/lib/client/triggers/TriggerManagerImpl.js.map +0 -1
- package/lib/client/watched/processors/AbstractQueryProcessor.d.ts +0 -68
- package/lib/client/watched/processors/AbstractQueryProcessor.js +0 -151
- package/lib/client/watched/processors/AbstractQueryProcessor.js.map +0 -1
- package/lib/db/ConnectionClosedError.d.ts +0 -10
- package/lib/db/ConnectionClosedError.js +0 -21
- package/lib/db/ConnectionClosedError.js.map +0 -1
- package/lib/db/schema/TableV2.d.ts +0 -9
- package/lib/db/schema/TableV2.js +0 -9
- package/lib/db/schema/TableV2.js.map +0 -1
- package/lib/utils/AbortOperation.d.ts +0 -9
- package/lib/utils/AbortOperation.js +0 -19
- package/lib/utils/AbortOperation.js.map +0 -1
- package/lib/utils/ControlledExecutor.d.ts +0 -25
- package/lib/utils/ControlledExecutor.js +0 -51
- package/lib/utils/ControlledExecutor.js.map +0 -1
- package/lib/utils/async.d.ts +0 -14
- package/lib/utils/async.js +0 -46
- package/lib/utils/async.js.map +0 -1
- package/lib/utils/parseQuery.d.ts +0 -6
- package/lib/utils/parseQuery.js +0 -17
- package/lib/utils/parseQuery.js.map +0 -1
- package/lib/utils/queue.d.ts +0 -16
- package/lib/utils/queue.js +0 -42
- package/lib/utils/queue.js.map +0 -1
- package/lib/utils/stream_transform.d.ts +0 -39
- package/lib/utils/stream_transform.js +0 -206
- package/lib/utils/stream_transform.js.map +0 -1
- package/src/client/AbstractPowerSyncDatabase.ts +0 -1362
- package/src/client/AbstractPowerSyncOpenFactory.ts +0 -39
- package/src/client/ConnectionManager.ts +0 -402
- package/src/client/CustomQuery.ts +0 -56
- package/src/client/constants.ts +0 -1
- package/src/client/sync/bucket/BucketStorageAdapter.ts +0 -49
- package/src/client/sync/bucket/SqliteBucketStorage.ts +0 -199
- package/src/client/sync/stream/AbstractRemote.ts +0 -602
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +0 -905
- package/src/client/sync/stream/WebsocketClientTransport.ts +0 -80
- package/src/client/sync/stream/core-instruction.ts +0 -98
- package/src/client/triggers/MemoryTriggerClaimManager.ts +0 -25
- package/src/client/triggers/TriggerManagerImpl.ts +0 -496
- package/src/client/watched/processors/AbstractQueryProcessor.ts +0 -226
- package/src/db/ConnectionClosedError.ts +0 -23
- package/src/db/schema/TableV2.ts +0 -9
- package/src/utils/AbortOperation.ts +0 -17
- package/src/utils/ControlledExecutor.ts +0 -72
- package/src/utils/async.ts +0 -50
- package/src/utils/parseQuery.ts +0 -25
- package/src/utils/queue.ts +0 -48
- package/src/utils/stream_transform.ts +0 -252
|
@@ -1,173 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* An empty differential result set.
|
|
4
|
-
* This is used as the initial state for differential incrementally watched queries.
|
|
5
|
-
*/
|
|
6
|
-
export const EMPTY_DIFFERENTIAL = {
|
|
7
|
-
added: [],
|
|
8
|
-
all: [],
|
|
9
|
-
removed: [],
|
|
10
|
-
updated: [],
|
|
11
|
-
unchanged: []
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Default implementation of the {@link DifferentialWatchedQueryComparator} for watched queries.
|
|
15
|
-
* It keys items by their `id` property if available, alternatively it uses JSON stringification
|
|
16
|
-
* of the entire item for the key and comparison.
|
|
17
|
-
*/
|
|
18
|
-
export const DEFAULT_ROW_COMPARATOR = {
|
|
19
|
-
keyBy: (item) => {
|
|
20
|
-
if (item && typeof item == 'object' && typeof item['id'] == 'string') {
|
|
21
|
-
return item['id'];
|
|
22
|
-
}
|
|
23
|
-
return JSON.stringify(item);
|
|
24
|
-
},
|
|
25
|
-
compareBy: (item) => JSON.stringify(item)
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Uses the PowerSync onChange event to trigger watched queries.
|
|
29
|
-
* Results are emitted on every change of the relevant tables.
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
export class DifferentialQueryProcessor extends AbstractQueryProcessor {
|
|
33
|
-
options;
|
|
34
|
-
comparator;
|
|
35
|
-
constructor(options) {
|
|
36
|
-
super(options);
|
|
37
|
-
this.options = options;
|
|
38
|
-
this.comparator = options.rowComparator ?? DEFAULT_ROW_COMPARATOR;
|
|
39
|
-
}
|
|
40
|
-
/*
|
|
41
|
-
* @returns If the sets are equal
|
|
42
|
-
*/
|
|
43
|
-
differentiate(current, previousMap) {
|
|
44
|
-
const { keyBy, compareBy } = this.comparator;
|
|
45
|
-
let hasChanged = false;
|
|
46
|
-
const currentMap = new Map();
|
|
47
|
-
const removedTracker = new Set(previousMap.keys());
|
|
48
|
-
// Allow mutating to populate the data temporarily.
|
|
49
|
-
const diff = {
|
|
50
|
-
all: [],
|
|
51
|
-
added: [],
|
|
52
|
-
removed: [],
|
|
53
|
-
updated: [],
|
|
54
|
-
unchanged: []
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Looping over the current result set array is important to preserve
|
|
58
|
-
* the ordering of the result set.
|
|
59
|
-
* We can replace items in the current array with previous object references if they are equal.
|
|
60
|
-
*/
|
|
61
|
-
for (const item of current) {
|
|
62
|
-
const key = keyBy(item);
|
|
63
|
-
const hash = compareBy(item);
|
|
64
|
-
currentMap.set(key, { hash, item });
|
|
65
|
-
const previousItem = previousMap.get(key);
|
|
66
|
-
if (!previousItem) {
|
|
67
|
-
// New item
|
|
68
|
-
hasChanged = true;
|
|
69
|
-
diff.added.push(item);
|
|
70
|
-
diff.all.push(item);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
// Existing item
|
|
74
|
-
if (hash == previousItem.hash) {
|
|
75
|
-
diff.unchanged.push(previousItem.item);
|
|
76
|
-
// Use the previous object reference
|
|
77
|
-
diff.all.push(previousItem.item);
|
|
78
|
-
// update the map to preserve the reference
|
|
79
|
-
currentMap.set(key, previousItem);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
hasChanged = true;
|
|
83
|
-
diff.updated.push({ current: item, previous: previousItem.item });
|
|
84
|
-
// Use the new reference
|
|
85
|
-
diff.all.push(item);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// The item is present, we don't consider it removed
|
|
89
|
-
removedTracker.delete(key);
|
|
90
|
-
}
|
|
91
|
-
diff.removed = Array.from(removedTracker).map((key) => previousMap.get(key).item);
|
|
92
|
-
hasChanged = hasChanged || diff.removed.length > 0;
|
|
93
|
-
return {
|
|
94
|
-
diff,
|
|
95
|
-
hasChanged,
|
|
96
|
-
map: currentMap
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
async linkQuery(options) {
|
|
100
|
-
const { db, watchOptions } = this.options;
|
|
101
|
-
const { abortSignal } = options;
|
|
102
|
-
const compiledQuery = watchOptions.query.compile();
|
|
103
|
-
const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
|
|
104
|
-
tables: options.settings.triggerOnTables
|
|
105
|
-
});
|
|
106
|
-
let currentMap = new Map();
|
|
107
|
-
// populate the currentMap from the placeholder data
|
|
108
|
-
this.state.data.forEach((item) => {
|
|
109
|
-
currentMap.set(this.comparator.keyBy(item), {
|
|
110
|
-
hash: this.comparator.compareBy(item),
|
|
111
|
-
item
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
db.onChangeWithCallback({
|
|
115
|
-
onChange: async () => {
|
|
116
|
-
if (this.closed || abortSignal.aborted) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
// This fires for each change of the relevant tables
|
|
120
|
-
try {
|
|
121
|
-
if (this.reportFetching && !this.state.isFetching) {
|
|
122
|
-
await this.updateState({ isFetching: true });
|
|
123
|
-
}
|
|
124
|
-
const partialStateUpdate = {};
|
|
125
|
-
// Always run the query if an underlying table has changed
|
|
126
|
-
const result = await watchOptions.query.execute({
|
|
127
|
-
sql: compiledQuery.sql,
|
|
128
|
-
// Allows casting from ReadOnlyArray[unknown] to Array<unknown>
|
|
129
|
-
// This allows simpler compatibility with PowerSync queries
|
|
130
|
-
parameters: [...compiledQuery.parameters],
|
|
131
|
-
db: this.options.db
|
|
132
|
-
});
|
|
133
|
-
if (abortSignal.aborted) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (this.reportFetching) {
|
|
137
|
-
partialStateUpdate.isFetching = false;
|
|
138
|
-
}
|
|
139
|
-
if (this.state.isLoading) {
|
|
140
|
-
partialStateUpdate.isLoading = false;
|
|
141
|
-
}
|
|
142
|
-
const { diff, hasChanged, map } = this.differentiate(result, currentMap);
|
|
143
|
-
// Update for future comparisons
|
|
144
|
-
currentMap = map;
|
|
145
|
-
if (hasChanged) {
|
|
146
|
-
await this.iterateAsyncListenersWithError((l) => l.onDiff?.(diff));
|
|
147
|
-
Object.assign(partialStateUpdate, {
|
|
148
|
-
data: diff.all
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
if (this.state.error) {
|
|
152
|
-
partialStateUpdate.error = null;
|
|
153
|
-
}
|
|
154
|
-
if (Object.keys(partialStateUpdate).length > 0) {
|
|
155
|
-
await this.updateState(partialStateUpdate);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
await this.updateState({ error });
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
onError: async (error) => {
|
|
163
|
-
await this.updateState({ error });
|
|
164
|
-
}
|
|
165
|
-
}, {
|
|
166
|
-
signal: abortSignal,
|
|
167
|
-
tables,
|
|
168
|
-
throttleMs: watchOptions.throttleMs,
|
|
169
|
-
triggerImmediate: true // used to emit the initial state
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
}
|
|
1
|
+
export {};
|
|
173
2
|
//# sourceMappingURL=DifferentialQueryProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DifferentialQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/DifferentialQueryProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DifferentialQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/DifferentialQueryProcessor.ts"],"names":[],"mappings":""}
|
|
@@ -1,33 +1,15 @@
|
|
|
1
1
|
import { WatchCompatibleQuery, WatchedQuery, WatchedQueryOptions } from '../WatchedQuery.js';
|
|
2
|
-
import { AbstractQueryProcessor, AbstractQueryProcessorOptions, LinkQueryOptions } from './AbstractQueryProcessor.js';
|
|
3
|
-
import { WatchedQueryComparator } from './comparators.js';
|
|
4
2
|
/**
|
|
5
3
|
* Settings for {@link WatchedQuery} instances created via {@link Query#watch}.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
6
|
*/
|
|
7
7
|
export interface WatchedQuerySettings<DataType> extends WatchedQueryOptions {
|
|
8
8
|
query: WatchCompatibleQuery<DataType>;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* {@link WatchedQuery} returned from {@link Query#watch}.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
12
14
|
*/
|
|
13
15
|
export type StandardWatchedQuery<DataType> = WatchedQuery<DataType, WatchedQuerySettings<DataType>>;
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export interface OnChangeQueryProcessorOptions<Data> extends AbstractQueryProcessorOptions<Data, WatchedQuerySettings<Data>> {
|
|
18
|
-
comparator?: WatchedQueryComparator<Data>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Uses the PowerSync onChange event to trigger watched queries.
|
|
22
|
-
* Results are emitted on every change of the relevant tables.
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export declare class OnChangeQueryProcessor<Data> extends AbstractQueryProcessor<Data, WatchedQuerySettings<Data>> {
|
|
26
|
-
protected options: OnChangeQueryProcessorOptions<Data>;
|
|
27
|
-
constructor(options: OnChangeQueryProcessorOptions<Data>);
|
|
28
|
-
/**
|
|
29
|
-
* @returns If the sets are equal
|
|
30
|
-
*/
|
|
31
|
-
protected checkEquality(current: Data, previous: Data): boolean;
|
|
32
|
-
protected linkQuery(options: LinkQueryOptions<Data>): Promise<void>;
|
|
33
|
-
}
|
|
@@ -1,83 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Uses the PowerSync onChange event to trigger watched queries.
|
|
4
|
-
* Results are emitted on every change of the relevant tables.
|
|
5
|
-
* @internal
|
|
6
|
-
*/
|
|
7
|
-
export class OnChangeQueryProcessor extends AbstractQueryProcessor {
|
|
8
|
-
options;
|
|
9
|
-
constructor(options) {
|
|
10
|
-
super(options);
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @returns If the sets are equal
|
|
15
|
-
*/
|
|
16
|
-
checkEquality(current, previous) {
|
|
17
|
-
// Use the provided comparator if available. Assume values are unique if not available.
|
|
18
|
-
return this.options.comparator?.checkEquality?.(current, previous) ?? false;
|
|
19
|
-
}
|
|
20
|
-
async linkQuery(options) {
|
|
21
|
-
const { db, watchOptions } = this.options;
|
|
22
|
-
const { abortSignal } = options;
|
|
23
|
-
const compiledQuery = watchOptions.query.compile();
|
|
24
|
-
const tables = await db.resolveTables(compiledQuery.sql, compiledQuery.parameters, {
|
|
25
|
-
tables: options.settings.triggerOnTables
|
|
26
|
-
});
|
|
27
|
-
db.onChangeWithCallback({
|
|
28
|
-
onChange: async () => {
|
|
29
|
-
if (this.closed || abortSignal.aborted) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
// This fires for each change of the relevant tables
|
|
33
|
-
try {
|
|
34
|
-
if (this.reportFetching && !this.state.isFetching) {
|
|
35
|
-
await this.updateState({ isFetching: true });
|
|
36
|
-
}
|
|
37
|
-
const partialStateUpdate = {};
|
|
38
|
-
// Always run the query if an underlying table has changed
|
|
39
|
-
const result = await watchOptions.query.execute({
|
|
40
|
-
sql: compiledQuery.sql,
|
|
41
|
-
// Allows casting from ReadOnlyArray[unknown] to Array<unknown>
|
|
42
|
-
// This allows simpler compatibility with PowerSync queries
|
|
43
|
-
parameters: [...compiledQuery.parameters],
|
|
44
|
-
db: this.options.db
|
|
45
|
-
});
|
|
46
|
-
if (abortSignal.aborted) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (this.reportFetching) {
|
|
50
|
-
partialStateUpdate.isFetching = false;
|
|
51
|
-
}
|
|
52
|
-
if (this.state.isLoading) {
|
|
53
|
-
partialStateUpdate.isLoading = false;
|
|
54
|
-
}
|
|
55
|
-
// Check if the result has changed
|
|
56
|
-
if (!this.checkEquality(result, this.state.data)) {
|
|
57
|
-
Object.assign(partialStateUpdate, {
|
|
58
|
-
data: result
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (this.state.error) {
|
|
62
|
-
partialStateUpdate.error = null;
|
|
63
|
-
}
|
|
64
|
-
if (Object.keys(partialStateUpdate).length > 0) {
|
|
65
|
-
await this.updateState(partialStateUpdate);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
await this.updateState({ error });
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
onError: async (error) => {
|
|
73
|
-
await this.updateState({ error });
|
|
74
|
-
}
|
|
75
|
-
}, {
|
|
76
|
-
signal: abortSignal,
|
|
77
|
-
tables,
|
|
78
|
-
throttleMs: watchOptions.throttleMs,
|
|
79
|
-
triggerImmediate: true // used to emit the initial state
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
1
|
+
export {};
|
|
83
2
|
//# sourceMappingURL=OnChangeQueryProcessor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/OnChangeQueryProcessor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OnChangeQueryProcessor.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/OnChangeQueryProcessor.ts"],"names":[],"mappings":""}
|
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
* A basic comparator for incrementally watched queries. This performs a single comparison which
|
|
3
3
|
* determines if the result set has changed. The {@link WatchedQuery} will only emit the new result
|
|
4
4
|
* if a change has been detected.
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
5
7
|
*/
|
|
6
8
|
export interface WatchedQueryComparator<Data> {
|
|
7
9
|
checkEquality: (current: Data, previous: Data) => boolean;
|
|
8
10
|
}
|
|
9
11
|
/**
|
|
10
12
|
* Options for {@link ArrayComparator}
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
11
15
|
*/
|
|
12
16
|
export type ArrayComparatorOptions<ItemType> = {
|
|
13
17
|
/**
|
|
@@ -18,6 +22,8 @@ export type ArrayComparatorOptions<ItemType> = {
|
|
|
18
22
|
/**
|
|
19
23
|
* An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
|
|
20
24
|
* result has changes without necessarily processing all items in the result.
|
|
25
|
+
*
|
|
26
|
+
* @public
|
|
21
27
|
*/
|
|
22
28
|
export declare class ArrayComparator<ItemType> implements WatchedQueryComparator<ItemType[]> {
|
|
23
29
|
protected options: ArrayComparatorOptions<ItemType>;
|
|
@@ -26,5 +32,7 @@ export declare class ArrayComparator<ItemType> implements WatchedQueryComparator
|
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
28
34
|
* Watched query comparator that always reports changed result sets.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
29
37
|
*/
|
|
30
38
|
export declare const FalsyComparator: WatchedQueryComparator<unknown>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* An efficient comparator for {@link WatchedQuery} created with {@link Query#watch}. This has the ability to determine if a query
|
|
3
3
|
* result has changes without necessarily processing all items in the result.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
4
6
|
*/
|
|
5
7
|
export class ArrayComparator {
|
|
6
8
|
options;
|
|
@@ -28,6 +30,8 @@ export class ArrayComparator {
|
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Watched query comparator that always reports changed result sets.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
31
35
|
*/
|
|
32
36
|
export const FalsyComparator = {
|
|
33
37
|
checkEquality: () => false // Default comparator that always returns false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/comparators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"comparators.js","sourceRoot":"","sources":["../../../../src/client/watched/processors/comparators.ts"],"names":[],"mappings":"AAuBA;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IACJ;IAAtB,YAAsB,OAAyC;QAAzC,YAAO,GAAP,OAAO,CAAkC;IAAG,CAAC;IAEnE,aAAa,CAAC,OAAmB,EAAE,QAAoB;QACrD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEnC,sCAAsC;QACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;YAE5C,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;gBACjC,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAoC;IAC9D,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,+CAA+C;CAC3E,CAAC"}
|
package/lib/db/DBAdapter.d.ts
CHANGED
|
@@ -2,110 +2,104 @@
|
|
|
2
2
|
* Set of generic interfaces to allow PowerSync compatibility with
|
|
3
3
|
* different SQLite DB implementations.
|
|
4
4
|
*/
|
|
5
|
-
import { BaseListener,
|
|
5
|
+
import { BaseListener, BaseObserver } from '../utils/BaseObserver.js';
|
|
6
|
+
import { QueryResult, RawQueryResult, SqliteRecord } from './QueryResult.js';
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
-
* which is used by the DB adapter libraries as well.
|
|
8
|
+
* @public
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
* Object returned by SQL Query executions.
|
|
12
|
-
*/
|
|
13
|
-
export type QueryResult = {
|
|
14
|
-
/** Represents the auto-generated row id if applicable. */
|
|
15
|
-
insertId?: number;
|
|
10
|
+
export interface DBGetUtils {
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
12
|
+
* Execute a read-only query and return results.
|
|
18
13
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
14
|
+
* @param sql - The SQL query to execute
|
|
15
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
16
|
+
* @returns An array of results
|
|
22
17
|
*/
|
|
23
|
-
rowsAffected: number;
|
|
24
|
-
/** if status is undefined or 0 this object will contain the query results */
|
|
25
|
-
rows?: {
|
|
26
|
-
/** Raw array with all dataset */
|
|
27
|
-
_array: any[];
|
|
28
|
-
/** The length of the dataset */
|
|
29
|
-
length: number;
|
|
30
|
-
/** A convenience function to acess the index based the row object
|
|
31
|
-
* @param idx the row index
|
|
32
|
-
* @returns the row structure identified by column names
|
|
33
|
-
*/
|
|
34
|
-
item: (idx: number) => any;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export interface DBGetUtils {
|
|
38
|
-
/** Execute a read-only query and return results. */
|
|
39
18
|
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
40
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Execute a read-only query and return the first result, or null if the ResultSet is empty.
|
|
21
|
+
*
|
|
22
|
+
* @param sql - The SQL query to execute
|
|
23
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
24
|
+
* @returns The first result if found, or null if no results are returned
|
|
25
|
+
*/
|
|
41
26
|
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
42
|
-
/**
|
|
27
|
+
/**
|
|
28
|
+
* Execute a read-only query and return the first result, error if the ResultSet is empty.
|
|
29
|
+
*
|
|
30
|
+
* @param sql - The SQL query to execute
|
|
31
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
32
|
+
* @returns The first result matching the query
|
|
33
|
+
* @throws Error if no rows are returned
|
|
34
|
+
*/
|
|
43
35
|
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
44
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
45
40
|
export interface SqlExecutor {
|
|
46
|
-
/** Execute a single write statement. */
|
|
47
|
-
execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
|
|
48
41
|
/**
|
|
49
|
-
* Execute a
|
|
50
|
-
*
|
|
51
|
-
* `executeRaw` returns a nested array of raw values, where each row is
|
|
52
|
-
* represented as an array of column values without field names.
|
|
42
|
+
* Execute a SQL write (INSERT/UPDATE/DELETE) query
|
|
43
|
+
* and optionally return results.
|
|
53
44
|
*
|
|
54
|
-
*
|
|
45
|
+
* When using the default client-side [JSON-based view system](https://docs.powersync.com/architecture/client-architecture#client-side-schema-and-sqlite-database-structure),
|
|
46
|
+
* the returned result's `rowsAffected` may be `0` for successful `UPDATE` and `DELETE` statements.
|
|
47
|
+
* Use a `RETURNING` clause and inspect `result.rows` when you need to confirm which rows changed.
|
|
55
48
|
*
|
|
56
|
-
*
|
|
49
|
+
* @param sql - The SQL query to execute
|
|
50
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
51
|
+
* @returns The query result as an object with structured key-value pairs
|
|
52
|
+
*/
|
|
53
|
+
execute: <T = SqliteRecord>(query: string, params?: any[] | undefined) => Promise<QueryResult<T>>;
|
|
54
|
+
/**
|
|
55
|
+
* Execute a SQL write (INSERT/UPDATE/DELETE) query directly on the database without any PowerSync processing.
|
|
56
|
+
* This bypasses certain PowerSync abstractions and is useful for accessing the raw database results.
|
|
57
57
|
*
|
|
58
|
-
*
|
|
58
|
+
* @param sql - The SQL query to execute
|
|
59
|
+
* @param parameters - Optional array of parameters to bind to the query
|
|
60
|
+
* @returns The {@link RawQueryResult} representing each row as an array.
|
|
61
|
+
*/
|
|
62
|
+
executeRaw: (query: string, params?: any[] | undefined) => Promise<RawQueryResult>;
|
|
63
|
+
/**
|
|
64
|
+
* Execute a write query (INSERT/UPDATE/DELETE) multiple times with each parameter set
|
|
65
|
+
* and optionally return results.
|
|
66
|
+
* This is faster than executing separately with each parameter set.
|
|
59
67
|
*
|
|
60
|
-
*
|
|
68
|
+
* @param sql - The SQL query to execute
|
|
69
|
+
* @param parameters - Optional 2D array of parameter sets, where each inner array is a set of parameters for one execution
|
|
70
|
+
* @returns The query result
|
|
61
71
|
*/
|
|
62
|
-
|
|
63
|
-
executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
|
|
72
|
+
executeBatch: (query: string, params?: any[][]) => Promise<QueryResult<never>>;
|
|
64
73
|
}
|
|
65
|
-
|
|
74
|
+
/**
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
export declare abstract class LockContext implements SqlExecutor, DBGetUtils {
|
|
78
|
+
abstract executeRaw<T>(query: string, params?: any[] | undefined): Promise<RawQueryResult>;
|
|
79
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
80
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
81
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
82
|
+
execute<T = SqliteRecord>(query: string, params?: any[] | undefined): Promise<QueryResult<T>>;
|
|
83
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult<never>>;
|
|
66
84
|
}
|
|
67
85
|
/**
|
|
68
|
-
*
|
|
86
|
+
* @public
|
|
69
87
|
*/
|
|
70
|
-
export declare function DBGetUtilsDefaultMixin<TBase extends new (...args: any[]) => Omit<SqlExecutor, 'executeBatch'>>(Base: TBase): {
|
|
71
|
-
new (...args: any[]): {
|
|
72
|
-
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
73
|
-
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
74
|
-
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
75
|
-
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
76
|
-
execute: (query: string, params?: any[] | undefined) => Promise<QueryResult>;
|
|
77
|
-
executeRaw: (query: string, params?: any[] | undefined) => Promise<any[][]>;
|
|
78
|
-
};
|
|
79
|
-
} & TBase;
|
|
80
88
|
export interface Transaction extends LockContext {
|
|
81
89
|
/** Commit multiple changes to the local DB using the Transaction context. */
|
|
82
|
-
commit: () => Promise<
|
|
90
|
+
commit: () => Promise<void>;
|
|
83
91
|
/** Roll back multiple attempted changes using the Transaction context. */
|
|
84
|
-
rollback: () => Promise<
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Update table operation numbers from SQLite
|
|
88
|
-
*/
|
|
89
|
-
export declare enum RowUpdateType {
|
|
90
|
-
SQLITE_INSERT = 18,
|
|
91
|
-
SQLITE_DELETE = 9,
|
|
92
|
-
SQLITE_UPDATE = 23
|
|
93
|
-
}
|
|
94
|
-
export interface TableUpdateOperation {
|
|
95
|
-
opType: RowUpdateType;
|
|
96
|
-
rowId: number;
|
|
92
|
+
rollback: () => Promise<void>;
|
|
97
93
|
}
|
|
98
94
|
/**
|
|
99
|
-
*
|
|
95
|
+
* @public
|
|
100
96
|
*/
|
|
101
|
-
export interface UpdateNotification extends TableUpdateOperation {
|
|
102
|
-
table: string;
|
|
103
|
-
}
|
|
104
97
|
export interface BatchedUpdateNotification {
|
|
105
|
-
rawUpdates: UpdateNotification[];
|
|
106
98
|
tables: string[];
|
|
107
|
-
groupedUpdates: Record<string, TableUpdateOperation[]>;
|
|
108
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
109
103
|
export interface DBAdapterListener extends BaseListener {
|
|
110
104
|
/**
|
|
111
105
|
* Listener for table updates.
|
|
@@ -113,49 +107,32 @@ export interface DBAdapterListener extends BaseListener {
|
|
|
113
107
|
* without the need for a major version bump
|
|
114
108
|
* The DB adapter can also batch update notifications if supported.
|
|
115
109
|
*/
|
|
116
|
-
tablesUpdated: (updateNotification: BatchedUpdateNotification
|
|
110
|
+
tablesUpdated: (updateNotification: BatchedUpdateNotification) => void;
|
|
117
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
118
115
|
export interface DBLockOptions {
|
|
119
116
|
timeoutMs?: number;
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
/**
|
|
119
|
+
* @public
|
|
120
|
+
*/
|
|
121
|
+
export declare abstract class DBAdapter extends BaseObserver<DBAdapterListener> implements SqlExecutor, DBGetUtils {
|
|
122
|
+
abstract get name(): string;
|
|
123
|
+
abstract close(): void | Promise<void>;
|
|
124
|
+
abstract readLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
125
|
+
abstract writeLock<T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
126
126
|
/**
|
|
127
127
|
* This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
|
|
128
128
|
*/
|
|
129
|
-
refreshSchema
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
abstract refreshSchema(): Promise<void>;
|
|
130
|
+
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
131
|
+
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
132
|
+
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
133
|
+
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
134
|
+
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
135
|
+
execute<T>(query: string, params?: any[]): Promise<QueryResult<T>>;
|
|
136
|
+
executeRaw(query: string, params?: any[]): Promise<RawQueryResult>;
|
|
137
|
+
executeBatch(query: string, params?: any[][]): Promise<QueryResult<never>>;
|
|
134
138
|
}
|
|
135
|
-
/**
|
|
136
|
-
* A mixin to implement {@link DBAdapter} by delegating to {@link ConnectionPool.readLock} and
|
|
137
|
-
* {@link ConnectionPool.writeLock}.
|
|
138
|
-
*/
|
|
139
|
-
export declare function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase): {
|
|
140
|
-
new (...args: any[]): {
|
|
141
|
-
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
142
|
-
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T>;
|
|
143
|
-
getAll<T>(sql: string, parameters?: any[]): Promise<T[]>;
|
|
144
|
-
getOptional<T>(sql: string, parameters?: any[]): Promise<T | null>;
|
|
145
|
-
get<T>(sql: string, parameters?: any[]): Promise<T>;
|
|
146
|
-
execute(query: string, params?: any[]): Promise<QueryResult>;
|
|
147
|
-
executeRaw(query: string, params?: any[]): Promise<any[][]>;
|
|
148
|
-
executeBatch(query: string, params?: any[][]): Promise<QueryResult>;
|
|
149
|
-
name: string;
|
|
150
|
-
close: () => void | Promise<void>;
|
|
151
|
-
readLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
152
|
-
writeLock: <T>(fn: (tx: LockContext) => Promise<T>, options?: DBLockOptions) => Promise<T>;
|
|
153
|
-
/**
|
|
154
|
-
* This method refreshes the schema information across all connections. This is for advanced use cases, and should generally not be needed.
|
|
155
|
-
*/
|
|
156
|
-
refreshSchema: () => Promise<void>;
|
|
157
|
-
registerListener(listener: Partial<DBAdapterListener>): () => void;
|
|
158
|
-
};
|
|
159
|
-
} & TBase;
|
|
160
|
-
export declare function isBatchedUpdateNotification(update: BatchedUpdateNotification | UpdateNotification): update is BatchedUpdateNotification;
|
|
161
|
-
export declare function extractTableUpdates(update: BatchedUpdateNotification | UpdateNotification): string[];
|