Skip to content

Commit e3cf0ad

Browse files
committed
Support options connection parameter
This supports the connection parameter documented here: https://www.postgresql.org/docs/9.1/libpq-connect.html#LIBPQ-CONNECT-OPTIONS
1 parent 70c8e5f commit e3cf0ad

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

packages/pg-connection-string/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export interface ConnectionOptions {
1111

1212
application_name?: string
1313
fallback_application_name?: string
14+
options?: string
1415
}

packages/pg-connection-string/test/parse.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ describe('parse', function () {
188188
subject.fallback_application_name.should.equal('TheAppFallback')
189189
})
190190

191-
it('configuration parameter fallback_application_name', function () {
192-
var connectionString = 'pg:///?fallback_application_name=TheAppFallback'
191+
it('configuration parameter options', function () {
192+
var connectionString = 'pg:///?options=-c geqo=off'
193193
var subject = parse(connectionString)
194-
subject.fallback_application_name.should.equal('TheAppFallback')
194+
subject.options.should.equal('-c geqo=off')
195195
})
196196

197197
it('configuration parameter ssl=true', function () {

packages/pg/lib/client.js

+4
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ Client.prototype.getStartupConf = function () {
391391
if (params.idle_in_transaction_session_timeout) {
392392
data.idle_in_transaction_session_timeout = String(parseInt(params.idle_in_transaction_session_timeout, 10))
393393
}
394+
if (params.options) {
395+
data.options = params.options
396+
}
397+
394398

395399
return data
396400
}

packages/pg/lib/connection-parameters.js

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var ConnectionParameters = function (config) {
7070
})
7171

7272
this.binary = val('binary', config)
73+
this.options = val('options', config)
7374

7475
this.ssl = typeof config.ssl === 'undefined' ? readSSLConfigFromEnvironment() : config.ssl
7576

@@ -126,6 +127,7 @@ ConnectionParameters.prototype.getLibpqConnectionString = function (cb) {
126127
add(params, this, 'application_name')
127128
add(params, this, 'fallback_application_name')
128129
add(params, this, 'connect_timeout')
130+
add(params, this, 'options')
129131

130132
var ssl = typeof this.ssl === 'object' ? this.ssl : this.ssl ? { sslmode: this.ssl } : {}
131133
add(params, ssl, 'sslmode')

packages/pg/lib/defaults.js

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ module.exports = {
5353

5454
fallback_application_name: undefined,
5555

56+
options: undefined,
57+
5658
parseInputDatesAsUTC: false,
5759

5860
// max milliseconds any query using this connection will execute for before timing out in error.

packages/pg/test/unit/connection-parameters/creation-tests.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var compare = function (actual, expected, type) {
2525
assert.equal(actual.password, expected.password, type + ' password')
2626
assert.equal(actual.binary, expected.binary, type + ' binary')
2727
assert.equal(actual.statement_timeout, expected.statement_timeout, type + ' statement_timeout')
28+
assert.equal(actual.options, expected.options, type + ' options')
2829
assert.equal(
2930
actual.idle_in_transaction_session_timeout,
3031
expected.idle_in_transaction_session_timeout,
@@ -48,12 +49,14 @@ test('ConnectionParameters initializing from defaults with connectionString set'
4849
binary: defaults.binary,
4950
statement_timeout: false,
5051
idle_in_transaction_session_timeout: false,
52+
options: '-c geqo=off',
5153
}
5254

5355
var original_value = defaults.connectionString
5456
// Just changing this here doesn't actually work because it's no longer in scope when viewed inside of
5557
// of ConnectionParameters() so we have to pass in the defaults explicitly to test it
56-
defaults.connectionString = 'postgres://brians-are-the-best:[email protected]:7777/scoobysnacks'
58+
defaults.connectionString =
59+
'postgres://brians-are-the-best:[email protected]:7777/scoobysnacks?options=-c geqo=off'
5760
var subject = new ConnectionParameters(defaults)
5861
defaults.connectionString = original_value
5962
compare(subject, config, 'defaults-connectionString')
@@ -73,6 +76,7 @@ test('ConnectionParameters initializing from config', function () {
7376
},
7477
statement_timeout: 15000,
7578
idle_in_transaction_session_timeout: 15000,
79+
options: '-c geqo=off',
7680
}
7781
var subject = new ConnectionParameters(config)
7882
compare(subject, config, 'config')

0 commit comments

Comments
 (0)