mysql
Advanced tools
Comparing version 2.0.0-alpha6 to 2.0.0-alpha7
@@ -5,2 +5,4 @@ var Connection = require('./lib/Connection'); | ||
var SqlString = require('./lib/protocol/SqlString'); | ||
var Pool = require('./lib/Pool'); | ||
var PoolConfig = require('./lib/PoolConfig'); | ||
@@ -11,2 +13,6 @@ exports.createConnection = function(config) { | ||
exports.createPool = function(config) { | ||
return new Pool({config: new PoolConfig(config)}); | ||
}; | ||
exports.createQuery = Connection.createQuery; | ||
@@ -13,0 +19,0 @@ |
var Net = require('net'); | ||
var ConnectionConfig = require('./ConnectionConfig'); | ||
var Pool = require('./Pool'); | ||
var Protocol = require('./protocol/Protocol'); | ||
@@ -4,0 +5,0 @@ var SqlString = require('./protocol/SqlString'); |
@@ -23,2 +23,3 @@ var urlParse = require('url').parse; | ||
this.queryFormat = options.queryFormat; | ||
this.pool = options.pool || undefined; | ||
this.typeCast = (options.typeCast === undefined) | ||
@@ -25,0 +26,0 @@ ? true |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 100% MIT licensed.", | ||
"version": "2.0.0-alpha6", | ||
"version": "2.0.0-alpha7", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "url": "" |
@@ -8,3 +8,3 @@ # node-mysql | ||
```bash | ||
npm install mysql@2.0.0-alpha6 | ||
npm install mysql@2.0.0-alpha7 | ||
``` | ||
@@ -193,2 +193,62 @@ | ||
## Pooling connections | ||
Connections can be pooled to ease sharing a single connection, or managing | ||
multiple connections. | ||
```js | ||
var mysql = require('mysql'); | ||
var pool = mysql.createPool({ | ||
host : 'example.org', | ||
user : 'bob', | ||
password : 'secret' | ||
}); | ||
pool.getConnection(function(err, connection) { | ||
// connected! (unless `err` is set) | ||
}); | ||
``` | ||
When you are done with a connection, just call `connection.end()` and the | ||
connection will return to the pool, ready to be used again by someone else. | ||
```js | ||
var mysql = require('mysql'); | ||
var pool = mysql.createPool(...); | ||
pool.getConnection(function(err, connection) { | ||
// Use the connection | ||
connection.query( 'SELECT something FROM sometable', function(err, rows) { | ||
// And done with the connection. | ||
connection.end(); | ||
// Don't use the connection here, it has been returned to the pool. | ||
}); | ||
}); | ||
``` | ||
If you would like to close the connection and remove it from the pool, use | ||
`connection.destroy()` instead. The pool will create a new connection the next | ||
time one is needed. | ||
Connections are lazily created by the pool. If you configure the pool to allow | ||
up to 100 connections, but only ever use 5 simultaneously, only 5 connections | ||
will be made. Connections are also cycled round-robin style, with connections | ||
being taken from the top of the pool and returning to the bottom. | ||
## Pool options | ||
Pools accept all the same options as a connection. When creating a new | ||
connection, the options are simply passed to the connection constructor. In | ||
addition to those options pools accept a few extras: | ||
* `createConnection`: The function to use to create the connection. (Default: | ||
`mysql.createConnection`) | ||
* `waitForConnections`: Determines the pool's action when no connections are | ||
available and the limit has been reached. If `true`, the pool will queue the | ||
connection request and call it when one becomes available. If `false`, the | ||
pool will immediately call back with an error. (Default: `true`) | ||
* `connectionLimit`: The maximum number of connections to create at once. | ||
(Default: `10`) | ||
## Switching users / altering connection state | ||
@@ -254,4 +314,4 @@ | ||
This logic will also be part of connection pool support once I add that to this | ||
library. | ||
With Pool, disconnected connections will be removed from the pool freeing up | ||
space for a new connection to be created on the next getConnection call. | ||
@@ -389,9 +449,5 @@ ## Escaping query values | ||
The MySQL protocol is sequential, this means that you need multiple connections | ||
to execute queries in parallel. Future version of this module may ship with a | ||
connection pool implementation, but for now you have to figure out how to | ||
manage multiple connections yourself if you want to execute queries in | ||
parallel. | ||
to execute queries in parallel. You can use a Pool to manage connections, one | ||
simple approach is to create one connection per incoming http request. | ||
One simple approach is to create one connection per incoming http request. | ||
## Streaming query rows | ||
@@ -769,4 +825,3 @@ | ||
* setTimeout() for Connection / Query | ||
* connection pooling | ||
* Support for encodings other than UTF-8 / ASCII | ||
* API support for transactions, similar to [php](http://www.php.net/manual/en/mysqli.quickstart.transactions.php) |
@@ -28,19 +28,12 @@ var common = exports; | ||
common.createConnection = function(config) { | ||
if (common.isTravis()) { | ||
// see: http://about.travis-ci.org/docs/user/database-setup/ | ||
config = _.extend({ | ||
user: 'root' | ||
}, config); | ||
} else { | ||
config = _.extend({ | ||
host : process.env.MYSQL_HOST, | ||
port : process.env.MYSQL_PORT, | ||
user : process.env.MYSQL_USER, | ||
password : process.env.MYSQL_PASSWORD | ||
}, config); | ||
} | ||
config = mergeTestConfig(config); | ||
return Mysql.createConnection(config); | ||
}; | ||
common.createPool = function(config) { | ||
config = mergeTestConfig(config); | ||
config.createConnection = common.createConnection; | ||
return Mysql.createPool(config); | ||
}; | ||
common.createFakeServer = function(options) { | ||
@@ -57,1 +50,18 @@ return new FakeServer(_.extend({}, options)); | ||
} | ||
function mergeTestConfig(config) { | ||
if (common.isTravis()) { | ||
// see: http://about.travis-ci.org/docs/user/database-setup/ | ||
config = _.extend({ | ||
user: 'root' | ||
}, config); | ||
} else { | ||
config = _.extend({ | ||
host : process.env.MYSQL_HOST, | ||
port : process.env.MYSQL_PORT, | ||
user : process.env.MYSQL_USER, | ||
password : process.env.MYSQL_PASSWORD | ||
}, config); | ||
} | ||
return config; | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
222987
125
5291
823
26
4