New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mysql2-promise

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql2-promise

Small promises wrapper for mysql2.

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.3K
increased by1.47%
Maintainers
1
Weekly downloads
 
Created
Source

mysql-promise

Small promises wrapper for mysql2, it's forked and compatible with mysql-promise.

build status NPM NPM

Installation

This module is installed via npm:

$ npm install mysql2-promise --save

Example Usage of query

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);
});


Example Usage of execute

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);
});

Example usage of namedPlaceholders

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);
});

Credits

This library is forked from mysql-promise

Keywords

FAQs

Package last updated on 28 Aug 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc