Skip to content

Commit 1c42a69

Browse files
authored
Improve docs for raw tables (#666)
1 parent cb6d3ec commit 1c42a69

File tree

3 files changed

+10
-27
lines changed

3 files changed

+10
-27
lines changed

.changeset/bright-snakes-clean.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,6 @@
77

88
Add experimental support for raw tables, giving you full control over the table structure to sync into.
99
While PowerSync manages tables as JSON views by default, raw tables have to be created by the application
10-
developer. Also, the upsert and delete statements for raw tables needs to be specified in the app schema:
10+
developer.
1111

12-
```JavaScript
13-
const customSchema = new Schema({});
14-
customSchema.withRawTables({
15-
lists: {
16-
put: {
17-
sql: 'INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)',
18-
// put statements can use `Id` and extracted columns to bind parameters.
19-
params: ['Id', { Column: 'name' }]
20-
},
21-
delete: {
22-
sql: 'DELETE FROM lists WHERE id = ?',
23-
// delete statements can only use the id (but a CTE querying existing rows by id could
24-
// be used as a workaround).
25-
params: ['Id']
26-
}
27-
}
28-
});
29-
30-
const powersync = // open powersync database;
31-
await powersync.execute('CREATE TABLE lists (id TEXT NOT NULL PRIMARY KEY, name TEXT);');
32-
33-
// Ready to sync into your custom table at this point
34-
```
35-
36-
The main benefit of raw tables is better query performance (since SQLite doesn't have to
37-
extract rows from JSON) and more control (allowing the use of e.g. column and table constraints).
12+
For more information about raw tables, see [the documentation](https://docs.powersync.com/usage/use-case-examples/raw-tables).

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ The next upload iteration will be delayed.`);
623623
}
624624

625625
private async legacyStreamingSyncIteration(signal: AbortSignal, resolvedOptions: RequiredPowerSyncConnectionOptions) {
626+
if (resolvedOptions.serializedSchema?.raw_tables != null) {
627+
this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.');
628+
}
629+
626630
this.logger.debug('Streaming sync iteration started');
627631
this.options.adapter.startSession();
628632
let [req, bucketMap] = await this.collectLocalBucketState();

packages/common/src/db/schema/RawTable.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export type PendingStatement = {
3838
* Since raw tables are not backed by JSON, running complex queries on them may be more efficient. Further, they allow
3939
* using client-side table and column constraints.
4040
*
41+
* To collect local writes to raw tables with PowerSync, custom triggers are required. See
42+
* {@link https://docs.powersync.com/usage/use-case-examples/raw-tables the documentation} for details and an example on
43+
* using raw tables.
44+
*
4145
* Note that raw tables are only supported when using the new `SyncClientImplementation.rust` sync client.
4246
*
4347
* @experimental Please note that this feature is experimental at the moment, and not covered by PowerSync semver or

0 commit comments

Comments
 (0)