Skip to content

Commit 972e8f9

Browse files
committed
Add support for connection parameters
1 parent e4cfd67 commit 972e8f9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/connection.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { errors } from './types.js'
88
export default function Connection(options = {}) {
99
const {
1010
transform,
11-
database,
12-
user,
1311
timeout,
1412
onnotify,
1513
onnotice,
@@ -152,7 +150,7 @@ export default function Connection(options = {}) {
152150
}
153151

154152
function ready() {
155-
socket.write(frontend.connect({ user, database }))
153+
socket.write(frontend.connect(options))
156154
}
157155

158156
function close() {

lib/frontend.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ export default {
7474
7575
*/
7676

77-
function connect({ user, database }) {
77+
function connect({ user, database, connection }) {
7878
return bytes
7979
.inc(4)
8080
.i16(3)
8181
.z(2)
82-
.str(['user', user, 'database', database, 'client_encoding', '\'utf-8\''].join(N))
82+
.str(Object.entries({
83+
user,
84+
database,
85+
client_encoding: '\'utf-8\'',
86+
...connection
87+
}).filter(([k, v]) => v).map(p).map(([k, v]) => k + N + v).join(N))
8388
.z(2)
8489
.end(0)
8590
}

0 commit comments

Comments
 (0)