708 Commits

Author SHA1 Message Date
Peter Boromissza
0993e4b61a Added the missing connect_timeout and keepalives_idle config parameters (#1847)
* Added the missing connect_timeout and keepalives_idle config parameters

* Implementation and tests for keepAliveInitialDelayMillis and connectionTimeoutMillis [squashed 4]
2019-05-10 11:48:38 -05:00
Sehrope Sarkuni
13c14f1de0 fix: Catch and emit query parameter prepareValue(...) errors (#1855)
Adds a try/catch block around the prepareValue(...) invocations in query.prepare(...)
to ensure that any that throw an error are caught and bubbled up to the caller.
2019-04-16 17:29:40 -05:00
Tony Wooster
566058de17 Add support for per per-query types (#1825)
The documentation states that you can pass custom type processors to
query objects. See:

https://node-postgres.com/features/queries#types

This didn't actually work. This commit adds an initial implementation
of per-query type-parsing. Caveats:

* It does not work with pg-native. That would require a separate pull
  request to pg-native, and a rather significant change to how that
  library handles query results.

* Per-query types do not "inherit" from types assigned to the Client,
  ala TypeOverrides.
2019-04-16 17:27:39 -05:00
Malcolm
43ebcfb6bc Fix input preparation for date objects with a BC year (#1864)
* test: BC date input preparation

* Fix input preparation for BC dates
2019-04-15 18:38:20 -05:00
andreme
5a92ba3701 sasl/scram authentication (#1835) 2019-03-07 11:02:21 -06:00
Rich Harris
e6a878cbb5 compare prepared statement text with previous to prevent incorrect queries (#1814)
* compare prepared statement text with previous to prevent incorrect queries - fixes #1813

* make suggested changes to error message
2019-03-06 09:35:30 -06:00
Gregory Lepsky
ccbccc9716 Issue #1769 - Inability to restrict communication protocols to set in ssl configuration (#1804)
- Propagate client's ssl.secureOptions config to TLS.
2019-01-08 09:08:43 -06:00
André Cruz
eb076db5d4 Add configurable query timeout (#1760)
* Add read_timeout to connection settings

* Fix uncaught error issue

* Fix lint

* Fix "queryCallback is not a function"

* Added test and fixed error returning

* Added query timeout to native client

* Added test for timeout not reached

* Ensure error is the correct one
Correct test name

* Removed dubious check

* Added new test

* Improved test
2018-11-29 09:11:47 -06:00
Igor Savin
badf0a1c65 Update ESLint (#1753)
* Update ESLint

* Downgrade ESLint version to restore Node 4 support

* Downgrade more dependencies

* Keep downgrading
2018-10-26 08:55:31 -05:00
Charmander
1cf1e05ab9 Allow a custom type to be used for Client promises (#1518)
Matches the Pool API.
2018-10-24 10:40:23 -05:00
Charmander
3828aa8608 Queued query errors (#1503)
* Add tests for query callbacks after connection-level errors

* Ensure callbacks are executed for all queued queries after connection-level errors

Separates socket errors from error messages, sends socket errors to all queries in the queue, marks clients as unusable after socket errors.

This is not very pleasant but should maintain backwards compatibility…?

* Always call `handleError` asynchronously

This doesn’t match the original behaviour of the type errors, but it’s correct.

* Fix return value of `Client.prototype.query` in immediate error cases

* Mark clients with closed connections as unusable consistently

* Add tests for error event when connecting Client

* Ensure the promise and callback versions of Client#connect always have the same behaviour

* Give same error to queued queries as to active query when ending

and do so in the native Client as well.

* Restore original ordering between queued query callbacks and 'end' event
2018-10-03 10:37:15 -05:00
Thomas Hunter II
fed6375e0a remove query.stream references
* This hasn't been supported since 0b2344b6b5afbb68e89eff1ef2b57ecf0726d80b
* `node-pg-copy-streams` relies on overriding the `handleCopyInResponse` method:
  * https://github.com/brianc/node-pg-copy-streams/blob/e15feb19/index.js#L53
2018-10-03 10:16:42 -05:00
Pat Gaffney
11a4793452 Add error handling for null params to Client.prototype.query() 2018-10-03 10:15:04 -05:00
Gajus Kuizinas
00d749cdfa refactor: simplify the escapeIdentifier logic 2018-07-29 21:29:27 +01:00
Matt Keas
7de137f9f8 tls.connect({checkServerIdentity}) option cannot be a null - must be a method or not exist.
Defaults to built-in `tls.checkServerIdentity` method in the event one is not passed into `pgConfig.ssl`

Found breaking in v9.4.2 vs v9.4.1 a la 49054717b4ec0c6d477f04c2becd1f9680b2d13a

cc @tobio @brianc
2018-05-07 10:05:56 -05:00
contra
72db7902fa dont use dynamic functions to parse rows, closes #1417 2018-05-04 12:34:46 -05:00
Toby Brain
49054717b4 Add ability to specify checkServerIdentity callback 2018-05-04 12:33:48 -05:00
Justin Jaffray
831dfb1b4c Pass through portal properly
This happened to work before because `Query.portalName` was undefined,
but in order to be able to set the portal explicitly it should be using
`Query.portal`.
2018-05-04 12:30:17 -05:00
Matthew Blewitt
9389527609 Add comments to case branches, explaining code meanings 2018-05-04 12:20:42 -05:00
Matthew Blewitt
5d32be4a90 Handle SSL negotiation errors more robustly
This commit adds some finer grained detail to handling the postmaster's
response to SSL negotiation packets, by accounting for the possibility
of an 'E' byte being sent back, and emitting an appropriate error.

In the naive case, the postmaster will respond with either 'S' (proceed
with an SSL connection) or 'N' (SSL is not supported). However, the
current if statement doesn't account for an 'E' byte being returned
by the postmaster, where an error is encountered (perhaps unable to
fork due to being out of memory).

By adding this case, we can prevent confusing error messages when SSL is
enforced and the postmaster returns an error after successful SSL
connections.

This also brings the connection handling further in line with
libpq, where 'E' is handled similarly as of this commit:

a49fbaaf8d

Given that there are no longer pre-7.0 databases out in the wild, I
believe this is a safe change to make, and should not break backwards
compatibility (unless matching on error message content).

* Replace if statement with switch, to catch 'S', 'E' and 'N' bytes
  returned by the postmaster
* Return an Error for non 'S' or 'N' cases
* Expand and restructure unit tests for SSL negotiation packets
2018-05-04 12:20:42 -05:00
Vratislav Kalenda
0902d145f4 fix: end stream connection 2018-05-04 12:19:53 -05:00
C. T. Lin
875236fc0b
use net.Socket instead of net.Stream
`net.Stream` is a undocumented legacy naming from node 0.x
4ae320f2b3/lib/net.js (L1762)
2018-03-14 22:43:52 +08:00
Ruben Bridgewater
3f1d7b9bc6
Remove noAssert argument
The support for the `noAssert` argument dropped in the upcoming
Node.js v.10.x. All input is then validated no matter if this
is set to true or not. Just remove the argument because of that.
2018-03-10 22:09:23 +01:00
Pasi Eronen
70a8ee1334 Don't repeat logic for reporting stream errors 2018-01-05 13:40:25 -06:00
Pasi Eronen
4cf67b23d4 Ignore socket hangup when ending connection also with ssl (#1344). 2018-01-05 13:40:25 -06:00
Jan Schär
894e2f2f1e Support Uint8Array values 2017-11-04 14:18:36 -05:00
Josh
ad36063ca5 support statement_timeout 2017-09-03 14:14:28 -05:00
Arnaud Benhamdine
3b3e52cdc2 Prefer max over poolSize : max is the only property documented in node-pg-pool 2017-09-03 14:01:34 -05:00
Arnaud Benhamdine
27492efc11 Remove properties no more used in node-pg-pool 2017-09-03 14:01:34 -05:00
Sehrope Sarkuni
ef3379a480 Normalize export in utils to use short form 2017-08-30 15:30:36 -05:00
Sehrope Sarkuni
e74c13ddad Centralize password md5 hashing logic
Centralize logic for md5 hashing of passwords for authentication. Adds
a new function postgresMd5PasswordHash(user, password, salt) to utils
and updates client.js and tests to use it.
2017-08-30 15:30:36 -05:00
Tobias Gurtzick
03c2270d0e add missing sslrootcert for native bindings 2017-08-26 12:26:08 -05:00
Sehrope Sarkuni
884e21e1ca Refactor addCommandComplete
Refactors addCommandComplete to tighten parsing regex start anchor and
handle edge case where no row count is specified (pre 8.2 COPY).
2017-08-26 12:24:59 -05:00
Brian M. Carlson
48543bfad0 Fix vulnerability 2017-08-12 16:34:22 -05:00
caub
3a6b8416c2 allow both connectionString and additional options 2017-08-03 23:53:00 -05:00
Vitaly Tomilov
40cc6aa111 Update utils.js
fixing invalid custom type check
2017-07-21 17:02:06 -05:00
Brian Carlson
66c6776f6e Make client.end return promise with active query 2017-07-21 16:59:24 -05:00
Billouboq
5062f275a7 remove unused variable
test
2017-07-19 00:48:20 +02:00
Brian M. Carlson
ca4ac9983a Re-implement other patch 2017-07-16 16:39:22 -05:00
Brian M. Carlson
f9390dab6b Re-implement changes from conflict 2017-07-16 16:35:32 -05:00
Brian M. Carlson
111e08d0d7 Cleanup 2017-07-16 16:25:35 -05:00
Brian M. Carlson
ac3102eea2 Add support for pg-native multi-row result 2017-07-16 16:25:35 -05:00
Brian M. Carlson
28b330c88e Add JS driver support for multiple results 2017-07-16 16:25:35 -05:00
Brian C
8798e50ad3 Re-enable eslint with standard format (#1367)
* Work on converting lib to standard

* Finish updating lib

* Finish linting lib

* Format test files

* Add .eslintrc with standard format

* Supply full path to eslint bin

* Move lint command to package.json

* Add eslint as dev dependency
2017-07-15 12:05:58 -05:00
Brian M. Carlson
f7de9ce820 Non-array query values cause query to end with an error.
This is a small change and is _kinda_ backwards compatible since the old behavior was to throw an error, but if someone was relying on anything with `.map` working as values it would break them, so it's in a major semver bump.
2017-07-15 11:19:37 -05:00
Brian Carlson
27450d07e6 Throw on reconnect attempt
Clients are not reusable.  This changes the client to raise errors whenever you try to reconnect a client that's already been used.  They're cheap to create: just instantiate a new one (or use the pool) 😉.

Closes #1352
2017-07-15 11:02:09 -05:00
Brian M. Carlson
da71ea58f6 Add query validity check
Passing nothing for both the query.text and query.name is unsupported but previously crashed with an impossible to catch error.
2017-06-18 17:15:46 -05:00
Brian M. Carlson
bd87cddc72 Fix connection / disconnection issues 2017-06-18 16:48:14 -05:00
Brian M. Carlson
0f1f8626cf Add use strict to every file 2017-06-18 16:48:14 -05:00
Brian M. Carlson
2300445646 Cleanup a bit of dead code 2017-06-18 16:48:14 -05:00