Registry / database / any-sqlite

any-sqlite

JSON →
library1.0.4jsnpmunverified

A unified SQLite interface for Node.js and React Native, allowing the same codebase to run SQLite queries on both platforms. Current stable version is 1.0.4, with ongoing development (monthly releases). It provides simple execute, batch, and query methods, with built-in TypeScript types. Unlike other adapters (like react-native-sqlite-storage), it abstracts away platform-specific implementations and provides a consistent Promise-based API. Note: browser support is not yet implemented.

npm install any-sqlite
INSTALL
IMPORT
SIG · ANY-SQLITE
A
any-sqlite
databasejavascriptv1.0.4
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.

open
import { open } from 'any-sqlite'
import open from 'any-sqlite'
Named import, not default. The package exports 'open' as a named export.
open
const { open } = require('any-sqlite')
const anySqlite = require('any-sqlite')
CommonJS requires destructuring to get 'open'.
SQLiteDatabase type
import type { SQLiteDatabase } from 'any-sqlite'
import { SQLiteDatabase } from 'any-sqlite'
Only the type can be imported using 'import type' for TypeScript users.

Opens a SQLite database, creates a table, inserts a row, and queries all rows.

import { open } from 'any-sqlite' async function main() { const db = await open('example.db') await db.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)') await db.execute('INSERT INTO users (name) VALUES (?)', ['Alice']) const rows = await db.execute('SELECT * FROM users') console.log(rows) await db.close() } main().catch(console.error)
Debug
Known issues
gotchaThe package may have different behavior on React Native vs Node.js due to underlying SQLite implementations (react-native-sqlite-storage vs better-sqlite3). For example, large numeric values may lose precision on React Native.
fix
Test your queries on both platforms and avoid relying on edge cases.
affects: >=1.0.0
gotchav1.0.4 is still in early development; API might change without major version bump.
fix
Expect potential breaking changes and pin version or check changelog before upgrading.
affects: >=1.0.0 <2.0.0
deprecatedNo deprecation warnings so far.
affects: >=1.0.0
breakingNo known breaking changes at this version.
affects: >=1.0.0
gotchaThe 'batch' method expects an array of [sql, params] tuples, but params can be omitted. If you pass a single array, it will be interpreted as the sql of the first query, leading to errors.
fix
Ensure each element in the batch array is an array, e.g., [['INSERT INTO t VALUES (?)', [1]], ['INSERT INTO t VALUES (?)', [2]]].
affects: >=1.0.0
gotchaThe 'execute' method returns an object with 'rows' and 'columns' on React Native, but on Node.js it returns rows directly from better-sqlite3. Inconsistent return type.
fix
Check the return value format across platforms or use a wrapper to normalize.
affects: >=1.0.0
gotchaBrowser support is not implemented; using in a web environment will throw an error.
fix
Do not use this package in browser environments; consider sql.js or sqlite3.js instead.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'better-sqlite3'
Missing optional dependency better-sqlite3 when running in Node.js environment.
fix
Install better-sqlite3: npm install better-sqlite3
TypeError: db.execute is not a function
The import was incorrect (e.g., default import instead of named import).
fix
Use import { open } from 'any-sqlite' and call open() to get db.
Error: React Native SQLite module is not installed
Using the package in a React Native app without installing react-native-sqlite-storage.
fix
Install react-native-sqlite-storage: npm install react-native-sqlite-storage
Error: [react-native-sqlite-storage] Cannot read property 'executeSql' of undefined
The react-native-sqlite-storage native module is not linked correctly in React Native.
fix
Link the native module: npx react-native link react-native-sqlite-storage
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
better-sqlite3requiredUsed as the Node.js backend for SQLite access.
react-native-sqlite-storageoptionalUsed as the React Native backend for SQLite access.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
any-sqlite — npm install any-sqlite · libregistry