* Improve Readme.md for not so advanced users
1. Add brief description about the 3 possible ways of executing queries: passing the query to a pool, borrowing a client from a pool or obtaining an exclusive client. Give examples for the 3 of them.
2. Use the examples to teach how to reuse a pool in all of your project. This should be helpful for not so advanced users and prevents mistakes.
3. Open a troubleshooting section.
* Shrink Troubleshooting and Point to Examples
1. Troubleshooting/FAQ section will only contain a reference to the wiki FAQ. I've already moved the content to the wiki.
2. At the end of "Pooling example" point to the wiki example page. Also indicate that there they can find how to use node-postgres with promises and async/await. I've already created that content in the wiki.
On Windows, after a connect attempt has failed, an error event with
ECONNRESET is emitted after the real connect error is propagated to the
connect callback, because the connection is not in ending state
(connection._ending) where ECONNRESET is ignored. This change ends the
connection when connect has failed.
This fixes#746.
* Avoid infinite loop on malformed message
If handling of such messages is deemed unimportant, `indexOf` is still faster (~40%) and cleaner than a manual loop.
Addresses #1048 to an extent.
* Use indexOf fallback for Node ≤0.12
They were disabled by 4cdd7a116bab03c6096ab1af8f0f522b04993768 without comment; it seems that this might have been unintentional?
In any case, they should probably be enabled, updated, or removed.
* Use container-based CI
* Remove unnecessary CI configuration
* Use Node 6/PostgreSQL 9.6 as default test
… rather than testing 0.10 twice with unspecified PostgreSQL.
* Use `precise` for PostgreSQL 9.1
According to https://docs.travis-ci.com/user/database-setup/, 9.1 isn’t supported on trusty.
* Fix Node 0.10 and 0.12 CI builds
These binaries appear to have been built using g++ with flags that clang doesn’t support. Or something.
* Revert "When connection fail, emit the error. (#28)"
This reverts commit 6a7edabc22e36db7386c97ee93f08f957364f37d.
The callback passed to `Pool.prototype.connect` should be responsible for handling connection errors. The `error` event is documented to be:
> Emitted whenever an idle client in the pool encounters an error.
This isn’t the case of an idle client in the pool; it never makes it into the pool.
It also breaks tests on pg’s master because of nonspecific dependencies.
* Don’t create promises when callbacks are provided
It’s incorrect to do so. One consequence is that a rejected promise will be unhandled, which is currently annoying, but also dangerous in the future:
> DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The way callbacks are used currently also causes #24 (hiding of errors thrown synchronously from the callback). One fix for that would be to call them asynchronously from inside the `new Promise()` executor:
process.nextTick(cb, error);
I don’t think it’s worth implementing, though, since it would still be backwards-incompatible – just less obvious about it.
Also fixes a bug where the `Pool.prototype.connect` callback would be called twice if there was an error.
* Use Node-0.10-compatible `process.nextTick`
* When connection fail, emit the error.
If client connect failed, emit the connection error rather than swallowing it.
* Add test for connection error.
* Pool.query calls cb if connect() fails
Old behavior was that if connect called back with an error, the promise would get rejected but the cb function would never get called.
* Test that Pool.query passes connection errors to callback
* Fixes to standardjs compliance
Setting PostgreSQL 9.5 as the main version to test against.
NOTE: The following settings are required for 9.5 to work:
```
sudo: required
dist: trusty
```
A long standing bug was the pure JS client didn't accept or call a callback on `client.end`. This is inconsistent with both the documentation & general node patterns.
This fixes the issue & adds a test. The issue did not exist in the native version of the client.