Registry / database / knex-react-native-sqlite

knex-react-native-sqlite

JSON →
library1.2.1jsnpmunverified

A SQLite3 dialect for Knex.js designed specifically for React Native via react-native-sqlite-storage. Version 1.2.1 provides a webpack-built, React Native-friendly version of Knex that avoids direct Node.js dependencies. It ships TypeScript types and requires react-native-sqlite-storage >=5.0.0 <7. Key differentiator: it generates a custom Knex bundle to work around React Native's lack of Node built-ins, unlike alternatives that require manual polyfilling. Active maintenance with monthly releases.

npm install knex-react-native-sqlite
INSTALL
IMPORT
SIG · KNEX-REACT-NATIVE-
K
knex-react-native-sqlite
databasejavascriptv1.2.1
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.

knex
import { knex } from 'knex-react-native-sqlite'
import knex from 'knex'
Must import from this package, not Knex directly, to get the React Native-compatible build.
RNSqliteDialect
import { RNSqliteDialect } from 'knex-react-native-sqlite'
import { SQLiteDialect } from 'knex-react-native-sqlite'
The dialect export is specifically named RNSqliteDialect. Using Knex's built-in SQLite dialect will fail due to Node.js dependencies.
knex and RNSqliteDialect
import { knex, RNSqliteDialect } from 'knex-react-native-sqlite'
const knex = require('knex').default; const RNSqliteDialect = require('knex-react-native-sqlite').RNSqliteDialect
CommonJS require may not work due to webpack bundling; ESM imports are recommended.

Demonstrates creating a SQLite database instance, creating a table, inserting a row, and querying data.

import { knex, RNSqliteDialect } from 'knex-react-native-sqlite'; const db = knex({ client: RNSqliteDialect, connection: { name: 'myapp.db', location: 'default', }, }); async function init() { const exists = await db.schema.hasTable('users'); if (!exists) { await db.schema.createTable('users', (table) => { table.increments('id'); table.string('name'); table.integer('age'); }); } const newUser = { name: 'Jane', age: 30 }; const [id] = await db('users').insert(newUser); console.log('Inserted user id:', id); const users = await db('users').select('*'); console.log(users); await db.destroy(); } init().catch(console.error);
Debug
Known issues
breakingreact-native-sqlite-storage v7+ is not supported. Only versions >=5.0.0 and <7 are compatible.
fix
Ensure react-native-sqlite-storage is installed at version 5.x or 6.x (e.g., npm install react-native-sqlite-storage@5)
affects: >=1.2.0
deprecatedThe package does not support Knex v3.x. It bundles an older webpack build of Knex which may not align with latest Knex versions.
fix
Check bundled Knex version; consider alternative if you need Knex v3 features.
affects: >=1.0.0
gotchaUsing require() syntax may fail because the package exports a webpack bundle; ESM import is required.
fix
Use ES module imports: import { knex, RNSqliteDialect } from 'knex-react-native-sqlite'
affects: >=1.0.0
gotchaThe connection object properties (name, location) are passed directly to react-native-sqlite-storage's openDatabase. Incorrect options may cause silent failures.
fix
Refer to react-native-sqlite-storage documentation for valid connection options.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'knex'
Importing from 'knex' instead of 'knex-react-native-sqlite'.
fix
Replace import { knex } from 'knex' with import { knex } from 'knex-react-native-sqlite'
Error: Dialect 'sqlite3' not supported
Using client: 'sqlite3' instead of client: RNSqliteDialect.
fix
Use the imported dialect: client: RNSqliteDialect
TypeError: Cannot read properties of undefined (reading 'create')
Missing or incompatible react-native-sqlite-storage peer dependency.
fix
Install react-native-sqlite-storage@5 or @6: npm install react-native-sqlite-storage@5
Error: WebSocket connection failed: connection is closed
Using this package in a non-React Native environment (e.g., web browser).
fix
This package is only for React Native; use sqlite3 or better-sqlite3 for Node.js.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
react-native-sqlite-storagerequiredRequired peer dependency for SQLite access on React Native. Must be >=5.0.0 and <7.
Agent activity
5 hits · last 30 days
node
4
Resources
knex-react-native-sqlite — npm install knex-react-native-sqlite · libregistry