Skip to content

Commit 102f7ba

Browse files
committed
Merge branch 'feat/drizzle-schema' of github.com:powersync-ja/powersync-js into feat/drizzle-schema
2 parents e4eddd3 + 31759b7 commit 102f7ba

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

packages/drizzle-driver/README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { wrapPowerSyncWithDrizzle } from '@powersync/drizzle-driver';
1515
import { PowerSyncDatabase } from '@powersync/web';
1616
import { relations } from 'drizzle-orm';
1717
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
18-
import { appSchema } from './schema';
18+
import { AppSchema } from './schema';
1919

2020
export const lists = sqliteTable('lists', {
2121
id: text('id'),
@@ -47,23 +47,33 @@ export const drizzleSchema = {
4747
todosRelations
4848
};
4949

50+
// As an alternative to manually defining a PowerSync schema, generate the local PowerSync schema from the Drizzle schema with `toPowerSyncSchema`:
51+
// import { toPowerSyncSchema } from '@powersync/drizzle-driver';
52+
// export const AppSchema = toPowerSyncSchema(drizzleSchema);
53+
//
54+
// This is optional, but recommended, since you will only need to maintain one schema on the client-side
55+
// Read on to learn more.
56+
5057
export const powerSyncDb = new PowerSyncDatabase({
5158
database: {
5259
dbFilename: 'test.sqlite'
5360
},
54-
schema: appSchema
61+
schema: AppSchema
5562
});
5663

64+
// This is the DB you will use in queries
5765
export const db = wrapPowerSyncWithDrizzle(powerSyncDb, {
5866
schema: drizzleSchema
5967
});
6068
```
6169

6270
## Schema Conversion
6371

64-
The `toPowerSyncSchema` schema function simplifies the process of integrating Drizzle with PowerSync. Define your Drizzle tables and supply the schema to the `toPowerSyncSchema` function for a unified development experience.
72+
The `toPowerSyncSchema` function simplifies the process of integrating Drizzle with PowerSync. It infers the local [PowerSync schema](https://docs.powersync.com/installation/client-side-setup/define-your-schema) from your Drizzle schema definition, providing a unified development experience.
73+
74+
As the PowerSync schema only supports SQLite types (`text`, `integer`, and `real`), the same limitation extends to the Drizzle table definitions.
6575

66-
As the PowerSync table only supports `text`, `integer`, and `real`, the same limitation extends to the Drizzle table definitions.
76+
To use it, define your Drizzle tables and supply the schema to the `toPowerSyncSchema` function:
6777

6878
```js
6979
import { toPowerSyncSchema } from '@powersync/drizzle-driver';
@@ -81,6 +91,7 @@ export const drizzleSchema = {
8191
lists
8292
};
8393

94+
// Infer the PowerSync schema from your Drizzle schema
8495
export const AppSchema = toPowerSyncSchema(drizzleSchema);
8596
```
8697

@@ -103,7 +114,7 @@ export const drizzleSchemaWithOptions = {
103114
export const AppSchema = toPowerSyncSchema(drizzleSchemaWithOptions);
104115
```
105116

106-
### Converting a Single Table From Drizzle to Powersync
117+
### Converting a Single Table From Drizzle to PowerSync
107118

108119
Drizzle tables can also be converted on a table-by-table basis with `toPowerSyncTable`.
109120

@@ -128,11 +139,7 @@ export const AppSchema = new Schema({
128139
});
129140
```
130141

131-
## Known limitations
132-
133-
- The integration does not currently support nested transactions (also known as `savepoints`).
134-
135-
### Compilable queries
142+
## Compilable queries
136143

137144
To use Drizzle queries in your hooks and composables, queries need to be converted using `toCompilableQuery`.
138145

@@ -144,3 +151,7 @@ const { data: listRecords, isLoading } = useQuery(toCompilableQuery(query));
144151
```
145152

146153
For more information on how to use Drizzle queries in PowerSync, see [here](https://docs.powersync.com/client-sdk-references/javascript-web/javascript-orm/drizzle#usage-examples).
154+
155+
## Known limitations
156+
157+
- The integration does not currently support nested transactions (also known as `savepoints`).

0 commit comments

Comments
 (0)