vibekōdo
Back to blog

Drizzle works with OP-SQLite on React Native without Expo

vibekōdo1 min read

Drizzle has very good documentation for using it with SQLite on React Native. But mainly for Expo users.

In the doc, Drizzle <> OP SQLite, it lists the steps to connect to OP-SQLite on React Native.

But one line in the provided config confused me.

import type { Config } from 'drizzle-kit';

export default {
	schema: './db/schema.ts',
	out: './drizzle',
  dialect: 'sqlite',
	driver: 'expo', // <--- very important
} satisfies Config;

The driver is expo. But I am not using Expo.

Anyway, I followed the doc and it works without Expo, even though the driver is expo.

Below is how the 2 parts work together.

import {drizzle} from 'drizzle-orm/op-sqlite';
import {open} from '@op-engineering/op-sqlite';
import * as schema from '@/services/db/schema';

// Open the database
const connection = open({
  name: 'dbname.db',
});

// Initialize Drizzle with the connection and schema
export const db = drizzle(connection, {schema});