Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mysql-promise

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-promise - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

test/index.test.js

24

index.js

@@ -5,10 +5,14 @@ 'use strict';

mysql = require('mysql'),
pool = null;
instances = {};
function DB() {
this.pool = null;
}
/**
* Setup the Database connection pool
* Setup the Database connection pool for this instance
* @param {Object} config
*/
exports.configure = function (config) {
pool = mysql.createPool(config);
DB.prototype.configure = function (config) {
this.pool = mysql.createPool(config);
};

@@ -22,7 +26,7 @@

*/
exports.query = function (query, params) {
DB.prototype.query = function (query, params) {
var defer = Promise.defer();
params = params || {};
pool.getConnection(function (err, con) {
this.pool.getConnection(function (err, con) {
if (err) {

@@ -42,1 +46,9 @@ return defer.reject(err);

};
module.exports = function (name) {
name = name || '_default_';
if (!instances[name]) {
instances[name] = new DB();
}
return instances[name];
};
{
"name": "mysql-promise",
"version": "0.2.0",
"version": "1.0.0",
"description": "Small wrapper for mysql that use promises.",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/jshint index.js"
"test": "./node_modules/.bin/jshint index.js && ./node_modules/.bin/mocha test/*.test.js"
},

@@ -23,8 +23,10 @@ "repository": {

"dependencies": {
"mysql": "~2.0.0-alpha9",
"bluebird": "~1.0.0"
"mysql": "^2.0.1",
"bluebird": "^1.0.7"
},
"devDependencies": {
"jshint": "~2.1.10"
"jshint": "~2.1.10",
"should": "^3.1.3",
"mocha": "^1.17.1"
}
}

@@ -18,3 +18,4 @@ # mysql-promise

``` js
var db = require('mysql-promise');
var db = require('mysql-promise')();
db.configure({

@@ -32,2 +33,17 @@ "host": "localhost",

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