Skip to content

Commit 869e487

Browse files
committed
* Supported parsing of database name from connection string URI path
1 parent e69582c commit 869e487

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
env:
5252
OS: ${{ matrix.os }}
5353
GO: ${{ matrix.go-version }}
54-
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
54+
YDB_CONNECTION_STRING: grpcs://localhost:2135/local
5555
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
5656
YDB_SHUTDOWN_URLS: http://localhost:8765/actors/kqp_proxy?force_shutdown=all
5757
HIDE_APPLICATION_OUTPUT: 1
@@ -94,7 +94,7 @@ jobs:
9494
env:
9595
OS: ${{ matrix.os }}
9696
GO: ${{ matrix.go-version }}
97-
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
97+
YDB_CONNECTION_STRING: grpcs://localhost:2135/local
9898
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
9999
runs-on: ${{ matrix.os }}
100100
steps:
@@ -136,7 +136,7 @@ jobs:
136136
env:
137137
OS: ${{ matrix.os }}
138138
GO: ${{ matrix.go-version }}
139-
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
139+
YDB_CONNECTION_STRING: grpcs://localhost:2135/local
140140
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
141141
runs-on: ${{ matrix.os }}
142142
steps:
@@ -177,7 +177,7 @@ jobs:
177177
env:
178178
OS: ${{ matrix.os }}
179179
GO: ${{ matrix.go-version }}
180-
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
180+
YDB_CONNECTION_STRING: grpcs://localhost:2135/local
181181
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
182182
runs-on: ${{ matrix.os }}
183183
steps:
@@ -218,7 +218,7 @@ jobs:
218218
env:
219219
OS: ${{ matrix.os }}
220220
GO: ${{ matrix.go-version }}
221-
YDB_CONNECTION_STRING: grpcs://localhost:2135/?database=/local
221+
YDB_CONNECTION_STRING: grpcs://localhost:2135/local
222222
YDB_SSL_ROOT_CERTIFICATES_FILE: /tmp/ydb_certs/ca.pem
223223
runs-on: ${{ matrix.os }}
224224
steps:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Supported parsing of database name from connection string URI path
12
* Added `options.WithExecuteScanQueryStats` option
23
* Added to query stats plan and AST
34
* Changed behaviour of `result.Stats()` (if query result have no stats - returns `nil`)

internal/dsn/dsn.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
var (
1212
parsers = map[string]Parser{
13+
// for compatibility with old connection string format
1314
"database": func(database string) ([]config.Option, error) {
1415
return []config.Option{
1516
config.WithDatabase(database),
@@ -40,6 +41,7 @@ func Parse(dsn string) (options []config.Option, err error) {
4041
options,
4142
config.WithEndpoint(uri.Host),
4243
config.WithSecure(uri.Scheme != insecureSchema),
44+
config.WithDatabase(uri.Path),
4345
)
4446
for param, values := range uri.Query() {
4547
if p, has := parsers[param]; has {

internal/dsn/dsn_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ func TestParseConnectionString(t *testing.T) {
3535
"/ru/home/gvit/mydb",
3636
"123",
3737
},
38+
{
39+
"grpc://ydb-ru.yandex.net:2135/ru/home/gvit/mydb?token=123",
40+
false,
41+
"ydb-ru.yandex.net:2135",
42+
"/ru/home/gvit/mydb",
43+
"123",
44+
},
3845
{
3946
"grpcs://ydb.serverless.yandexcloud.net:2135/?" +
4047
"database=/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1&token=123",
@@ -43,6 +50,22 @@ func TestParseConnectionString(t *testing.T) {
4350
"/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1",
4451
"123",
4552
},
53+
{
54+
"grpcs://ydb.serverless.yandexcloud.net:2135" +
55+
"/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1?token=123",
56+
true,
57+
"ydb.serverless.yandexcloud.net:2135",
58+
"/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1",
59+
"123",
60+
},
61+
{
62+
"grpcs://ydb.serverless.yandexcloud.net:2135" +
63+
"/ru-central1/b1g8skpblkos03malf3s/etn02qso4v3isjb00te1?database=/ru/home/gvit/mydb&token=123",
64+
true,
65+
"ydb.serverless.yandexcloud.net:2135",
66+
"/ru/home/gvit/mydb",
67+
"123",
68+
},
4669
{
4770
"grpcs://lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135/?" +
4871
"database=/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv&token=123",
@@ -51,13 +74,28 @@ func TestParseConnectionString(t *testing.T) {
5174
"/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv",
5275
"123",
5376
},
77+
{
78+
"grpcs://lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135" +
79+
"/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv?token=123",
80+
true,
81+
"lb.etn03r9df42nb631unbv.ydb.mdb.yandexcloud.net:2135",
82+
"/ru-central1/b1g8skpblkos03malf3s/etn03r9df42nb631unbv",
83+
"123",
84+
},
5485
{
5586
"abcd://ydb-ru.yandex.net:2135/?database=/ru/home/gvit/mydb",
5687
true,
5788
"ydb-ru.yandex.net:2135",
5889
"/ru/home/gvit/mydb",
5990
"",
6091
},
92+
{
93+
"abcd://ydb-ru.yandex.net:2135/ru/home/gvit/mydb",
94+
true,
95+
"ydb-ru.yandex.net:2135",
96+
"/ru/home/gvit/mydb",
97+
"",
98+
},
6199
} {
62100
t.Run(test.connectionString, func(t *testing.T) {
63101
options, err := Parse(test.connectionString)

0 commit comments

Comments
 (0)