Registry / database / react-native-sqlite-2

react-native-sqlite-2

JSON →
library3.6.3jsnpmunverified

React Native SQLite 2 is a native SQLite3 plugin for React Native supporting iOS, Android, Windows, and macOS. It provides a WebSQL-compatible API and serves as a drop-in replacement for react-native-sqlite-storage, specifically solving issues with null characters (\u0000) in string data and attachment storage that affected PouchDB compatibility. It uses sqlite-android to deliver a newer SQLite version on Android with support for JSON1, CTE, expression indexes, and FTS5. Current stable version: 3.6.3. Release cadence is irregular; maintained by craftzdog. Key differentiator: PouchDB-friendly due to proper handling of null characters and stable attachment storage, and a more up-to-date SQLite engine on Android.

npm install react-native-sqlite-2
INSTALL
IMPORT
SIG · REACT-NATIVE-SQLIT
R
react-native-sqlite-2
databasejavascriptv3.6.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SQLite
✓ import SQLite from 'react-native-sqlite-2'
✗ const SQLite = require('react-native-sqlite-2')
Default import. No named exports; the module exports a single object with openDatabase and deleteDatabase.
openDatabase
✓ const db = SQLite.openDatabase('test.db', '1.0', '', 1)
✗ const db = SQLite.openDatabase({name: 'test.db', version: '1.0'})
openDatabase takes positional arguments: name, version, description, size. Object argument is not supported.
deleteDatabase
✓ SQLite.deleteDatabase('test.db')
✗ const { deleteDatabase } = require('react-native-sqlite-2'); deleteDatabase('test.db')
deleteDatabase is a method on the default export, not a named export.

Opens a database, creates a table, inserts a row, and queries all rows using WebSQL-compatible transaction API.

import SQLite from 'react-native-sqlite-2'; const db = SQLite.openDatabase('test.db', '1.0', '', 1); db.transaction((txn) => { txn.executeSql( 'CREATE TABLE IF NOT EXISTS users (user_id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(30))', [] ); txn.executeSql('INSERT INTO users (name) VALUES (?)', ['Alice']); txn.executeSql('SELECT * FROM users', [], (tx, res) => { for (let i = 0; i < res.rows.length; ++i) { console.log('User:', res.rows.item(i).name); } }); });
Debug
Known issues
gotchaopenDatabase expects positional arguments (name, version, description, size). Passing an object will fail silently or throw.
fix
Use positional arguments: openDatabase('mydb', '1.0', '', 1)
affects: >=1.0.0
deprecatedThe 'success' callback in openDatabase is deprecated. Use Promises or async/await.
fix
Use openDatabase('mydb', '1.0', '', 1).catch(err => console.error(err))
affects: >=3.0.0
gotchaOn Android, the database file is created in a default location. Using relative paths may cause unexpected behaviors.
fix
Use absolute paths if you need custom location; otherwise rely on default.
affects: >=0.1.0
breakingIn version 3.0.0, the package dropped support for React Native < 0.60 and switched to autolinking. Manual linking is no longer required but pod install is needed for iOS.
fix
Update React Native to 0.60+ and run pod install in ios/ directory.
affects: >=3.0.0
gotchaForeign key constraints are enabled automatically on database initialization, which may affect existing schemas.
fix
Ensure your app does not rely on foreign keys being off by default.
affects: >=0.8.0
Errors
Common errors & fixes
Error: Cannot find module 'react-native-sqlite-2'
Package not installed or not linked correctly (pre-autolinking).
fix
Run npm install react-native-sqlite-2 --save and for RN < 0.60 run react-native link react-native-sqlite-2
TypeError: SQLite.openDatabase is not a function
Incorrect import; default import used incorrectly.
fix
Use default import: import SQLite from 'react-native-sqlite-2'
The database has been closed
Attempting to execute SQL on a database after it has been closed or after a transaction has ended.
fix
Manage database lifecycle properly; use a single instance and avoid closing while transactions are pending.
SQLite3: Error while executing SQL: near "?": syntax error
Using parameter placeholders incorrectly (e.g., using ? for identifiers or wrong syntax).
fix
Use ? placeholders only for values, not for table/column names.
Upgrade
Version history
3.6.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Meta
1
Resources
react-native-sqlite-2 — npm install react-native-sqlite-2 · libregistry