Skip to content

Commit

Permalink
Support for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Apr 20, 2024
1 parent 50c52be commit 24f3c8d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"${workspaceFolder}/test/project.code-workspace",
"--extensionDevelopmentPath=${workspaceFolder}"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
"${workspaceFolder}/dist/**/*.js"
],
"preLaunchTask": "npm: webpack"
}
Expand Down
9 changes: 9 additions & 0 deletions connection.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"title": "Show system items?",
"type": "boolean",
"default": false
},
"filter": {
"title": "Filter",
"type": "string",
"examples": [
"'Ens*",
"'HS*"
],
"description": "* 0 or more characters, _ any one character, ' NOT pattern"
}
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"mtxr.sqltools"
],
"activationEvents": [
"*",
"onStartupFinished",
"onLanguage:sql",
"onCommand:sqltools.*"
],
Expand Down
8 changes: 6 additions & 2 deletions src/ls/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im

queries: IQueries = queries;
private showSystem = false;
private filter = "";

public async open() {
if (this.connection) {
Expand All @@ -22,6 +23,7 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
const { namespace } = this.credentials;
let config: IRISDirect;
this.showSystem = this.credentials.showSystem || false;
this.filter = this.credentials.filter || "";

if (this.credentials.serverName) {
throw new Error("not supported");
Expand Down Expand Up @@ -113,6 +115,7 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im

private async getSchemas({ item }: Arg0<IConnectionDriver['getChildrenForItem']>) {
item['showSystem'] = this.showSystem;
item['filter'] = this.filter;

switch (item.childType) {
case ContextValue.TABLE:
Expand All @@ -127,6 +130,7 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im

private async getChildrenForSchema({ item }: Arg0<IConnectionDriver['getChildrenForItem']>) {
item['showSystem'] = this.showSystem;
item['filter'] = this.filter;

switch (item.childType) {
case ContextValue.TABLE:
Expand All @@ -151,11 +155,11 @@ export default class IRISDriver extends AbstractDriver<IRISdb, DriverOptions> im
case ContextValue.DATABASE:
// Syntatically, a schema in IRIS SQL resembles a database in other databases.
// That's the simplest way to adapt IRIS SQL to the generic Hue parser vscode-sqltools uses.
return this.queryResults(this.queries.searchEverything({ search, showSystem: this.showSystem }));
return this.queryResults(this.queries.searchEverything({ search, showSystem: this.showSystem, filter: this.filter }));
case ContextValue.TABLE:
case ContextValue.FUNCTION:
case ContextValue.VIEW:
const searchParams = { search, showSystem: this.showSystem, itemType, ...extraParams };
const searchParams = { search, showSystem: this.showSystem, filter: this.filter, itemType, ...extraParams };
if (extraParams['database']) {
searchParams['schema'] = extraParams['database'];
}
Expand Down
3 changes: 2 additions & 1 deletion src/ls/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ValueColumn[ContextValue.FUNCTION] = "PROCEDURE_NAME";

interface ISchema extends NSDatabase.ISchema {
showSystem: boolean;
filter: string;
}

const describeTable: IQueries['describeTable'] = queryFactory`
Expand Down Expand Up @@ -173,7 +174,7 @@ DISTINCT BY(SCHEMA_NAME)
'${ContextValue.SCHEMA}' as "type",
'${type}' as "childType",
'folder' as iconId
FROM ${Functions[type]} (${p => p.showSystem ? 1 : 0})
FROM ${Functions[type]} (${p => p.showSystem ? 1 : 0}, '${p => (p.filter && p.filter != "") ? `${p.filter.replace("'", "''")}` : "*"}')
`;

const fetchTableSchemas = fetchTypedSchemas(ContextValue.TABLE);
Expand Down
14 changes: 8 additions & 6 deletions test/project.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@
"username": "_SYSTEM"
},
{
"askForPassword": false,
"namespace": "USER",
"connectionMethod": "Server and Port",
"showSystem": false,
"filter": "'Ens*",
"previewLimit": 50,
"server": "localhost",
"port": 52773,
"https": false,
"askForPassword": false,
"driver": "InterSystems IRIS",
"name": "InterSystems IRIS",
"namespace": "USER",
"password": "SYS",
"port": 52773,
"previewLimit": 50,
"server": "localhost",
"showSystem": true,
"username": "_SYSTEM"
}
]
Expand Down

0 comments on commit 24f3c8d

Please sign in to comment.