Skip to content

Commit 45995f4

Browse files
committed
Expose server parameters
1 parent 7e3f0e0 commit 45995f4

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lib/backend.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const char = (acc, [k, v]) => (acc[k.charCodeAt(0)] = v, acc)
66
export default Backend
77

88
function Backend({
9+
onparameter,
910
parsers,
1011
onauth,
1112
onready,
@@ -46,7 +47,6 @@ function Backend({
4647

4748
const state = backend.state = {
4849
status : 'I',
49-
settings : {},
5050
pid : null,
5151
secret : null
5252
}
@@ -167,7 +167,7 @@ function Backend({
167167

168168
function ParameterStatus(x) {
169169
const [k, v] = x.utf8Slice(5, x.length - 1).split(N)
170-
state.settings[k] = v
170+
onparameter(k, v)
171171
}
172172

173173
function PortalSuspended(x) {

lib/connection.js

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { errors } from './types.js'
77

88
export default function Connection(options = {}) {
99
const {
10+
onparameter,
1011
transform,
1112
timeout,
1213
onnotify,
@@ -33,6 +34,7 @@ export default function Connection(options = {}) {
3334
})
3435

3536
const backend = Backend({
37+
onparameter,
3638
transform,
3739
parsers,
3840
resolve,

lib/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,22 @@ export default function Postgres(url, options) {
4141
}
4242

4343
Object.assign(postgres, {
44+
parameters: {},
4445
listen,
4546
begin,
4647
end
4748
})
4849

4950
addTypes(postgres)
5051

52+
const onparameter = options.onparameter
53+
options.onparameter = (k, v) => {
54+
if (postgres.parameters[k] !== v) {
55+
postgres.parameters[k] = v
56+
onparameter && onparameter(k, v)
57+
}
58+
}
59+
5160
return postgres
5261

5362
function begin(options, fn) {
@@ -110,10 +119,7 @@ export default function Postgres(url, options) {
110119
})
111120

112121
function scoped(xs, ...args) {
113-
return query(false, connection, xs, args).catch(err => {
114-
reject(err)
115-
throw err
116-
})
122+
return query(false, connection, xs, args).catch(reject)
117123
}
118124
}
119125

0 commit comments

Comments
 (0)