mysql-promise
Advanced tools
Comparing version 0.2.0 to 1.0.0
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); | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3723
7
54
1
48
3
+ Addedbignumber.js@9.0.0(transitive)
+ Addedbluebird@1.2.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmysql@2.18.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.7(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsqlstring@2.3.1(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedbignumber.js@1.0.1(transitive)
- Removedbluebird@1.0.8(transitive)
- Removedisarray@0.0.1(transitive)
- Removedmysql@2.0.1(transitive)
- Removedreadable-stream@1.1.14(transitive)
- Removedrequire-all@0.0.3(transitive)
- Removedstring_decoder@0.10.31(transitive)
Updatedbluebird@^1.0.7
Updatedmysql@^2.0.1