Skip to content

Commit 6e1367d

Browse files
committed
Iterating on readme entry.
1 parent 9be7f91 commit 6e1367d

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

packages/drizzle-driver/README.md

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,76 @@
11
# PowerSync Drizzle Driver
22

3-
```
4-
import { wrapPowerSyncWithDrizzle} from "@powersync/drizzle-driver";
3+
This package (`@powersync/drizzle-driver`) brings the benefits of an ORM through our maintained [Drizzle](https://orm.drizzle.team/) driver to PowerSync.
4+
5+
## Alpha Release
6+
7+
The `drizzle-driver` package is currently in an Alpha release.
8+
9+
## Getting Started
10+
11+
Set up the PowerSync Database and wrap it with Drizzle.
12+
13+
Currently, you need to create the Drizzle schema manually, and it should match the table definitions of your PowerSync AppSchema.
514

6-
export const lists = sqliteTable("lists", {
7-
id: text("id"),
8-
name: text("name"),
15+
```js
16+
import { wrapPowerSyncWithDrizzle } from '@powersync/drizzle-driver';
17+
import { PowerSyncDatabase } from '@powersync/web';
18+
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
19+
import { appSchema } from './schema';
20+
21+
import { wrapPowerSyncWithDrizzle } from '@powersync/drizzle-driver';
22+
23+
export const lists = sqliteTable('lists', {
24+
id: text('id'),
25+
name: text('name')
926
});
1027

11-
export const todos = sqliteTable("todos", {
12-
id: text("id"),
13-
description: text("description"),
14-
list_id: text("list_id"),
15-
created_at: text("created_at"),
28+
export const todos = sqliteTable('todos', {
29+
id: text('id'),
30+
description: text('description'),
31+
list_id: text('list_id'),
32+
created_at: text('created_at')
1633
});
1734

1835
export const listsRelations = relations(lists, ({ one, many }) => ({
19-
todos: many(todos),
36+
todos: many(todos)
2037
}));
2138

2239
export const todosRelations = relations(todos, ({ one, many }) => ({
2340
list: one(lists, {
2441
fields: [todos.list_id],
25-
references: [lists.id],
26-
}),
42+
references: [lists.id]
43+
})
2744
}));
2845

29-
export const db = wrapPowerSyncWithDrizzle(PowerSync, {
30-
schema: {
31-
lists,
32-
todos,
33-
listsRelations,
34-
todosRelations,
46+
export const drizzleSchema = {
47+
lists,
48+
todos,
49+
listsRelations,
50+
todosRelations
51+
};
52+
53+
export const powerSyncDb = new PowerSyncDatabase({
54+
database: {
55+
dbFilename: 'test.sqlite'
3556
},
57+
schema: appSchema
3658
});
3759

60+
export const db = wrapPowerSyncWithDrizzle(powerSyncDb, {
61+
schema: drizzleSchema
62+
});
3863
```
3964

4065
## Compilable queries
4166

42-
To use drizzle queries in our hooks and composables they currently need to be converted.
67+
To use Drizzle queries in your hooks and composables, they currently need to be converted using `toCompilableQuery`.
4368

44-
```
45-
import { toCompilableQuery } from "@powersync/drizzle-driver";
69+
```js
70+
import { toCompilableQuery } from '@powersync/drizzle-driver';
4671

47-
const query = drizzleDb.select().from(lists);
72+
const query = db.select().from(lists);
4873
const { data: listRecords, isLoading } = useQuery(toCompilableQuery(query));
4974
```
75+
76+
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).

0 commit comments

Comments
 (0)