Skip to content

Commit 95fb832

Browse files
committed
Updated Readme.
1 parent 4b7c60f commit 95fb832

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

packages/drizzle-driver/README.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,54 @@ export const db = wrapPowerSyncWithDrizzle(powerSyncDb, {
5959
});
6060
```
6161

62-
## Converting Drizzle Tables to PowerSync Tables
62+
## Schema Conversion
6363

64-
The `toPowerSyncTable` function simplifies the process of integrating Drizzle with PowerSync. Define your Drizzle tables, convert each using `toPowerSyncTable`, and supply the converted table definitions into your PowerSync schema for a unified development experience.
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.
6565

6666
As the PowerSync table only supports `text`, `integer`, and `real`, the same limitation extends to the Drizzle table definitions.
6767

68+
```js
69+
import { toPowerSyncSchema } from '@powersync/drizzle-driver';
70+
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
71+
72+
// Define a Drizzle table
73+
const lists = sqliteTable('lists', {
74+
id: text('id').primaryKey().notNull(),
75+
created_at: text('created_at'),
76+
name: text('name').notNull(),
77+
owner_id: text('owner_id')
78+
});
79+
80+
export const drizzleSchema = {
81+
lists
82+
};
83+
84+
export const AppSchema = toPowerSyncSchema(drizzleSchema);
85+
```
86+
87+
### Defining PowerSync Options
88+
89+
The PowerSync table definition allows additional options supported by PowerSync's app schema beyond that which are supported by Drizzle.
90+
They can be specified as follows. Note that these options exclude indexes as they can be specified in a Drizzle table.
91+
92+
```js
93+
import { toPowerSyncSchema } from '@powersync/drizzle-driver';
94+
// import { toPowerSyncSchema, type DrizzleTableWithPowerSyncOptions} from '@powersync/drizzle-driver'; for TypeScript
95+
96+
const listsWithOptions = { tableDefinition: logs, options: { localOnly: true } };
97+
// const listsWithOptions: DrizzleTableWithPowerSyncOptions = { tableDefinition: logs, options: { localOnly: true } }; for TypeScript
98+
99+
export const drizzleSchemaWithOptions = {
100+
lists: listsWithOptions
101+
};
102+
103+
export const AppSchema = toPowerSyncSchema(drizzleSchemaWithOptions);
104+
```
105+
106+
### Converting a Single Table From Drizzle to Powersync
107+
108+
Drizzle tables can also be converted on a table-by-table basis with `toPowerSyncTable`.
109+
68110
```js
69111
import { toPowerSyncTable } from '@powersync/drizzle-driver';
70112
import { Schema } from '@powersync/web';
@@ -79,7 +121,7 @@ const lists = sqliteTable('lists', {
79121
});
80122

81123
const psLists = toPowerSyncTable(lists); // converts the Drizzle table to a PowerSync table
82-
// toPowerSyncTable(lists, { localOnly: true }); - th allows for PowerSync table configuration
124+
// toPowerSyncTable(lists, { localOnly: true }); - allows for PowerSync table configuration
83125

84126
export const AppSchema = new Schema({
85127
lists: psLists // names the table `lists` in the PowerSync schema

0 commit comments

Comments
 (0)