Skip to content

Commit

Permalink
feat: Add JSON parameter support for MSSQL connection (#5200)
Browse files Browse the repository at this point in the history
Co-authored-by: k144 <k144@debian-BULLSEYE-live-builder-AMD64>
  • Loading branch information
ByteOPCode and k144 committed May 29, 2022
1 parent 8bb9e83 commit 8a50dd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/knex-builder/internal/parse-connection.js
Expand Up @@ -69,8 +69,10 @@ function connectionObject(parsed) {
}
if (parsed.searchParams) {
for (const [key, value] of parsed.searchParams.entries()) {
const isMySQLLike = ['mysql:', 'mariadb:'].includes(parsed.protocol);
if (isMySQLLike) {
const isNestedConfigSupported = ['mysql:', 'mariadb:', 'mssql:'].includes(
parsed.protocol
);
if (isNestedConfigSupported) {
try {
connection[key] = JSON.parse(value);
} catch (err) {
Expand Down
24 changes: 24 additions & 0 deletions test/tape/parse-connection.js
Expand Up @@ -311,3 +311,27 @@ test('#4628, supports mysql / mariadb client JSON parameters', function (t) {
}
);
});

test('support MSSQL JSON parameters for config object', function (t) {
t.plan(1);
t.deepLooseEqual(
parseConnection(
'mssql://user:password@host/database?domain=testDomain&options={"instanceName": "TestInstance001", "readOnlyIntent": true}'
),

{
client: 'mssql',
connection: {
server: 'host',
user: 'user',
password: 'password',
database: 'database',
domain: 'testDomain',
options: {
instanceName: 'TestInstance001',
readOnlyIntent: true,
},
},
}
);
});

0 comments on commit 8a50dd7

Please sign in to comment.