feat: Add JSON parameter support for MSSQL connection (#5200)

Co-authored-by: k144 <k144@debian-BULLSEYE-live-builder-AMD64>
This commit is contained in:
ByteOPCode 2022-05-29 07:07:07 +01:00 committed by GitHub
parent 8bb9e830ff
commit 8a50dd7462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -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) {

View File

@ -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,
},
},
}
);
});