{"id":16797,"library":"database-js-sqlite","title":"Database-js SQLite Driver","description":"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.","status":"maintenance","version":"1.3.0","language":"javascript","source_language":"en","source_url":"https://github.com/mlaanderson/database-js-sqlite","tags":["javascript","database-js","sqlite"],"install":[{"cmd":"npm install database-js-sqlite","lang":"bash","label":"npm"},{"cmd":"yarn add database-js-sqlite","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-js-sqlite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core framework required for connection abstraction.","package":"database-js","optional":false},{"reason":"Primary underlying SQLite driver for Node.js environments.","package":"node-sqlite3","optional":false},{"reason":"Alternative SQLite driver for browser environments or where native modules are undesired. Used when 'driver=sql.js' is specified.","package":"sql.js","optional":true}],"imports":[{"note":"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.","wrong":"var Database = require('database-js2').Connection;","symbol":"Connection","correct":"import { Connection } from 'database-js';"},{"note":"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.","wrong":"import { SQLiteConnection } from 'database-js-sqlite';","symbol":"SQLiteConnection","correct":"import SQLiteConnection from 'database-js-sqlite';"},{"note":"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.","wrong":"const Database = require('database-js-sqlite');","symbol":"Database (CJS)","correct":"const { Connection: Database } = require('database-js');"}],"quickstart":{"code":"import { Connection } from 'database-js';\n\n// Ensure database-js-sqlite and node-sqlite3 are installed:\n// npm install database-js database-js-sqlite node-sqlite3\n\n(async () => {\n    let connection;\n    try {\n        // Connect to an SQLite database file. It will be created if it doesn't exist.\n        connection = new Connection('sqlite:///test.sqlite');\n        console.log('Database connection established.');\n\n        // Create a table if it doesn't exist\n        await connection.query(\n            \"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, user_name TEXT, email TEXT);\"\n        );\n        console.log('Table 'users' ensured.');\n\n        // Insert data using a prepared statement\n        let statement = await connection.prepareStatement(\"INSERT INTO users (user_name, email) VALUES (?, ?)\");\n        await statement.query('john_doe', 'john@example.com');\n        await statement.query('jane_smith', 'jane@example.com');\n        console.log('Users inserted.');\n\n        // Query data using a prepared statement\n        statement = await connection.prepareStatement(\"SELECT * FROM users WHERE user_name = ?\");\n        const rows = await statement.query('john_doe');\n        console.log('Query result for john_doe:', rows);\n\n    } catch (error) {\n        console.error('Database operation failed:', error);\n    } finally {\n        if (connection) {\n            await connection.close();\n            console.log('Database connection closed.');\n        }\n    }\n})();","lang":"javascript","description":"Demonstrates connecting to an SQLite database, creating a table, inserting data, and querying using prepared statements with the `database-js` API."},"warnings":[{"fix":"Always use `require('database-js')` or `import { Connection } from 'database-js'` for the core library.","message":"The 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.","severity":"gotcha","affected_versions":"<=1.3.0"},{"fix":"Thoroughly test compatibility with your target Node.js version. Consider alternative, more actively maintained SQLite drivers if encountering issues with newer environments.","message":"This 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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');`","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change your import statement from `require('database-js2')` to `require('database-js')` or `import { Connection } from 'database-js';`.","cause":"The core `database-js` library was incorrectly referred to as `database-js2` in older documentation or examples.","error":"Error: Cannot find module 'database-js2'"},{"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`.","cause":"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`.","error":"Error: NAPI_VERSION_MISMATCH (node-sqlite3)"},{"fix":"Ensure `database-js-sqlite` is listed in your dependencies and properly installed: `npm install database-js-sqlite`.","cause":"The `database-js-sqlite` package, which registers the 'sqlite' driver for `database-js`, is not installed or accessible in your project.","error":"Error: A database-js driver for 'sqlite' could not be found."}],"ecosystem":"npm","meta_description":null}