Skip to main content

npm: @powersync/drizzle-driver

This package enables using Drizzle with the PowerSync React Native and JavaScript Web SDKs.

Setup

Set up the PowerSync Database and wrap it with Drizzle.

Schema Conversion

The DrizzleAppSchema constructor simplifies the process of integrating Drizzle with PowerSync. It infers the client-side PowerSync 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. To use it, define your Drizzle tables and supply the schema to the DrizzleAppSchema function:

Defining PowerSync Options

The PowerSync table definition allows additional options supported by PowerSync’s app schema beyond that which are supported by Drizzle. They can be specified as follows. Note that these options exclude indexes as they can be specified in a Drizzle table.

Converting a Single Table From Drizzle to PowerSync

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

Compilable Queries

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

Usage Examples

Below are examples comparing Drizzle and PowerSync syntax for common database operations.

Select Operations

Insert Operations

Delete Operations

Update Operations

Watched Queries

For watched queries with Drizzle it’s recommended to use the watch() function from the Drizzle integration which takes in a Drizzle query.

Transactions

Developer Notes

Table Constraint Restrictions

The Drizzle ORM relies on the underlying PowerSync table definitions which are subject to certain limitations. This means that most Drizzle constraint features (such as cascading deletes, foreign checks, unique) are currently not supported.