Skip to content

Commit bc549b0

Browse files
committed
Ensure url or options is not falsy
Fix message Fix parameter names
1 parent 08fcaa5 commit bc549b0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ Object.assign(Postgres, {
3636

3737
module.exports = Postgres
3838

39-
function Postgres(url, options) {
40-
options = parseOptions(url, options)
39+
function Postgres(a, b) {
40+
if (arguments.length && !a)
41+
throw new Error(a + ' - is not a url or connection object')
42+
43+
const options = parseOptions(a, b)
4144

4245
const max = Math.max(1, options.max)
4346
, connections = Queue()
@@ -444,10 +447,10 @@ function Postgres(url, options) {
444447
}
445448
}
446449

447-
function parseOptions(uri, options) {
450+
function parseOptions(a, b) {
448451
const env = process.env // eslint-disable-line
449-
, url = typeof uri === 'string' ? Url.parse(uri, true) : { query: {}, pathname: '' }
450-
, o = (typeof uri === 'string' ? options : uri) || {}
452+
, url = typeof a === 'string' ? Url.parse(a, true) : { query: {}, pathname: '' }
453+
, o = (typeof a === 'string' ? b : a) || {}
451454
, auth = (url.auth || '').split(':')
452455
, host = o.hostname || o.host || url.hostname || env.PGHOST || 'localhost'
453456
, port = o.port || url.port || env.PGPORT || 5432

0 commit comments

Comments
 (0)