Skip to content

Commit

Permalink
fixing the latest release - last minute change.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Dec 14, 2015
1 parent c644440 commit 256bba9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -256,7 +256,7 @@ db.manyOrNone(query, values); // expects anything, same as `any`
```

There is however one specific method `result(query, values)` to bypass any result verification, and instead resolve
with the original [Result](https://github.com/brianc/node-postgres/blob/master/lib/result.js#L6) object passed from the [PG] library.
with the original [Result] object passed from the [PG] library.

You can also add your own methods and properties to this protocol via the [extend](#extend) event.

Expand Down Expand Up @@ -1050,8 +1050,9 @@ or from a stream.
```js
var options = {
receive: function (data, e) {
receive: function (data, result, e) {
console.log("DATA:", data);
// result = original Result object, if available;
// e = event context object;
}
};
Expand All @@ -1071,6 +1072,9 @@ This event notification serves two purposes:
Parameter `data` is always a non-empty array, containing objects - rows. If any of those
objects are modified during notification, the client will receive the modified data.
Parameter `result` is the [Result] object, if the data comes from a regular query.
When the data comes from a stream, parameter `result` is `null`.
**NOTES:**
* If you are pre-processing the data, you should only change properties of the individual elements
(objects - rows), but never the elements themselves, much less the array's length, as it will
Expand Down Expand Up @@ -1346,3 +1350,4 @@ DEALINGS IN THE SOFTWARE.
[Learn by Example]:https://github.com/vitaly-t/pg-promise/wiki/Learn-by-Example
[Promise Adapter]:https://github.com/vitaly-t/pg-promise/wiki/Promise-Adapter
[spex.sequence]:https://github.com/vitaly-t/spex/blob/master/docs/code/sequence.md
[Result]:https://github.com/brianc/node-postgres/blob/master/lib/result.js#L6
11 changes: 6 additions & 5 deletions lib/index.js
Expand Up @@ -616,7 +616,7 @@ function $query(ctx, query, values, qrm) {
}
if (!notifyReject()) {
if (result.rows.length) {
errMsg = $notify.receive(opt, result.rows, {
errMsg = $notify.receive(opt, result.rows, result, {
client: ctx.db.client,
query: query,
params: params,
Expand Down Expand Up @@ -700,7 +700,7 @@ function $stream(ctx, qs, init) {
nRows += rows.length;
var client = getClient();
if (error === undefined) {
error = $notify.receive(ctx.options, rows, {
error = $notify.receive(ctx.options, rows, null, {
client: client,
query: qs.text,
params: qs.values,
Expand Down Expand Up @@ -972,13 +972,14 @@ var $notify = {
* @event receive
* @memberof module:pg-promise
* @summary Global notification of any received data.
* @param {Object} data - received data.
* @param {Array} data - array of received data rows.
* @param {Object} result - original $[Result] object, if available.
* @param {Object} e - event context object.
*/
receive: function (options, data, context) {
receive: function (options, data, result, context) {
if (options && options.receive instanceof Function) {
try {
options.receive(data, context);
options.receive(data, result, context);
} catch (err) {
// throwing an error during event 'receive'
// will result in a reject for the request.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "pg-promise",
"version": "2.8.0",
"version": "2.8.1",
"description": "PostgreSQL via promises",
"main": "lib/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions test/eventSpec.js
Expand Up @@ -408,7 +408,7 @@ describe("Receive event", function () {
describe("query positive", function () {
var ctx, data, counter = 0;
beforeEach(function (done) {
options.receive = function (d, e) {
options.receive = function (d, r, e) {
counter++;
data = d;
ctx = e;
Expand Down Expand Up @@ -448,7 +448,7 @@ describe("Receive event", function () {
describe("stream positive", function () {
var ctx, data, counter = 0;
beforeEach(function (done) {
options.receive = function (d, e) {
options.receive = function (d, r, e) {
counter++;
data = d;
ctx = e;
Expand Down

0 comments on commit 256bba9

Please sign in to comment.