Registry / database / database-js-sqlite

database-js-sqlite

JSON →
library1.3.0jsnpmunverified

database-js-sqlite serves as a wrapper for the `node-sqlite3` package, providing SQLite database connectivity for applications utilizing the `database-js` framework. It enables a consistent API for interacting with SQLite databases, including support for prepared statements and async/await operations. Additionally, it offers an alternative driver option for `sql.js` for browser-compatible SQLite usage. The current stable version is 1.3.0, released in 2018. Given the lack of recent updates, the package appears to be in a maintenance or effectively abandoned state, meaning release cadence is irregular or ceased, and compatibility with very recent Node.js versions or security patches might be a concern. Its primary differentiator is its integration within the `database-js` ecosystem, providing a unified interface across different database types.

npm install database-js-sqlite
INSTALL
IMPORT
SIG · DATABASE-JS-SQLITE
D
database-js-sqlite
databasejavascriptv1.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

Connection
import { Connection } from 'database-js';
var Database = require('database-js2').Connection;
While the README historically showed `database-js2`, the correct package name for the core framework is `database-js`. This is the main class used to establish database connections after `database-js-sqlite` is installed and registers its driver.
SQLiteConnection
import SQLiteConnection from 'database-js-sqlite';
import { SQLiteConnection } from 'database-js-sqlite';
This package exports its `SQLiteConnection` as a default export, though typical usage with `database-js` involves letting `database-js` auto-discover the driver via the connection string rather than direct instantiation.
Database (CJS)
const { Connection: Database } = require('database-js');
const Database = require('database-js-sqlite');
For CommonJS environments, `Connection` is destructured from `database-js`. While `database-js-sqlite` exports `SQLiteConnection` as a default, the quickstart's `new Database(...)` refers to the core `Connection` object.

Demonstrates connecting to an SQLite database, creating a table, inserting data, and querying using prepared statements with the `database-js` API.

import { Connection } from 'database-js'; // Ensure database-js-sqlite and node-sqlite3 are installed: // npm install database-js database-js-sqlite node-sqlite3 (async () => { let connection; try { // Connect to an SQLite database file. It will be created if it doesn't exist. connection = new Connection('sqlite:///test.sqlite'); console.log('Database connection established.'); // Create a table if it doesn't exist await connection.query( "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, user_name TEXT, email TEXT);" ); console.log('Table 'users' ensured.'); // Insert data using a prepared statement let statement = await connection.prepareStatement("INSERT INTO users (user_name, email) VALUES (?, ?)"); await statement.query('john_doe', 'john@example.com'); await statement.query('jane_smith', 'jane@example.com'); console.log('Users inserted.'); // Query data using a prepared statement statement = await connection.prepareStatement("SELECT * FROM users WHERE user_name = ?"); const rows = await statement.query('john_doe'); console.log('Query result for john_doe:', rows); } catch (error) { console.error('Database operation failed:', error); } finally { if (connection) { await connection.close(); console.log('Database connection closed.'); } } })();
Debug
Known issues
gotchaThe README and examples historically referenced `database-js2`. The correct package name for the core library is `database-js`. Using `database-js2` will result in a 'Cannot find module' error.
fix
Always use `require('database-js')` or `import { Connection } from 'database-js'` for the core library.
affects: <=1.3.0
breakingThis package, and its core dependency `database-js`, have not seen significant updates since 2018-2019. This means it may not be compatible with newer Node.js versions (e.g., > v16) or may lack support for modern JavaScript features or API changes.
fix
Thoroughly test compatibility with your target Node.js version. Consider alternative, more actively maintained SQLite drivers if encountering issues with newer environments.
affects: >=1.0.0
gotchaThe underlying `node-sqlite3` package is a native module, which can cause installation issues (e.g., `node-gyp` errors) if build tools are not properly configured on your system or if prebuilt binaries are unavailable for your specific OS/Node.js architecture.
fix
Ensure you have Python 2.x/3.x, `make` (Linux/macOS) or Visual Studio Build Tools (Windows) installed. Refer to `node-sqlite3` documentation for troubleshooting native module compilation errors. Consider using the `sql.js` driver option for purely JavaScript environments.
affects: >=1.0.0
gotchaWhen specifying the `sql.js` driver, ensure `sql.js` is installed as a dependency. Without it, the connection attempt will fail when `driver=sql.js` is used.
fix
Install `sql.js` (e.g., `npm install sql.js`) if you intend to use it as the SQLite driver: `connection = new Connection('sqlite:///test.sqlite?driver=sql.js');`
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'database-js2'
The core `database-js` library was incorrectly referred to as `database-js2` in older documentation or examples.
fix
Change your import statement from `require('database-js2')` to `require('database-js')` or `import { Connection } from 'database-js';`.
Error: NAPI_VERSION_MISMATCH (node-sqlite3)
The native `node-sqlite3` module was compiled against a different Node.js N-API version than the one currently running, often due to Node.js version changes or corrupted `node_modules`.
fix
Delete `node_modules` and `package-lock.json`, then reinstall: `rm -rf node_modules package-lock.json && npm install`. If issues persist, ensure `node-gyp` is configured correctly or try rebuilding `node-sqlite3` specifically using `npm rebuild node-sqlite3`.
Error: A database-js driver for 'sqlite' could not be found.
The `database-js-sqlite` package, which registers the 'sqlite' driver for `database-js`, is not installed or accessible in your project.
fix
Ensure `database-js-sqlite` is listed in your dependencies and properly installed: `npm install database-js-sqlite`.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
database-jsrequiredCore framework required for connection abstraction.
node-sqlite3requiredPrimary underlying SQLite driver for Node.js environments.
sql.jsoptionalAlternative SQLite driver for browser environments or where native modules are undesired. Used when 'driver=sql.js' is specified.
Agent activity
4 hits · last 30 days
node
4
Resources
database-js-sqlite — npm install database-js-sqlite · libregistry