database-js2 is a JavaScript library providing a common, promise-based interface for accessing various database systems, inspired by Java's JDBC (Java Database Connectivity) pattern. It allows developers to interact with different databases (e.g., SQLite, MySQL, PostgreSQL) and even non-SQL data sources like Firebase, INI files, or Excel/CSV sheets using a unified API and connection string format. The library supports built-in prepared statements and integrates well with ES7 async/await syntax via Promises. This specific package, `database-js2`, is currently at version 1.4.2 but has been officially deprecated. All new feature development has ceased for this package, and future development and bug fixes are being published under the new `database-js` package (v3.x and above), which has claimed the original `database-js` npm package name.
npm install database-js2Verified import paths — ran on the pinned version, not inferred.
This example demonstrates how to establish a connection to an SQLite database, create a table, insert data using prepared statements, query specific data, and properly close the connection using async/await.
Migrate your projects to use the `database-js` package (npm install database-js) and update your code to its API, which is largely compatible but may have minor breaking changes in newer major versions.
Use `const MySymbol = require('database-js2').MySymbol;` for all imports. For new projects, consider migrating to the `database-js` package which offers better ESM support.Before establishing a connection, ensure the corresponding driver package for your database type is installed via npm. For example, for `sqlite:///`, ensure `database-js-sqlite` is installed.
Install the required driver package for your database type: `npm install database-js-sqlite` (for SQLite), `npm install database-js-mysql` (for MySQL), etc.
Ensure you are using `const Connection = require('database-js2').Connection;` for CommonJS environments.Always chain a `.catch()` method to your promise-based database operations, or use `try...catch` blocks with `async/await` to handle potential errors gracefully.