database-js-mysql

1.1.3 · abandoned · verified Wed Apr 22

database-js-mysql is a wrapper for the `mysql` package, primarily designed to integrate MySQL functionality into applications using the `database-js` abstraction layer. It provides a promise-based API for handling MySQL connections and executing queries, offering both standalone usage and integration with the `database-js` Connection class. As of its latest stable version, 1.1.3, released over seven years ago, the package relies on CommonJS modules and older JavaScript syntax. Its key differentiator was providing a consistent `database-js` interface for MySQL, including support for parameterized queries and streamlined connection management, which was useful for abstracting database interactions in its ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to establish a standalone MySQL connection using `database-js-mysql` and execute a simple query. It uses environment variables for sensitive credentials and handles connection opening, querying, and closing with async/await.

const mysql = require('database-js-mysql');

(async () => {
    let connection, rows;
    try {
        connection = mysql.open({
            Hostname: process.env.DB_HOST ?? 'localhost',
            Port: parseInt(process.env.DB_PORT ?? '3306', 10),
            Username: process.env.DB_USERNAME ?? 'my_secret_username',
            Password: process.env.DB_PASSWORD ?? 'my_secret_password',
            Database: process.env.DB_DATABASE ?? 'my_top_secret_database'
        });

        // Ensure the connection is established before querying
        rows = await connection.query("SELECT * FROM tablea WHERE user_name = 'not_so_secret_user'");
        console.log('Query result:', rows);
    } catch (error) {
        console.error('Database operation failed:', error);
    } finally {
        if (connection) {
            await connection.close();
            console.log('Connection closed.');
        }
    }
})();

view raw JSON →