Skip to content

Commit

Permalink
Don't store redundant properties on connections that use `connectStri…
Browse files Browse the repository at this point in the history
…ng` (#1088)

* Drop `port` and `askForPassword` when saving `connectString` connections

* Add test connection for MySQL ConnectionString schema

* Fix incorrect formatting of connection's JSON readback
  • Loading branch information
gjsjohnmurray authored Jan 6, 2023
1 parent 8f8542e commit c83a4b7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/driver.mssql/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export async function activate(extContext: ExtensionContext): Promise<IDriverExt
propsToRemove.push('askForPassword');
}
}
if (connInfo.connectString) {
propsToRemove.push('port');
propsToRemove.push('askForPassword');
}
propsToRemove.forEach(p => delete connInfo[p]);

return connInfo;
Expand Down
4 changes: 4 additions & 0 deletions packages/driver.mysql/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export async function activate(extContext: vscode.ExtensionContext): Promise<IDr
propsToRemove.push('askForPassword');
}
}
if (connInfo.connectString) {
propsToRemove.push('port');
propsToRemove.push('askForPassword');
}
propsToRemove.forEach(p => delete connInfo[p]);

return connInfo;
Expand Down
4 changes: 4 additions & 0 deletions packages/driver.pg/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export async function activate(extContext: ExtensionContext): Promise<IDriverExt
propsToRemove.push('askForPassword');
}
}
if (connInfo.connectString) {
propsToRemove.push('port');
propsToRemove.push('askForPassword');
}
propsToRemove.forEach(p => delete connInfo[p]);

connInfo.pgOptions = connInfo.pgOptions || {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ const transformCode = (code: string, language: string) => {

if (language === 'json' && typeof code === 'object') {
return JSON.stringify(code, null, 2)
.replace(/( *)(".+") *:/g, '$1<span class="key">$2</span>:')
.replace(/: *(".+")/g, ': <span class="string">$1</span>')
.replace(/: *([0-9]+(\.[0-9]+)?)/g, ': <span class="number">$1</span>')
.replace(/: *(null|true|false)/g, ': <span class="bool">$1</span>');
.replace(/( *)(".+"):/g, '$1<span class="key">$2</span>:')
.replace(/: (".+")/g, ': <span class="string">$1</span>')
.replace(/: ([0-9]+(\.[0-9]+)?)/g, ': <span class="number">$1</span>')
.replace(/: (null|true|false)/g, ': <span class="bool">$1</span>');
}
return JSON.stringify(code);
};
10 changes: 10 additions & 0 deletions test/test-vscode-sqltools.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@
"previewLimit": 50,
"server": "localhost",
"username": "sa"
},
{
"mysqlOptions": {
"authProtocol": "default"
},
"previewLimit": 50,
"server": "localhost",
"driver": "MySQL",
"name": "MySQL ConnectionString schema",
"connectString": "mysql://root:root@localhost:3307/test_db"
}
],
"sqltools.languageServerEnv": {
Expand Down

0 comments on commit c83a4b7

Please sign in to comment.