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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Connection
✓ import { Connection } from 'database-js2';
✗ import { Connection } from 'database-js';
While `database-js-json` enables JSON support, the primary `Connection` class is imported from its peer dependency `database-js2`. This package is a driver for `database-js2`.
Connection
✓ const { Connection } = require('database-js2');
✗ var Connection = require('database-js').Connection;
For CommonJS environments, `Connection` is imported from `database-js2`. The quickstart initially shows `var Connection = require('database-js2').Connection;`, but modern practice favors `const` and destructuring.
(Side Effect)
✓ require('database-js-json');
✗ import { JsonConnection } from 'database-js-json';
Installing and `require`ing `database-js-json` (even without assigning its exports to a variable) registers the `json://` protocol with `database-js2`. This package is primarily a driver for its side-effect registration, and direct symbol imports from `database-js-json` are uncommon for general usage.
Demonstrates connecting to a JSON file, querying data with a prepared statement, and closing the connection, including setup for a dummy JSON file.
const { Connection } = require('database-js2');
require('database-js-json'); // Ensure the driver is loaded and registers itself
(async () => {
// Create a dummy JSON file for demonstration
require('fs').writeFileSync('test.json', JSON.stringify([
{ "id": 1, "user_name": "alpha_user", "email": "alpha@example.com" },
{ "id": 2, "user_name": "beta_user", "email": "beta@example.com" },
{ "id": 3, "user_name": "not_so_secret_user", "email": "secret@example.com" }
], null, 2));
const connection = new Connection( 'json:///test.json' );
try {
console.log('Connecting to json:///test.json...');
// Query with a prepared statement
let statement = await connection.prepareStatement("SELECT * WHERE user_name = ?");
let rows = await statement.query('not_so_secret_user');
console.log('Query result for "not_so_secret_user":', rows);
console.log(`Found ${rows.length} user(s) matching the criteria.`);
// Fetch all data
let allRows = await connection.query("SELECT id, user_name FROM * LIMIT 2");
console.log('First 2 entries:', allRows);
} catch (error) {
console.error('An error occurred:', error);
} finally {
await connection.close();
console.log('Connection closed.');
// Clean up the dummy file
require('fs').unlinkSync('test.json');
}
} )();
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open 'test.json'
The specified JSON file path is incorrect or the file does not exist, and the `checkOnConnect` option is implicitly or explicitly set to `true`.
fixVerify the JSON file exists at the specified path relative to your application's execution context, or append `?checkOnConnect=false` to the connection string to bypass the check.
Error: Protocol 'json' not found
The `database-js-json` driver has not been properly loaded or required, thus `database-js2` is unaware of how to handle the `json://` connection protocol.
fixEnsure `database-js-json` is installed (`npm install database-js-json`) and explicitly required or imported in your application's entry point: `require('database-js-json');`. Error: SQL parse error: Unexpected token: <token>
The SQL-like query provided is syntactically incorrect or uses features not supported by the underlying `jl-sql-api` parser.
fixReview the query syntax against the `jl-sql-api` documentation for supported grammar and operations. Ensure proper quotation for string literals and valid identifiers.
Audit
Dependencies
database-js2requiredPeer dependency for the core Connection class and to register the 'json://' protocol driver.
jl-sql-apirequiredCore dependency providing the SQL-like query parsing and execution against JSON data.