Comparing version 0.4.4 to 0.5.0
@@ -177,4 +177,4 @@ # Any-DB API | ||
* `'release'` - emitted whenever `pool.release` is called | ||
* `'query', statement, params` - emitted immediately before `.query` is | ||
called on a connection via `pool.query`. | ||
* `'query', query` - emitted immediately after `.query` is called on a | ||
connection via `pool.query`. The argument is a [query](#query) object. | ||
* `'close'` - emitted when the connection pool has closed all of it | ||
@@ -216,4 +216,4 @@ connections after a call to `close()`. | ||
* `'query', statement, params` - emitted immediately before `.query` is | ||
called on a connection via `transaction.query`. | ||
* `'query', query` - emitted immediately after `.query` is called on a | ||
connection via `tx.query`. The argument is a [query](#query) object. | ||
* `'commit:start'` - Emitted when `.commit()` is called. | ||
@@ -220,0 +220,0 @@ * `'commit:complete'` - Emitted after the transaction has committed. |
@@ -109,4 +109,3 @@ var inherits = require('util').inherits | ||
if (this.log) this.log('starting transaction') | ||
this.emit('query', stmt) | ||
conn.query(stmt, function (err) { | ||
var queryObject = conn.query(stmt, function (err) { | ||
if (err) return self.handleError(err, callback) | ||
@@ -119,2 +118,3 @@ this._connection = conn | ||
}.bind(this)) | ||
this.emit('query', queryObject) | ||
return this | ||
@@ -135,8 +135,4 @@ } | ||
, handleError = this.handleError | ||
, queryAndParams = this._queue.shift() | ||
if (queryAndParams) { | ||
var query = queryAndParams[0] | ||
, stmt = queryAndParams[1] | ||
, params = queryAndParams[2] | ||
, query = this._queue.shift() | ||
if (query) { | ||
// TODO - ask @brianc about changing pg.Query to use '_callback' | ||
@@ -155,3 +151,3 @@ var cbName = query._callback ? '_callback' : 'callback' | ||
} | ||
this.emit('query', stmt, params); | ||
this.emit('query', query); | ||
conn.query(query) | ||
@@ -178,3 +174,3 @@ | ||
if (typeof params == 'function') params = undefined | ||
this._queue.push([q, stmt, params]) | ||
this._queue.push(q) | ||
return q | ||
@@ -188,6 +184,6 @@ } | ||
} | ||
this.emit('query', stmt, params) | ||
var q = this._connection.query(stmt, params, callback) | ||
if (!callback) q.on('error', this.handleError) | ||
return q | ||
var queryObject = this._connection.query(stmt, params, callback) | ||
this.emit('query', queryObject) | ||
if (!callback) queryObject.on('error', this.handleError) | ||
return queryObject | ||
} | ||
@@ -221,4 +217,3 @@ | ||
if (this.state(stmt + ':start', callback)) { | ||
this.emit('query', stmt) | ||
this._connection.query(stmt, function (err) { | ||
var queryObject = this._connection.query(stmt, function (err) { | ||
if (err) return this.handleError(err, callback) | ||
@@ -229,2 +224,3 @@ if (this.state(stmt + ':complete', callback)) { | ||
}.bind(this)) | ||
this.emit('query', queryObject) | ||
} | ||
@@ -231,0 +227,0 @@ return this |
{ | ||
"name": "any-db", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"description": "Database-agnostic connection pooling, querying, and result sets", | ||
@@ -23,3 +23,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"any-db-pool": ">= 0.0.3" | ||
"any-db-pool": ">= 0.0.6" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
@@ -5,8 +5,10 @@ # any-db - a less-opinionated database abstraction layer. | ||
**Heads up!** - v0.4.0 changed transaction event names. If you had listeners for | ||
'committed' or 'rolled back' events before, they are now called 'commit:complete' | ||
and 'rollback:complete' respectively. They are emitted **after** the corresponding | ||
SQL query has completed, if you want the old behaviour (events emitted when the | ||
`commit`/`rollback` methods are called) use 'commit:start' and 'rollback:start'. | ||
**Heads up!** - v0.5.0 changed the behaviour of 'query' events emitted by the | ||
connection pool and transaction objects. Whereas this would previously emit the | ||
SQL statement and an array of parameters, it now emits a single [Query | ||
object][query]. The query object is emitted *after* the query has been submitted | ||
to the backend so treat it as *read-only*. | ||
[query]: https://github.com/grncdr/node-any-db/blob/master/API.md | ||
## Synopsis | ||
@@ -13,0 +15,0 @@ |
@@ -11,3 +11,4 @@ require('./helpers').allPools("Pool query events", function (pool, t) { | ||
pool.on('query', function onQuery(stmt) { | ||
pool.on('query', function onQuery(query) { | ||
var stmt = query.sql || query.text || query.stmt; | ||
t.equal(stmt, expected.shift()) | ||
@@ -14,0 +15,0 @@ if (!expected.length) pool.removeListener('query', onQuery); |
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
41539
115
830
Updatedany-db-pool@>= 0.0.6