Skip to content

martinj/node-mysql-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mysql-promise

Small wrapper for mysql and mysql2 that use promises.

Build Status

Installation

This module is installed via npm:

$ npm install mysql-promise

Example Usage

var db = require('mysql-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('Loook 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');

//check if has already been configured
if (!db2.isConfigured()) {
	db2.configure({
		"host": "localhost",
		"user": "foo",
		"password": "bar",
		"database": "another-db"
	});
}

db2.query('SELECT * FROM users').spread(function (users) {
	console.log('Hello users', users);
});

Using mysql2

var mysql2 = require('mysql2');
var db = require('mysql-promise')();
var opts = {
	"host": "localhost",
	"user": "foo",
	"password": "bar",
	"database": "db"
};

db.configure(opts, require('mysql2'));

Use different promise implementation

var db = require('mysql-promise')();

db.configure(dbOpts, null, PromiseImpl);

About

Small wrapper for mysql that use promises.

Resources

Stars

Watchers

Forks

Packages

No packages published