{"id":19537440,"url":"https://github.com/margelo/react-native-nitro-sqlite","last_synced_at":"2026-03-08T18:04:17.270Z","repository":{"id":268570356,"uuid":"623876293","full_name":"margelo/react-native-nitro-sqlite","owner":"margelo","description":"📕 Fast SQLite library for React Native built using Nitro Modules","archived":false,"fork":false,"pushed_at":"2025-12-26T03:00:55.000Z","size":12310,"stargazers_count":514,"open_issues_count":43,"forks_count":41,"subscribers_count":6,"default_branch":"main","last_synced_at":"2026-01-22T04:50:24.515Z","etag":null,"topics":["android","cplusplus","cpp","ios","lib","native","nitro","nitro-modules","nitrogen","react","react-native","sql","sqlite","storage"],"latest_commit_sha":null,"homepage":"https://margelo.com","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/margelo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["mrousavy","chrispader"]}},"created_at":"2023-04-05T09:24:15.000Z","updated_at":"2026-01-20T20:10:50.000Z","dependencies_parsed_at":"2024-12-17T16:13:54.432Z","dependency_job_id":"d8336596-bb8c-4f7c-8df2-3e505273f85c","html_url":"https://github.com/margelo/react-native-nitro-sqlite","commit_stats":null,"previous_names":["margelo/react-native-nitro-sqlite"],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/margelo/react-native-nitro-sqlite","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/margelo%2Freact-native-nitro-sqlite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/margelo%2Freact-native-nitro-sqlite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/margelo%2Freact-native-nitro-sqlite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/margelo%2Freact-native-nitro-sqlite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/margelo","download_url":"https://codeload.github.com/margelo/react-native-nitro-sqlite/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/margelo%2Freact-native-nitro-sqlite/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29092983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-04T03:31:03.593Z","status":"ssl_error","status_checked_at":"2026-02-04T03:29:50.742Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cplusplus","cpp","ios","lib","native","nitro","nitro-modules","nitrogen","react","react-native","sql","sqlite","storage"],"created_at":"2024-11-11T02:27:57.038Z","updated_at":"2026-03-08T18:04:17.257Z","avatar_url":"https://github.com/margelo.png","language":"C","readme":"\u003ca href=\"https://margelo.com\"\u003e\n  \u003cpicture\u003e\n    \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"./assets/img/banner-dark.png\" /\u003e\n    \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"./assets/img/banner-light.png\" /\u003e\n    \u003cimg alt=\"Nitro Modules\" src=\"./assets/img/banner-light.png\" /\u003e\n  \u003c/picture\u003e\n\u003c/a\u003e\n\n\u003cbr /\u003e\n\n\u003e [!IMPORTANT]\n\u003e `react-native-quick-sqlite` has been deprecated in favor of this new [Nitro module](https://nitro.margelo.com/) implementation.\n\u003e\n\u003e From major version `9.0.0` on, the package is `react-native-nitro-sqlite`. Bug fixes for `react-native-quick-sqlite@8.x.x` will continue for a limited time.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cpre align=\"center\"\u003e\n    npm i react-native-nitro-sqlite react-native-nitro-modules\n    npx pod-install\u003c/pre\u003e\n  \u003ca align=\"center\" href=\"https://github.com/margelo\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/followers/margelo?label=Follow%20%40margelo\u0026style=social\" /\u003e\n  \u003c/a\u003e\n  \u003cbr /\u003e\n  \u003ca align=\"center\" href=\"https://twitter.com/margelo_io\"\u003e\n    \u003cimg src=\"https://img.shields.io/twitter/follow/margelo_io?label=Follow%20%40margelo_io\u0026style=social\" /\u003e\n  \u003c/a\u003e\n  \u003ca align=\"center\" href=\"https://bsky.app/profile/margelo.com\"\u003e\n    \u003cimg src=\"https://img.shields.io/twitter/follow/margelo_com?label=Follow%20%40margelo_com\u0026style=social\u0026logo=bluesky\u0026url=https%3A%2F%2Fbsky.app%2Fprofile%2Fmargelo.com\" style=\"pointer-events: 'none'\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n\u003e [!NOTE]\n\u003e Requires [Nitro modules](https://nitro.margelo.com/) and React Native `0.71` or later.\n\nNitro SQLite embeds SQLite and exposes a JSI API. Each operation is available in **sync** and **async** form; async runs off the JS thread to avoid blocking the UI.\n\n---\n\n# Installation\n\n```bash\nnpm install react-native-nitro-sqlite react-native-nitro-modules\nnpx pod-install\n```\n\n---\n\n# API overview\n\nOpen a database with `open()`. The returned connection is used for all operations; the database name is bound to that connection.\n\n```typescript\nimport { open } from 'react-native-nitro-sqlite'\n\nconst db = open({ name: 'myDb.sqlite' })\n// Optional: open({ name: 'myDb.sqlite', location: '/some/path' })\n```\n\n| Method | Sync | Async | Description |\n|--------|------|-------|-------------|\n| **Execute** | `db.execute(query, params?)` | `db.executeAsync(query, params?)` | Run a single SQL statement. |\n| **Batch** | `db.executeBatch(commands)` | `db.executeBatchAsync(commands)` | Run multiple statements in one transaction. |\n| **Load file** | `db.loadFile(path)` | `db.loadFileAsync(path)` | Execute SQL from a file. |\n| **Transaction** | — | `db.transaction(async (tx) =\u003e { ... })` | Run multiple statements in a transaction (async only). |\n| **Lifecycle** | `db.close()`, `db.delete()` | — | Close or delete the database. |\n| **Attach** | `db.attach(dbName, alias, location?)`, `db.detach(alias)` | — | Attach/detach another database. |\n\n---\n\n# Sync vs async\n\n- **Sync** (`execute`, `executeBatch`, `loadFile`): Run on the JS thread. Use for small, fast work; heavy work can block the UI.\n- **Async** (`executeAsync`, `executeBatchAsync`, `loadFileAsync`, `transaction`): Run off the JS thread. Prefer these for larger or many queries to keep the app responsive.\n\n---\n\n# Basic usage\n\n## Execute (sync and async)\n\nBoth return a result with `results` (array of rows), `rowsAffected`, and `insertId` (when relevant). Rows are plain objects keyed by column name.\n\n```typescript\n// Sync — blocks JS thread\nconst { results, rowsAffected } = db.execute(\n  'UPDATE sometable SET somecolumn = ? WHERE somekey = ?',\n  [0, 1]\n)\n\n// Async — off JS thread\nconst { results } = await db.executeAsync('SELECT * FROM sometable')\nresults.forEach((row) =\u003e console.log(row))\n```\n\n## Transactions (async only)\n\nUse `db.transaction()` for multiple statements in a single transaction. The callback receives a `tx` object with `execute`, `executeAsync`, `commit`, and `rollback`. If the callback throws, the transaction is rolled back. Otherwise it is committed when the callback resolves (or you can call `tx.commit()` / `tx.rollback()` explicitly).\n\n```typescript\nawait db.transaction(async (tx) =\u003e {\n  tx.execute('UPDATE sometable SET somecolumn = ? WHERE somekey = ?', [0, 1])\n  await tx.executeAsync('INSERT INTO sometable (id, name) VALUES (?, ?)', [2, 'foo'])\n  // Uncaught error → rollback\n  // Success → commit (or call tx.commit() / tx.rollback() yourself)\n})\n```\n\n## Batch (sync and async)\n\nRun many statements in one transaction. Each command has `query` and optional `params`. For one query with many parameter sets, use a single `query` and `params` as an array of arrays.\n\n```typescript\nconst commands = [\n  { query: 'CREATE TABLE IF NOT EXISTS TEST (id INTEGER, age INTEGER)' },\n  { query: 'INSERT INTO TEST (id, age) VALUES (?, ?)', params: [1, 10] },\n  { query: 'INSERT INTO TEST (id, age) VALUES (?, ?)', params: [2, 20] },\n  {\n    query: 'INSERT INTO TEST (id, age) VALUES (?, ?)',\n    params: [\n      [3, 30],\n      [4, 40],\n    ],\n  },\n]\n\nconst { rowsAffected } = db.executeBatch(commands)\n// Or: await db.executeBatchAsync(commands)\n```\n\n## Dynamic Column Metadata\n\n# Column metadata\n\nWhen you need column types or names for the result set, use the `metadata` field on the query result. Keys are column names; values include `name`, `type` (e.g. from `ColumnType`), and `index`.\n\n```typescript\nconst { results, metadata } = db.execute('SELECT id, name FROM users LIMIT 1')\nif (metadata) {\n  for (const [columnName, meta] of Object.entries(metadata)) {\n    console.log(columnName, meta.type, meta.index)\n  }\n}\n```\n\n---\n\n# Attach / detach\n\nAttach another database file under an alias; useful for JOINs across files or separate configs. Detach when no longer needed. Closing the main connection detaches all.\n\n```typescript\ndb.attach('otherDb.sqlite', 'other', '/path/to/dir')\nconst { results } = db.execute(\n  'SELECT * FROM main.users a INNER JOIN other.stats b ON a.id = b.user_id'\n)\ndb.detach('other')\n```\n\n---\n\n# Loading SQL files\n\nExecute all statements in a file (e.g. a dump). Sync and async; async is better for large files.\n\n```typescript\nconst { rowsAffected, commands } = db.loadFile('/absolute/path/to/file.sql')\n// Or: await db.loadFileAsync('/absolute/path/to/file.sql')\n```\n\n---\n\n# Loading existing databases\n\nDatabases are created under the app documents directory (iOS) or files directory (Android). To open an existing file elsewhere, use `location` in `open()`, or use relative paths from that root (e.g. `../www/myDb.sqlite`). On iOS you cannot access paths outside the app sandbox. You can also copy or move files with a React Native file library before opening.\n\n---\n\n# TypeORM\n\nYou can use this package as a TypeORM driver. Because of Metro and Node resolution, TypeORM’s `package.json` must be exposed and the driver aliased.\n\n1. **Expose TypeORM `package.json`** (in TypeORM’s `package.json` `exports` add `\"./package.json\": \"./package.json\"`), then:\n   ```sh\n   npx patch-package --exclude 'nothing' typeorm\n   ```\n2. **Alias the driver** in `babel.config.js`:\n   ```js\n   plugins: [\n     [\n       'module-resolver',\n       {\n         alias: {\n           'react-native-sqlite-storage': 'react-native-nitro-sqlite',\n         },\n       },\n     ],\n   ]\n   ```\n   Install: `npm i -D babel-plugin-module-resolver`\n3. **Use the driver**:\n   ```ts\n   import { typeORMDriver } from 'react-native-nitro-sqlite'\n\n   const datasource = new DataSource({\n     type: 'react-native',\n     database: 'typeormdb',\n     location: '.',\n     driver: typeORMDriver,\n     entities: [...],\n     synchronize: true,\n   })\n   ```\n\n---\n\n# Configuration\n\n## Use system SQLite on iOS\n\nTo use the system SQLite instead of the bundled one:\n\n```bash\nNITRO_SQLITE_USE_PHONE_VERSION=1 npx pod-install\n```\n\n## Compile-time options (e.g. FTS5, Geopoly)\n\n**iOS** — in your app’s `ios/Podfile`, in a `post_install` block:\n\n```ruby\ninstaller.pods_project.targets.each do |target|\n  if target.name == \"RNNitroSQLite\"\n    target.build_configurations.each do |config|\n      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']\n      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] \u003c\u003c 'SQLITE_ENABLE_FTS5=1'\n    end\n  end\nend\n```\n\n**Android** — in `android/gradle.properties`:\n\n```properties\nnitroSqliteFlags=\"-DSQLITE_ENABLE_FTS5=1\"\n```\n\n## App groups (iOS)\n\nTo put the database in an app group (e.g. for extensions), set `RNNitroSQLite_AppGroup` in your `Info.plist` to the app group ID and add the App Groups capability in Xcode.\n\n---\n\n# Exports\n\n```typescript\nimport {\n  open,\n  NitroSQLiteError,\n  typeORMDriver,\n} from 'react-native-nitro-sqlite'\nimport type { QueryResult, BatchQueryCommand, NitroSQLiteConnection, ... } from 'react-native-nitro-sqlite'\n```\n\n---\n\n# Community\n\n[Join the Margelo Community Discord](https://discord.gg/6CSHz2qAvA)\n\n# License\n\nMIT License.\n","funding_links":["https://github.com/sponsors/mrousavy","https://github.com/sponsors/chrispader"],"categories":["Published"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmargelo%2Freact-native-nitro-sqlite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmargelo%2Freact-native-nitro-sqlite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmargelo%2Freact-native-nitro-sqlite/lists"}