Skip to content

Commit

Permalink
Update readme for slightly improved flow
Browse files Browse the repository at this point in the history
  • Loading branch information
benitav committed Nov 21, 2024
1 parent 2cfd592 commit b3882ac
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/drizzle-driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,24 @@ export const powerSyncDb = new PowerSyncDatabase({
schema: appSchema
});

// This is the DB you will use in queries
export const db = wrapPowerSyncWithDrizzle(powerSyncDb, {
schema: drizzleSchema
});

// Generate the local PowerSync schema from the Drizzle schema with `toPowerSyncSchema`
// Optional, but recommended, since you will only need to maintain one schema on the client-side
// Read on to learn more.
export const AppSchema = toPowerSyncSchema(drizzleSchema);
```

## Schema Conversion

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.
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.

As the PowerSync schema only supports SQLite types (`text`, `integer`, and `real`), the same limitation extends to the Drizzle table definitions.

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

```js
import { toPowerSyncSchema } from '@powersync/drizzle-driver';
Expand All @@ -81,6 +89,7 @@ export const drizzleSchema = {
lists
};

// Infer the PowerSync schema from your Drizzle schema
export const AppSchema = toPowerSyncSchema(drizzleSchema);
```

Expand All @@ -103,7 +112,7 @@ export const drizzleSchemaWithOptions = {
export const AppSchema = toPowerSyncSchema(drizzleSchemaWithOptions);
```

### Converting a Single Table From Drizzle to Powersync
### Converting a Single Table From Drizzle to PowerSync

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

Expand All @@ -128,11 +137,7 @@ export const AppSchema = new Schema({
});
```

## Known limitations

- The integration does not currently support nested transactions (also known as `savepoints`).

### Compilable queries
## Compilable queries

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

Expand All @@ -144,3 +149,7 @@ const { data: listRecords, isLoading } = useQuery(toCompilableQuery(query));
```

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).

## Known limitations

- The integration does not currently support nested transactions (also known as `savepoints`).

0 comments on commit b3882ac

Please sign in to comment.