Skip to content

Commit

Permalink
docs update.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Feb 11, 2016
1 parent 9f2d7c4 commit 79cd40a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 56 deletions.
60 changes: 7 additions & 53 deletions README.md
Expand Up @@ -957,7 +957,7 @@ The library verifies whether the callback function is a generator, and executes
## Initialization Options
When initializing the library, you can pass object `options` with a set of global properties.
See [API->options](http://vitaly-t.github.io/pg-promise/module-pg-promise.html).
See [API / options](http://vitaly-t.github.io/pg-promise/module-pg-promise.html).
---
#### pgFormatting
Expand Down Expand Up @@ -1018,17 +1018,17 @@ mostly needed by smaller and simplified [Conformant Implementations](https://pro
---
#### connect
See [API->connect](http://vitaly-t.github.io/pg-promise/global.html#event:connect).
See [API / event `connect`](http://vitaly-t.github.io/pg-promise/global.html#event:connect).
---
#### disconnect
See [API->disconnect](http://vitaly-t.github.io/pg-promise/global.html#event:disconnect).
See [API / event `disconnect`](http://vitaly-t.github.io/pg-promise/global.html#event:disconnect).
---
#### query
See [API->query](http://vitaly-t.github.io/pg-promise/global.html#event:query).
See [API / event `query`](http://vitaly-t.github.io/pg-promise/global.html#event:query).
---
#### receive
Expand Down Expand Up @@ -1097,63 +1097,17 @@ function camelizeColumns(data) {
---
#### error
See [API->error](http://vitaly-t.github.io/pg-promise/global.html#event:error).
See [API / event `error`](http://vitaly-t.github.io/pg-promise/global.html#event:error).
---
#### task
Global notification of a task start / finish events.
```javascript
var options = {
task: function (e) {
console.log("Start Time:", e.ctx.start);
if (e.ctx.finish) {
// this is a task `finish` event;
console.log("Finish Time:", e.ctx.finish);
if (e.ctx.success) {
// e.ctx.result = the data resolved;
} else {
// e.ctx.result = the rejection reason;
}
} else {
// this is a task `start` event;
}
}
};
```
For parameter `e` see documentation of the `query` event earlier.
The library will suppress any error thrown by the handler and write it into the console.
See [API / event `task`](http://vitaly-t.github.io/pg-promise/global.html#event:task).
---
#### transact
Global notification of a transaction start / finish events.
```javascript
var options = {
transact: function (e) {
console.log("Start Time:", e.ctx.start);
if (e.ctx.finish) {
// this is a transaction `finish` event;
console.log("Finish Time:", e.ctx.finish);
if (e.ctx.success) {
// e.ctx.result = the data resolved;
} else {
// e.ctx.result = the rejection reason;
}
} else {
// this is a transaction `start` event;
}
}
};
```
For parameter `e` see documentation of the `query` event earlier.
The library will suppress any error thrown by the handler and write it into the console.
See [API / event `transact`](http://vitaly-t.github.io/pg-promise/global.html#event:transact).
---
#### extend
Expand Down
59 changes: 57 additions & 2 deletions lib/events.js
Expand Up @@ -8,6 +8,7 @@ var $npm = {
/////////////////////////////////
// Client notification helpers;
var $events = {

/**
* @event connect
* @description
Expand Down Expand Up @@ -43,6 +44,7 @@ var $events = {
}
}
},

/**
* @event disconnect
* @description
Expand Down Expand Up @@ -78,6 +80,7 @@ var $events = {
}
}
},

/**
* @event query
* @description
Expand Down Expand Up @@ -169,6 +172,7 @@ var $events = {
}
}
},

/**
* @event receive
* @summary Global notification of any received data.
Expand All @@ -190,14 +194,38 @@ var $events = {
}
}
},

/**
* @event task
* @summary Global notification of a task start / finish events.
* @description
* Global notification of a task start / finish events.
*
* The library will suppress any error thrown by the handler and write it into the console.
*
* @param {Object} e - Event Context Object.
*
* This type of object is used by several events. See event {@link event:query query}
* for its complete documentation.
*
* @example
*
* var options = {
* task: function (e) {
* if (e.ctx.finish) {
* // this is a task->finish event;
* console.log("Finish Time:", e.ctx.finish);
* if (e.ctx.success) {
* // e.ctx.result = resolved data;
* } else {
* // e.ctx.result = error/rejection reason;
* }
* } else {
* // this is a task->start event;
* console.log("Start Time:", e.ctx.start);
* }
* }
* };
*
*/
task: function (options, context) {
if (options && options.task instanceof Function) {
Expand All @@ -209,14 +237,38 @@ var $events = {
}
}
},

/**
* @event transact
* @summary Global notification of a transaction start / finish events.
* @description
* Global notification of a transaction start / finish events.
*
* The library will suppress any error thrown by the handler and write it into the console.
*
* @param {Object} e - Event Context Object.
*
* This type of object is used by several events. See event {@link event:query query}
* for its complete documentation.
*
* @example
*
* var options = {
* transact: function (e) {
* if (e.ctx.finish) {
* // this is a transaction->finish event;
* console.log("Finish Time:", e.ctx.finish);
* if (e.ctx.success) {
* // e.ctx.result = resolved data;
* } else {
* // e.ctx.result = error/rejection reason;
* }
* } else {
* // this is a transaction->start event;
* console.log("Start Time:", e.ctx.start);
* }
* }
* };
*
*/
transact: function (options, context) {
if (options && options.transact instanceof Function) {
Expand All @@ -228,6 +280,7 @@ var $events = {
}
}
},

/**
* @event error
* @description
Expand Down Expand Up @@ -284,6 +337,7 @@ var $events = {
}
}
},

/**
* @event extend
* @summary Extends database protocol with custom methods and properties.
Expand All @@ -301,6 +355,7 @@ var $events = {
}
}
},

/**
* @event unexpected
* @param {String} event - unhandled event name.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "pg-promise",
"version": "3.1.6",
"version": "3.1.7",
"description": "PostgreSQL via promises",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 79cd40a

Please sign in to comment.