You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,58 +11,132 @@ This package enables using [Drizzle](https://orm.drizzle.team/) with the PowerSy
11
11
12
12
Set up the PowerSync Database and wrap it with Drizzle.
13
13
14
-
Currently, you need to create the Drizzle schema manually, and it should match the table definitions of your PowerSync [client-side schema](/installation/client-side-setup/define-your-schema).
import { index, integer, sqliteTable, text } from'drizzle-orm/sqlite-core';
19
+
import { AppSchema } from'./schema';
20
+
21
+
exportconstlists=sqliteTable('lists', {
22
+
id:text('id'),
23
+
name:text('name')
27
24
});
28
25
29
-
exportconsttodos=sqliteTable("todos", {
30
-
id:text("id"),
31
-
description:text("description"),
32
-
list_id:text("list_id"),
33
-
created_at:text("created_at"),
26
+
exportconsttodos=sqliteTable('todos', {
27
+
id:text('id'),
28
+
description:text('description'),
29
+
list_id:text('list_id'),
30
+
created_at:text('created_at')
34
31
});
35
32
36
33
exportconstlistsRelations=relations(lists, ({ one, many }) => ({
37
-
todos:many(todos),
34
+
todos:many(todos)
38
35
}));
39
36
40
37
exportconsttodosRelations=relations(todos, ({ one, many }) => ({
41
38
list:one(lists, {
42
39
fields: [todos.list_id],
43
-
references: [lists.id],
44
-
}),
40
+
references: [lists.id]
41
+
})
45
42
}));
46
43
47
44
exportconstdrizzleSchema= {
48
45
lists,
49
46
todos,
50
47
listsRelations,
51
-
todosRelations,
48
+
todosRelations
52
49
};
53
50
54
-
// Existing PowerSync database constructor
51
+
// As an alternative to manually defining a PowerSync schema, generate the local PowerSync schema from the Drizzle schema with the `DrizzleAppSchema` constructor:
52
+
// import { DrizzleAppSchema } from '@powersync/drizzle-driver';
53
+
// export const AppSchema = new DrizzleAppSchema(drizzleSchema);
54
+
//
55
+
// This is optional, but recommended, since you will only need to maintain one schema on the client-side
The `DrizzleAppSchema` constructor simplifies the process of integrating Drizzle with PowerSync. It infers the local [PowerSync schema](/installation/client-side-setup/define-your-schema) from your Drizzle schema definition, providing a unified development experience.
74
+
75
+
As the PowerSync schema only supports SQLite types (`text`, `integer`, and `real`), the same limitation extends to the Drizzle table definitions.
76
+
77
+
To use it, define your Drizzle tables and supply the schema to the `DrizzleAppSchema` function:
lists: psLists // names the table `lists` in the PowerSync schema
66
140
});
67
141
```
68
142
@@ -219,4 +293,11 @@ For watched queries with Drizzle it's recommended to use the `watch()` function
219
293
// 'James Smith'
220
294
221
295
```
222
-
</CodeGroup>
296
+
</CodeGroup>
297
+
298
+
## Developer Notes
299
+
300
+
### Table Constraint Restrictions
301
+
302
+
The Drizzle ORM relies on the underlyng PowerSync table definitions which are subject to certain limitations.
303
+
This means that most Drizzle [constraint features](https://orm.drizzle.team/docs/indexes-constraints) (such as cascading deletes, foreign checks, unique) are currently not supported.
0 commit comments