Skip to content

Experimental: Trigger Based Table Diff Tracking #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/tame-islands-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@powersync/common': minor
'@powersync/node': minor
'@powersync/react-native': minor
'@powersync/web': minor
---

Added SQLite trigger based table change tracking.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ docs/react-sdk/
docs/vue-sdk/
docs/web-sdk/
docs/tanstack-react-query-sdk
docs/node-sdk

.env
12 changes: 6 additions & 6 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { themes as prismThemes } from 'prism-react-renderer';
import type { TypeDocOptionMap } from 'typedoc';
import type { Config } from '@docusaurus/types';
import type * as Preset from '@docusaurus/preset-classic';
import type { Config } from '@docusaurus/types';
import type { PluginOptions } from 'docusaurus-plugin-typedoc';
import { DOC_FOLDER, packageMap } from './utils/packageMap';
import 'dotenv/config';
import { themes as prismThemes } from 'prism-react-renderer';
import type { TypeDocOptionMap } from 'typedoc';
import { DOC_FOLDER, packageMap } from './utils/packageMap';

const PROJECT_NAME = process.env.GH_PROJECT_NAME;

Expand Down Expand Up @@ -155,8 +155,8 @@ const config: Config = {
darkTheme: prismThemes.dracula
},
future: {
experimental_faster: true,
},
experimental_faster: true
}
} satisfies Preset.ThemeConfig
};

Expand Down
15 changes: 15 additions & 0 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
type PowerSyncConnectionOptions,
type RequiredAdditionalConnectionOptions
} from './sync/stream/AbstractStreamingSyncImplementation.js';
import { TriggerManager } from './triggers/TriggerManager.js';
import { TriggerManagerImpl } from './triggers/TriggerManagerImpl.js';
import { DEFAULT_WATCH_THROTTLE_MS, WatchCompatibleQuery } from './watched/WatchedQuery.js';
import { OnChangeQueryProcessor } from './watched/processors/OnChangeQueryProcessor.js';
import { WatchedQueryComparator } from './watched/processors/comparators.js';
Expand Down Expand Up @@ -191,6 +193,12 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB

protected runExclusiveMutex: Mutex;

/**
* @experimental
* Allows creating SQLite triggers which can be used to track various operations on SQLite tables.
*/
readonly triggers: TriggerManager;

logger: ILogger;

constructor(options: PowerSyncDatabaseOptionsWithDBAdapter);
Expand Down Expand Up @@ -226,6 +234,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
this.ready = false;
this.sdkVersion = '';
this.runExclusiveMutex = new Mutex();

// Start async init
this.connectionManager = new ConnectionManager({
createSyncImplementation: async (connector, options) => {
Expand All @@ -252,7 +261,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
},
logger: this.logger
});

this._isReadyPromise = this.initialize();

this.triggers = new TriggerManagerImpl({
db: this,
schema: this.schema
});
}

/**
Expand Down
Loading