NitroSQLite
Integrations

ORMs and query builders

Install an integration, open a local SQLite database, and write and read your first row.

SQLite stores tables and indexes in a file on the device. An ORM maps entities to those tables and tracks changes to objects. A query builder compiles typed SQL and bound parameters. Both use the same SQLite transactions and file locks as direct queries.

For entity mapping, dialects, and migrations, see how ORMs work with SQLite. Choose the integration that matches how your app represents its data. Each package below uses the SQLite adapter for the same host. Keep one ORM or query-builder instance for each database and close it after its outstanding work finishes.

IntegrationReact NativeNitroUI
Drizzlereact-native-nitro-sqlite-drizzlenitro-sqlite-drizzle
TypeORMreact-native-nitro-sqlite-typeormnitro-sqlite-typeorm
MikroORMreact-native-nitro-sqlite-mikro-ormnitro-sqlite-mikro-orm
Kyselyreact-native-nitro-sqlite-kyselynitro-sqlite-kysely

Drizzle and Kysely use typed queries. TypeORM and MikroORM also provide entity mapping and change tracking. Vector search has a separate guide.

Choose Drizzle ORM, TypeORM, MikroORM, or Kysely, a typed SQL query builder. All four store data in SQLite on the device. Vector search has a separate guide.

For the difference between entity mapping and a typed query builder, see How ORMs work with SQLite.

Installation

Follow Getting Started to install Nitro SQLite and Nitro Modules. Add the packages for your library below before rebuilding the native app.

Install Drizzle and its Nitro SQLite driver.

npm install react-native-nitro-sqlite-drizzle drizzle-orm@0.45.4

Install TypeORM and the Babel plugins, then configure module resolution.

npm install typeorm@1.1.2
npm install --save-dev babel-plugin-module-resolver @babel/plugin-transform-class-static-block

Nitro SQLite 10.4.0 includes the TypeORM driver in core. For releases that ship the standalone adapter, also run npm install react-native-nitro-sqlite-typeorm and switch the driver import and Babel alias.

Install the driver and its runtime dependencies. Configure Metro, Babel, and Buffer before importing the ORM.

npm install react-native-nitro-sqlite-mikro-orm @mikro-orm/core@7.2.13 @mikro-orm/sql@7.2.13 kysely@0.29.9 @craftzdog/react-native-buffer@6.1.2 react-native-quick-base64@3.0.1 base64-js@1.5.1

Install Kysely and its Nitro SQLite dialect.

npm install react-native-nitro-sqlite-kysely 'kysely@^0.29.9'

Install from a source checkout

Use a source checkout with its workspace dependencies installed. The NitroUI companion packages are source previews. For this checkout, build local archives of the SQLite adapter and companions for your host. The archive name contains the version in each package manifest.

From the package directory for your host and integration, build a local archive. For example:

cd packages/integrations/nitro-ui/kysely
bun run pack

For the staged NitroUI package version, this produces nitro-sqlite-kysely-11.0.0.tgz. Use the corresponding packages/integrations/react-native/kysely directory for React Native. The ORM companions have the same packing entry point. For React Native Vec, run bun pm pack in packages/integrations/react-native/vec instead.

Install the archive into your app alongside the SQLite adapter for that host. For NitroUI, follow adapter installation. For React Native, follow React Native setup and use the matching SQLite archive from this checkout.

A companion archive includes its shared implementation. Your app does not need shared/orm, nitro-sqlite-core, or nitro-sqlite-drizzle-core installed from a registry. If you install a package through a local directory instead of an archive, prepare it from the source checkout first.

NitroUI apps also need the ORM libraries in the installation tabs above, using their nitro-sqlite-* companions instead of the React Native companions. MikroORM requires both its driver and Kysely companion archives. Its NitroUI browser bundle and Buffer setup uses JavaScript dependencies. React Native keeps its native Buffer setup or can use the shared JavaScript adapter.

Usage

The examples below use React Native imports. For NitroUI, replace the react-native-nitro-sqlite prefix with nitro-sqlite. Complete each guide's host setup first, including TypeORM and MikroORM browser bundles.

Open the database, create a table, and read back the note you insert. For an app that keeps its database open, initialize it once and close it after outstanding queries finish.

import { eq } from 'drizzle-orm'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
import { open } from 'react-native-nitro-sqlite'
import { drizzle } from 'react-native-nitro-sqlite-drizzle'

const notes = sqliteTable('notes', {
  id: integer('id').primaryKey(),
  title: text('title').notNull(),
})

const connection = open({ name: 'notes.sqlite' })
const db = drizzle(connection)
try {
  connection.execute(
    'CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, title TEXT NOT NULL)',
  )
  const { id } = await db
    .insert(notes)
    .values({ title: 'Packing list' })
    .returning({ id: notes.id })
    .get()
  const saved = await db.select().from(notes).where(eq(notes.id, id)).get()
  console.log(saved?.title)
} finally {
  connection.close()
}

See the Drizzle ORM guide for Drizzle Kit migrations, connection options, and transactions.

This example uses the core 10.4.0 driver. With the standalone adapter, import typeORMDriver from react-native-nitro-sqlite-typeorm.

import { DataSource, EntitySchema } from 'typeorm'
import { typeORMDriver } from 'react-native-nitro-sqlite'

type Note = { id: number; title: string }

const NoteEntity = new EntitySchema<Note>({
  name: 'Note',
  tableName: 'notes',
  columns: {
    id: { type: Number, primary: true, generated: true },
    title: { type: String },
  },
})

const dataSource = new DataSource({
  type: 'react-native',
  database: 'notes.sqlite',
  location: '.',
  driver: typeORMDriver,
  entities: [NoteEntity],
  synchronize: true,
})

await dataSource.initialize()
try {
  const notes = dataSource.getRepository(NoteEntity)
  const { id } = await notes.save({ title: 'Packing list' })
  const saved = await notes.findOneByOrFail({ id })
  console.log(saved.title)
} finally {
  await dataSource.destroy()
}

See the TypeORM guide for schema management, connection callbacks, and encryption.

import { defineEntity, MikroORM, p } from '@mikro-orm/sql'
import { NitroSQLiteDriver } from 'react-native-nitro-sqlite-mikro-orm'

const Note = defineEntity({
  name: 'Note',
  tableName: 'notes',
  properties: {
    id: p.integer().primary(),
    title: p.string(),
  },
})

const orm = new MikroORM({
  driver: NitroSQLiteDriver,
  dbName: 'notes.sqlite',
  entities: [Note],
})

try {
  await orm.schema.update()
  const writer = orm.em.fork()
  const note = writer.create(Note, { title: 'Packing list' })
  await writer.flush()
  const saved = await orm.em.fork().findOneOrFail(Note, note.id)
  console.log(saved.title)
} finally {
  await orm.close()
}

See the MikroORM guide for entity discovery, transactions, and paging.

import { Kysely, type Generated } from 'kysely'
import { createNitroSQLiteDialect } from 'react-native-nitro-sqlite-kysely'

interface Database {
  notes: { id: Generated<number>; title: string }
}

const db = new Kysely<Database>({
  dialect: createNitroSQLiteDialect({ name: 'notes.sqlite' }),
})

try {
  await db.schema
    .createTable('notes')
    .ifNotExists()
    .addColumn('id', 'integer', (column) => column.primaryKey())
    .addColumn('title', 'text', (column) => column.notNull())
    .execute()
  const { id } = await db
    .insertInto('notes')
    .values({ title: 'Packing list' })
    .returning('id')
    .executeTakeFirstOrThrow()
  const saved = await db
    .selectFrom('notes')
    .select('title')
    .where('id', '=', id)
    .executeTakeFirstOrThrow()
  console.log(saved.title)
} finally {
  await db.destroy()
}

See the Kysely guide for connection lifetime, migrations, transactions, and binary values.