Registry / database / database-js-mysql2

database-js-mysql2

JSON →
library1.0.0jsnpmunverified

database-js-mysql2 is an adapter that provides a MySQL2 driver for the database-js abstraction layer. It wraps the `mysql2` package, allowing `database-js` connections to interact with MySQL databases using the `mysql2://` connection string protocol. Additionally, it offers a standalone, Promise-based API for `mysql2` directly, which can be useful for those who want a simple Promise interface without the full `database-js` ecosystem. The package is currently at version 1.0.0. Given its last commit in 2018, its release cadence is effectively ceased, and it should be considered abandoned, potentially lacking updates for modern Node.js versions or security patches. Its primary differentiator is its integration with `database-js` and its out-of-the-box Promise support for `mysql2`.

npm install database-js-mysql2
INSTALL
IMPORT
SIG · DATABASE-JS-MYSQL2
D
database-js-mysql2
databasejavascriptv1.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

mysql
✓ const mysql = require('database-js-mysql2');
✗ import mysql from 'database-js-mysql2';
The package primarily targets CommonJS environments. ESM imports are not directly supported.
Connection
✓ const { Connection } = require('database-js');
✗ import { Connection } from 'database-js';
When used with `database-js`, the Connection class is imported from the parent `database-js` package, which also targets CommonJS.
Database
✓ const Database = require('database-js').Connection;
✗ import Database from 'database-js/Connection';
Common aliasing pattern for the `database-js` Connection class in CommonJS.

Demonstrates connecting to MySQL using `database-js` with the `database-js-mysql2` driver, including parameterized queries and SSL configuration via connection string. Uses environment variables for credentials.

const Database = require('database-js').Connection; const fs = require('fs'); // Dummy 'fs' for example to make it runnable without actual files // In a real scenario, these files would exist on disk. const caCertPath = './path/to/ca.pem'; const keyPath = './path/to/key.pem'; const certPath = './path/to/cert.pem'; // Mock fs.existsSync and fs.readFileSync for demonstration purposes const originalExistsSync = fs.existsSync; const originalReadFileSync = fs.readFileSync; fs.existsSync = (path) => path === caCertPath || path === keyPath || path === certPath; fs.readFileSync = (path) => Buffer.from(`mock_certificate_for_${path}`); (async () => { let connection, statement, rows; const dbUser = process.env.DB_USER ?? 'my_secret_username'; const dbPass = process.env.DB_PASSWORD ?? 'my_secret_password'; const dbHost = process.env.DB_HOST ?? 'localhost'; const dbPort = process.env.DB_PORT ?? 3306; const dbName = process.env.DB_NAME ?? 'my_top_secret_database'; // Example connection string with SSL parameters, ensuring paths are URL-encoded // In a real application, ensure your SSL files are correctly placed and permissions set. const connectionString = `mysql2://${dbUser}:${dbPass}@${dbHost}:${dbPort}/${dbName}?ssl[ca]=${encodeURIComponent(caCertPath)}&ssl[key]=${encodeURIComponent(keyPath)}&ssl[cert]=${encodeURIComponent(certPath)}`; try { connection = new Database(connectionString); statement = await connection.prepareStatement("SELECT ? AS user_name_col, ? AS value_col"); rows = await statement.query('not_so_secret_user', 123); console.log('Query Result:', rows); } catch (error) { console.error('Database Error:', error); } finally { if (connection) { await connection.close(); } } })(); // Restore original fs methods if necessary in a larger application context fs.existsSync = originalExistsSync; fs.readFileSync = originalReadFileSync;
Debug
Known issues
breakingThis project appears to be abandoned, with the last commit in 2018. It is unlikely to receive updates for new Node.js versions, security patches, or compatibility with newer `mysql2` releases, posing potential stability and security risks.
fix
Consider migrating to a actively maintained `database-js` driver if available, or a direct `mysql2` client for more current support.
affects: >=1.0.0
gotchaThe package exclusively uses CommonJS `require()` syntax. It does not natively support ES Modules (`import/export`) and attempting to use them will result in syntax errors or module resolution failures.
fix
Ensure your project or file uses CommonJS `require()` statements for importing `database-js-mysql2` and `database-js`.
affects: >=1.0.0
gotchaSSL certificate files (ca, key, cert) specified in the connection string are read synchronously using `fs.readFileSync`. In high-performance or serverless environments, this synchronous I/O can block the Node.js event loop, potentially impacting application responsiveness during connection setup.
fix
Be aware of the synchronous file access. For critical applications, pre-loading certificates or using an alternative driver that supports asynchronous certificate loading might be preferable if this becomes a performance bottleneck.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'database-js'
The `database-js` core package is not installed, but `database-js-mysql2` expects it when used as a driver.
fix
Install the `database-js` package: `npm install database-js`.
TypeError: Cannot read properties of undefined (reading 'Connection')
Attempting to destructure `Connection` from `require('database-js')` when `database-js` might not be correctly installed or resolved, or `Connection` is not a named export in an unexpected scenario.
fix
Verify `npm list database-js` shows the package, and ensure the import is `const Database = require('database-js').Connection;` if you are using the older `database-js` pattern.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'host' (using password: YES/NO)
Incorrect MySQL username, password, or host settings in the connection string. The database server rejected the authentication attempt.
fix
Double-check your `DB_USER`, `DB_PASSWORD`, `DB_HOST`, and `DB_PORT` environment variables or hardcoded values. Ensure the user has correct privileges for the specified database.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
database-jsoptionalRequired as the core abstraction layer when using this package as a database-js driver.
mysql2requiredThe underlying MySQL client library that this package wraps.
Agent activity
10 hits · last 30 days
node
10
Resources
database-js-mysql2 — npm install database-js-mysql2 · libregistry