
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
mysql2-promise
Advanced tools
Small promises wrapper for mysql2
,
it's forked and compatible with mysql-promise
.
This module is installed via npm:
$ npm install mysql2-promise --save
var db = require('mysql2-promise')();
db.configure({
"host": "localhost",
"user": "foo",
"password": "bar",
"database": "db"
});
db.query('UPDATE foo SET key = ?', ['value']).then(function () {
return db.query('SELECT * FROM foo');
}).spread(function (rows) {
console.log('Look at all the foo', rows);
});
//using multiple databases, giving it a name 'second-db' so it can be retrieved inside other modules/files.
var db2 = require('mysql-promise')('second-db');
db2.configure({
"host": "localhost",
"user": "foo",
"password": "bar",
"database": "another-db"
});
db2.query('SELECT * FROM users').spread(function (users) {
console.log('Hello users', users);
});
execute()
function is similar to query
but it use prepared-statements.
var db = require('mysql2-promise')();
db.configure({
"host": "localhost",
"user": "foo",
"password": "bar",
"database": "db"
});
db.execute('SELECT * FROM users WHERE LIMIT = ?', [10]).spread(function (users) {
console.log('Hello users', users);
});
var db = require('mysql2-promise')();
db.configure({
"host": "localhost",
"user": "foo",
"password": "bar",
"database": "db"
});
db.pool.on('connection', function (poolConnection) {
poolConnection.config.namedPlaceholders = true;
});
db.execute('SELECT * FROM users WHERE LIMIT = :limit', {limit: 10}).spread(function (users) {
console.log('Hello users', users);
});
This library is forked from mysql-promise
FAQs
Small promises wrapper for mysql2.
The npm package mysql2-promise receives a total of 3,406 weekly downloads. As such, mysql2-promise popularity was classified as popular.
We found that mysql2-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.