Skip to content

Commit 9e3e3a5

Browse files
Experimental: Trigger Based Table Diff Tracking (#663)
Co-authored-by: benitav <[email protected]>
1 parent 8decd49 commit 9e3e3a5

File tree

12 files changed

+1459
-10
lines changed

12 files changed

+1459
-10
lines changed

.changeset/tame-islands-deliver.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@powersync/common': minor
3+
'@powersync/node': minor
4+
'@powersync/react-native': minor
5+
'@powersync/web': minor
6+
---
7+
8+
Added SQLite trigger based table change tracking.

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ docs/react-sdk/
2525
docs/vue-sdk/
2626
docs/web-sdk/
2727
docs/tanstack-react-query-sdk
28+
docs/node-sdk
2829

2930
.env

docs/docusaurus.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { themes as prismThemes } from 'prism-react-renderer';
2-
import type { TypeDocOptionMap } from 'typedoc';
3-
import type { Config } from '@docusaurus/types';
41
import type * as Preset from '@docusaurus/preset-classic';
2+
import type { Config } from '@docusaurus/types';
53
import type { PluginOptions } from 'docusaurus-plugin-typedoc';
6-
import { DOC_FOLDER, packageMap } from './utils/packageMap';
74
import 'dotenv/config';
5+
import { themes as prismThemes } from 'prism-react-renderer';
6+
import type { TypeDocOptionMap } from 'typedoc';
7+
import { DOC_FOLDER, packageMap } from './utils/packageMap';
88

99
const PROJECT_NAME = process.env.GH_PROJECT_NAME;
1010

@@ -155,8 +155,8 @@ const config: Config = {
155155
darkTheme: prismThemes.dracula
156156
},
157157
future: {
158-
experimental_faster: true,
159-
},
158+
experimental_faster: true
159+
}
160160
} satisfies Preset.ThemeConfig
161161
};
162162

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
type PowerSyncConnectionOptions,
3636
type RequiredAdditionalConnectionOptions
3737
} from './sync/stream/AbstractStreamingSyncImplementation.js';
38+
import { TriggerManager } from './triggers/TriggerManager.js';
39+
import { TriggerManagerImpl } from './triggers/TriggerManagerImpl.js';
3840
import { DEFAULT_WATCH_THROTTLE_MS, WatchCompatibleQuery } from './watched/WatchedQuery.js';
3941
import { OnChangeQueryProcessor } from './watched/processors/OnChangeQueryProcessor.js';
4042
import { WatchedQueryComparator } from './watched/processors/comparators.js';
@@ -191,6 +193,12 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
191193

192194
protected runExclusiveMutex: Mutex;
193195

196+
/**
197+
* @experimental
198+
* Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
199+
*/
200+
readonly triggers: TriggerManager;
201+
194202
logger: ILogger;
195203

196204
constructor(options: PowerSyncDatabaseOptionsWithDBAdapter);
@@ -226,6 +234,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
226234
this.ready = false;
227235
this.sdkVersion = '';
228236
this.runExclusiveMutex = new Mutex();
237+
229238
// Start async init
230239
this.connectionManager = new ConnectionManager({
231240
createSyncImplementation: async (connector, options) => {
@@ -252,7 +261,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
252261
},
253262
logger: this.logger
254263
});
264+
255265
this._isReadyPromise = this.initialize();
266+
267+
this.triggers = new TriggerManagerImpl({
268+
db: this,
269+
schema: this.schema
270+
});
256271
}
257272

258273
/**

0 commit comments

Comments
 (0)