This package (@powersync-community/drizzle-op-sqlite-sync) brings the benefits of an ORM to your synchronous React Native applications by integrating Drizzle ORM with the op-sqlite database.
The drizzle-op-sqlite-sync package is currently in an Alpha release.
A demo project is available in the demo folder of this repository. It is a React Native project that uses bare bones React Native to run on iOS and Android.
To run the demo project:
- Navigate to the
demofolder - Run
pnpm installto install dependencies - Run
pnpm run startto start the Metro bundler - In another terminal, run
pnpm run iosorpnpm run android
If you encounter any issues, please refer to the React Native Getting Started guide to ensure your environment is set up correctly.
Set up the PowerSync Database and wrap it with Drizzle.
import { relations } from 'drizzle-orm';
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { drizzle } from '@powersync-community/drizzle-op-sqlite-sync';
const lists = sqliteTable('lists', {
id: text('id'),
name: text('name'),
owner_id: text('owner_id')
});
const opSqlite = open({
name: 'my-database.db'
});
// This is the DB you will use in queries
const db = drizzle(opSqlite, {
schema: {
lists
}
});
const allLists = db.select().from(lists).all();
console.log(allLists); // [{ id: '1', name: 'My List' }]