NitroSQLite

Getting Started

Install Nitro SQLite, rebuild your React Native app, and run your first query.

Nitro SQLite gives React Native apps a local SQLite database on iOS and Android in the Nitro V1 prerelease. The stable 10.x line also supports macOS and visionOS. Start by installing its native package and Nitro Modules, then open a database with open().

1. Install the packages

Nitro SQLite is built with Nitro V1, which requires React Native 0.88 or newer with the New Architecture. iOS builds require Xcode with Swift 6.4 or newer. Install the Nitro version that Nitro SQLite was built with, because the generated native bindings must match it:

npm install react-native-nitro-sqlite@nitro-v1 react-native-nitro-modules@1.0.0-alpha.nightly.138.g43e09c161101

2. Set up the native project

For iOS, follow the React Native SwiftPM setup. If your app uses Expo prebuild, follow the Expo setup to generate the Xcode project and set up SwiftPM before building.

Android needs no additional Nitro SQLite configuration for the default setup. For macOS and visionOS, install Nitro SQLite 10.x with Nitro Modules 0.37.2 and reinstall Pods in your platform's native project. The macOS setup describes the stable macOS example, and the 10.x CocoaPods options cover Apple build settings for both platforms. Use Configuration for the shared package.json options.

3. Rebuild the app

An already installed binary cannot load a native module added only to JavaScript. From a standard React Native CLI project, run the native build for your platform:

npm run ios
# or
npm run android

If your app uses different scripts, run its equivalent native build. See the React Native build setup for platform prerequisites.

For an Expo project, build a native app for your platform:

npx expo run:ios
# or
npx expo run:android

Note

Expo Go does not include Nitro SQLite. Use a native build after adding the package.

For optional features such as FTS5, vector search, or iOS App Groups, use the Expo config plugin.

4. Run your first query

open() returns a connection bound to a database name. SQLite creates the file if it does not exist. This example creates a table, binds a value to ?, and reads it back:

import { open } from 'react-native-nitro-sqlite'

const db = open({ name: 'app.sqlite' })

db.execute(`
  CREATE TABLE IF NOT EXISTS notes (
    id INTEGER PRIMARY KEY,
    body TEXT NOT NULL
  )
`)

const body = 'Read the docs'
db.execute('INSERT INTO notes (body) VALUES (?)', [body])

const { rows } = db.execute<{ id: number; body: string }>(
  'SELECT id, body FROM notes WHERE body = ?',
  [body],
)

console.log(rows._array)
db.close()

Bind user supplied values as parameters rather than putting them into the SQL string. The row generic gives rows._array and rows.item(index) a TypeScript shape; it does not validate database values at runtime. For more result details, see parameters and results.

Keep going

Start with databases and connections for SQLite fundamentals. The Concepts section covers data, queries, transactions, and isolation.

For Nitro SQLite APIs, see database lifecycle, sync and async, and parameters and results. The generated API reference lists public exports and method signatures.

On this page