pg-promise
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -249,3 +249,3 @@ var npm = { | ||
} | ||
} | ||
}; | ||
@@ -252,0 +252,0 @@ // private properties and functions; |
{ | ||
"name": "pg-promise", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "PG + Promise made easy, with transactions support.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# Introduction | ||
This library unifies [Promise] and [PG] to fascilitate easy-to-read database code that relies on promises: | ||
>- Simplistic approach to organizing streamlined database code, thanks to full [Promise] integration; | ||
>- Database connections are managed automatically, in every usage case; | ||
>- Functions, Procedures and Transactions are all fully supported; | ||
>- Robust approach to handling results from every single query. | ||
* Simplistic approach to organizing streamlined database code, thanks to full [Promise] integration; | ||
* Database connections are managed automatically, in every usage case; | ||
* Functions, Procedures and Transactions are all fully supported; | ||
* Robust approach to handling results from every single query. | ||
@@ -105,3 +105,5 @@ # Getting started | ||
Note that while inside a transaction, we make calls to the same-named methods as outside of transactions, except we do it on the transaction object instance now, as opposed to the global ````pgp```` object, which gives us access to the shared connection object. The same goes for calling functions and procedures within transactions, using ````tx.func```` and ````tx.proc```` accordingly. | ||
<b>Notes</b> | ||
1. While inside a transaction, we make calls to the same-named methods as outside of transactions, except we do it on the transaction object instance now, as opposed to the global ````pgp```` object, which gives us access to the shared connection object. The same goes for calling functions and procedures within transactions, using ````tx.func```` and ````tx.proc```` accordingly. | ||
2. Just for flexibility, the transaction call-back function takes one parameter - PG client connection object. | ||
@@ -122,6 +124,46 @@ ### Type Helpers | ||
# Advanced | ||
Work in progress. | ||
### Initialization options | ||
Initialization options are supported as shown in the example below: | ||
``` | ||
var options = { | ||
connect: function(n, client){ | ||
console.log(n + ' virtual connections established'); | ||
}, | ||
disconnect: function(n, client){ | ||
console.log(n + ' virtual connections are remaining open'); | ||
} | ||
}; | ||
``` | ||
Two events supported at the moment - ```connect``` and ```disconnect```, to notify of virtual connections being established or closed accordingly. Each takes parameter ```client```, which is the PG client connection object. | ||
### Direct connection usage | ||
The library exposes method ```connect``` in case for some very unique reason you want to be able to open and close the connection yourself, as opposed to trusting the library doing it for you automatically. | ||
Usage example: | ||
``` | ||
pgp.connect().then(function(db){ | ||
// connection was established successfully; | ||
// do stuff with the connection object (db.client) and/or queries; | ||
// when done with all the queries, call done(): | ||
db.done(); | ||
// when the connection is no longer needed, must call: | ||
db.client.end(); | ||
}, function(reason){ | ||
// failed to connect; | ||
console.log('Connection problem: ' + reason); | ||
}); | ||
``` | ||
<b>NOTE:</b> When using the direct connection, events ```connect``` and ```disconnect``` won't be fired. | ||
# History | ||
* It reached version 0.0.9 on March 4th, 2015. Presumably, making it 0.1.0 would siginify the first beta of the package. | ||
* The first draft v0.0.1 was published on March 3rd, 2015, and then rapidly incremented due to many initial changes that had to come in, mostly documentation. | ||
[PG]:https://www.npmjs.com/package/pg | ||
[Promise]:https://www.npmjs.com/package/promise | ||
Sorry, the diff of this file is not supported yet
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
36008
168