Skip to content

Commit 45d4233

Browse files
committed
Fix porsager#3 url without db and trailing slash
1 parent c1ce6ae commit 45d4233

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function parseOptions(uri, options) {
456456
host,
457457
port,
458458
path : o.path || host.indexOf('/') > -1 && host + '/.s.PGSQL.' + port,
459-
database : o.database || o.db || url.pathname.slice(1) || env.PGDATABASE || 'postgres',
459+
database : o.database || o.db || (url.pathname || '').slice(1) || env.PGDATABASE || 'postgres',
460460
user : o.user || o.username || auth[0] || env.PGUSERNAME || os.userInfo().username,
461461
pass : o.pass || o.password || auth[1] || env.PGPASSWORD || '',
462462
max : o.max || url.query.max || Math.max(1, os.cpus().length),

tests/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ t('Connects with no options', async() => {
4747
return [1, result]
4848
})
4949

50+
t('Uses default database without slash', async() =>
51+
['postgres', postgres('postgres://localhost').options.database]
52+
)
53+
54+
t('Uses default database with slash', async() =>
55+
['postgres', postgres('postgres://localhost/').options.database]
56+
)
57+
5058
t('Result is array', async() =>
5159
[true, Array.isArray(await sql`select 1`)]
5260
)

0 commit comments

Comments
 (0)