{"library":"promise-mysql","title":"Promise MySQL Wrapper","description":"promise-mysql is a Node.js library that provides a promise-based wrapper around the `mysqljs/mysql` driver. It leverages the Bluebird promise library to transform the traditional callback-based API of `node-mysql` into an asynchronous, promise-returning interface, supporting `async/await` patterns. Currently at version 5.2.0, this package has not seen a major release in over four years, with its core dependency, `mysqljs/mysql`, also being largely unmaintained. While it differentiates itself by offering promise support for the widely used `node-mysql` driver, modern applications might opt for `mysql2/promise` for native promise support and better performance and features. Its release cadence has been infrequent, indicating a mature but largely static project.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install promise-mysql"],"cli":null},"imports":["import mysql from 'promise-mysql';\nconst connection = await mysql.createConnection(options);","const mysql = require('promise-mysql');\nconst pool = await mysql.createPool(options);","const [rows, fields] = await connection.query('SELECT * FROM users');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const mysql = require('promise-mysql');\n\nasync function runDbOperations() {\n  let connection; // Declare connection outside try block for finally\n  try {\n    connection = await mysql.createConnection({\n      host: process.env.DB_HOST ?? 'localhost',\n      user: process.env.DB_USER ?? 'root',\n      password: process.env.DB_PASSWORD ?? 'password',\n      database: process.env.DB_NAME ?? 'test_db'\n    });\n\n    console.log('Database connected successfully!');\n\n    // Create a table if it doesn't exist\n    await connection.query(`\n      CREATE TABLE IF NOT EXISTS users (\n        id INT AUTO_INCREMENT PRIMARY KEY,\n        name VARCHAR(255) NOT NULL,\n        email VARCHAR(255) UNIQUE NOT NULL\n      );\n    `);\n    console.log('Users table ensured.');\n\n    // Insert a new user\n    const insertResult = await connection.query('INSERT INTO users (name, email) VALUES (?, ?)', ['Alice', 'alice@example.com']);\n    console.log('Inserted user:', insertResult.insertId);\n\n    // Select all users\n    const users = await connection.query('SELECT * FROM users');\n    console.log('Users:', users);\n\n    // Clean up (optional: delete the user for idempotency)\n    await connection.query('DELETE FROM users WHERE email = ?', ['alice@example.com']);\n    console.log('Cleaned up user.');\n\n  } catch (err) {\n    console.error('Database operation failed:', err);\n  } finally {\n    if (connection) {\n      await connection.end();\n      console.log('Connection closed.');\n    }\n  }\n}\n\nrunDbOperations();\n","lang":"javascript","description":"Demonstrates connecting to a MySQL database, performing DDL and DML operations (create table, insert, select, delete), and properly closing the connection using async/await with promise-mysql. Environment variables are used for credentials for security.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}