Skip to content

Commit 4a3c1d5

Browse files
committed
refactor(connection-string): Change protocol name to gaussdb
- Updated connection string parsing logic to recognize `gaussdb://`. - Modified test cases. - Revised README documentation with updated connection examples.
1 parent 5c04b3f commit 4a3c1d5

File tree

15 files changed

+102
-101
lines changed

15 files changed

+102
-101
lines changed

docs/pages/apis/client.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Config = {
1515
host?: string, // default process.env.PGHOST
1616
port?: number, // default process.env.PGPORT
1717
database?: string, // default process.env.PGDATABASE || user
18-
connectionString?: string, // e.g. postgres://user:password@host:5432/database
18+
connectionString?: string, // e.g. gaussdb://user:password@host:5432/database
1919
ssl?: any, // passed directly to node.TLSSocket, supports all tls.connect options
2020
types?: any, // custom type parsers
2121
statement_timeout?: number, // number of milliseconds before a statement in query will time out, default is no timeout

docs/pages/features/ssl.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ If you plan to use a combination of a database connection string from the enviro
4242

4343
```js
4444
const config = {
45-
connectionString: 'postgres://user:password@host:port/db?sslmode=require',
45+
connectionString: 'gaussdb://user:password@host:port/db?sslmode=require',
4646
// Beware! The ssl object is overwritten when parsing the connectionString
4747
ssl: {
4848
rejectUnauthorized: false,

packages/gaussdb-connection-string/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ MIT License
1414
```js
1515
const parse = require('pg-connection-string').parse;
1616

17-
const config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
17+
const config = parse('gaussdb://someuser:somepassword@somehost:381/somedatabase')
1818
```
1919

2020
The resulting config contains a subset of the following properties:
@@ -40,7 +40,7 @@ The pg-connection-string `ConnectionOptions` interface is not compatible with th
4040
import { ClientConfig } from 'pg';
4141
import { parseIntoClientConfig } from 'pg-connection-string';
4242

43-
const config: ClientConfig = parseIntoClientConfig('postgres://someuser:somepassword@somehost:381/somedatabase')
43+
const config: ClientConfig = parseIntoClientConfig('gaussdb://someuser:somepassword@somehost:381/somedatabase')
4444
```
4545

4646
You can also use `toClientConfig` to convert an existing `ConnectionOptions` interface into a `ClientConfig` interface:
@@ -49,7 +49,7 @@ You can also use `toClientConfig` to convert an existing `ConnectionOptions` int
4949
import { ClientConfig } from 'pg';
5050
import { parse, toClientConfig } from 'pg-connection-string';
5151

52-
const config = parse('postgres://someuser:somepassword@somehost:381/somedatabase')
52+
const config = parse('gaussdb://someuser:somepassword@somehost:381/somedatabase')
5353
const clientConfig: ClientConfig = toClientConfig(config)
5454
```
5555

@@ -58,7 +58,7 @@ const clientConfig: ClientConfig = toClientConfig(config)
5858
The short summary of acceptable URLs is:
5959

6060
* `socket:<path>?<query>` - UNIX domain socket
61-
* `postgres://<user>:<password>@<host>:<port>/<database>?<query>` - TCP connection
61+
* `gaussdb://<user>:<password>@<host>:<port>/<database>?<query>` - TCP connection
6262

6363
But see below for more details.
6464

packages/gaussdb-connection-string/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function parse(str, options = {}) {
2323
}
2424

2525
try {
26-
result = new URL(str, 'postgres://base')
26+
result = new URL(str, 'gaussdb://base')
2727
} catch (e) {
2828
// The URL is invalid so try again with a dummy host
29-
result = new URL(str.replace('@/', '@___DUMMY___/'), 'postgres://base')
29+
result = new URL(str.replace('@/', '@___DUMMY___/'), 'gaussdb://base')
3030
dummyHost = true
3131
}
3232

packages/gaussdb-connection-string/test/clientConfig.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { parse, toClientConfig, parseIntoClientConfig } from '../'
66

77
describe('toClientConfig', function () {
88
it('converts connection info', function () {
9-
const config = parse('postgres://brian:pw@boom:381/lala')
9+
const config = parse('gaussdb://brian:pw@boom:381/lala')
1010
const clientConfig = toClientConfig(config)
1111

1212
clientConfig.user?.should.equal('brian')
@@ -18,7 +18,7 @@ describe('toClientConfig', function () {
1818

1919
it('converts query params', function () {
2020
const config = parse(
21-
'postgres:///?application_name=TheApp&fallback_application_name=TheAppFallback&client_encoding=utf8&options=-c geqo=off'
21+
'gaussdb:///?application_name=TheApp&fallback_application_name=TheAppFallback&client_encoding=utf8&options=-c geqo=off'
2222
)
2323
const clientConfig = toClientConfig(config)
2424

@@ -29,21 +29,21 @@ describe('toClientConfig', function () {
2929
})
3030

3131
it('converts SSL boolean', function () {
32-
const config = parse('pg:///?ssl=true')
32+
const config = parse('gaussdb:///?ssl=true')
3333
const clientConfig = toClientConfig(config)
3434

3535
clientConfig.ssl?.should.equal(true)
3636
})
3737

3838
it('converts sslmode=disable', function () {
39-
const config = parse('pg:///?sslmode=disable')
39+
const config = parse('gaussdb:///?sslmode=disable')
4040
const clientConfig = toClientConfig(config)
4141

4242
clientConfig.ssl?.should.equal(false)
4343
})
4444

4545
it('converts sslmode=noverify', function () {
46-
const config = parse('pg:///?sslmode=no-verify')
46+
const config = parse('gaussdb:///?sslmode=no-verify')
4747
const clientConfig = toClientConfig(config)
4848

4949
clientConfig.ssl?.should.deep.equal({
@@ -52,22 +52,22 @@ describe('toClientConfig', function () {
5252
})
5353

5454
it('converts other sslmode options', function () {
55-
const config = parse('pg:///?sslmode=verify-ca')
55+
const config = parse('gaussdb:///?sslmode=verify-ca')
5656
const clientConfig = toClientConfig(config)
5757

5858
clientConfig.ssl?.should.deep.equal({})
5959
})
6060

6161
it('converts other sslmode options', function () {
62-
const config = parse('pg:///?sslmode=verify-ca')
62+
const config = parse('gaussdb:///?sslmode=verify-ca')
6363
const clientConfig = toClientConfig(config)
6464

6565
clientConfig.ssl?.should.deep.equal({})
6666
})
6767

6868
it('converts ssl cert options', function () {
6969
const connectionString =
70-
'pg:///?sslcert=' +
70+
'gaussdb:///?sslcert=' +
7171
__dirname +
7272
'/example.cert&sslkey=' +
7373
__dirname +
@@ -93,13 +93,13 @@ describe('toClientConfig', function () {
9393
})
9494

9595
it('handles invalid port', function () {
96-
const config = parse('postgres://@boom:381/lala')
96+
const config = parse('gaussdb://@boom:381/lala')
9797
config.port = 'bogus'
9898
expect(() => toClientConfig(config)).to.throw()
9999
})
100100

101101
it('handles invalid sslconfig values', function () {
102-
const config = parse('postgres://@boom/lala')
102+
const config = parse('gaussdb://@boom/lala')
103103
config.ssl = {}
104104
config.ssl.cert = null
105105
config.ssl.key = undefined
@@ -114,7 +114,7 @@ describe('toClientConfig', function () {
114114

115115
describe('parseIntoClientConfig', function () {
116116
it('converts url', function () {
117-
const clientConfig = parseIntoClientConfig('postgres://brian:pw@boom:381/lala')
117+
const clientConfig = parseIntoClientConfig('gaussdb://brian:pw@boom:381/lala')
118118

119119
clientConfig.user?.should.equal('brian')
120120
clientConfig.password?.should.equal('pw')

0 commit comments

Comments
 (0)