Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
"command": "mysql.selectTop1000",
"title": "Select Top 1000",
"category": "MySQL"
},
{
"command": "mysql.keywordFilter",
"title": "Filter",
"category": "MySQL"
}
],
"keybindings": [
Expand Down Expand Up @@ -109,6 +114,11 @@
"when": "view == mysql && viewItem == connection",
"group": "mysql@2"
},
{
"command": "mysql.keywordFilter",
"when": "view == mysql && viewItem == connection",
"group": "mysql@2"
},
{
"command": "mysql.newQuery",
"when": "view == mysql && viewItem == database",
Expand All @@ -119,6 +129,11 @@
"when": "view == mysql && viewItem == database",
"group": "mysql@1"
},
{
"command": "mysql.keywordFilter",
"when": "view == mysql && viewItem == database",
"group": "mysql@2"
},
{
"command": "mysql.selectTop1000",
"when": "view == mysql && viewItem == table",
Expand Down
Binary file added resources/b_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export function activate(context: vscode.ExtensionContext) {
mysqlTreeDataProvider.addConnection();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.keywordFilter", (databaseOrConnectionNode: DatabaseNode | ConnectionNode) => {
mysqlTreeDataProvider.keywordFilter(databaseOrConnectionNode);
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.deleteConnection", (connectionNode: ConnectionNode) => {
connectionNode.deleteConnection(context, mysqlTreeDataProvider);
}));
Expand Down
6 changes: 4 additions & 2 deletions src/model/connectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { InfoNode } from "./infoNode";
import { INode } from "./INode";

export class ConnectionNode implements INode {
public keyword;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a blank line after this


constructor(private readonly id: string, private readonly host: string, private readonly user: string,
private readonly password: string, private readonly port: string,
private readonly certPath: string) {
Expand All @@ -23,7 +25,7 @@ export class ConnectionNode implements INode {
label: this.host,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue: "connection",
iconPath: path.join(__filename, "..", "..", "..", "resources", "server.png"),
iconPath: path.join(__filename, "..", "..", "..", "resources", this.keyword ? "b_search.png" : "server.png") ,
};
}

Expand All @@ -36,7 +38,7 @@ export class ConnectionNode implements INode {
certPath: this.certPath,
});

return Utility.queryPromise<any[]>(connection, "SHOW DATABASES")
return Utility.queryPromise<any[]>(connection, "SHOW DATABASES" + (this.keyword ? ` LIKE '%${this.keyword}%'` : ""))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database name becomes blank:
image

.then((databases) => {
return databases.map<DatabaseNode>((database) => {
return new DatabaseNode(this.host, this.user, this.password, this.port, database.Database, this.certPath);
Expand Down
9 changes: 6 additions & 3 deletions src/model/databaseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as vscode from "vscode";
import { AppInsightsClient } from "../common/appInsightsClient";
import { Global } from "../common/global";
import { Utility } from "../common/utility";
import { MySQLTreeDataProvider } from "../mysqlTreeDataProvider";
import { InfoNode } from "./infoNode";
import { INode } from "./INode";
import { TableNode } from "./tableNode";

export class DatabaseNode implements INode {
public keyword;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a blank line after this


constructor(private readonly host: string, private readonly user: string,
private readonly password: string, private readonly port: string, private readonly database: string,
private readonly certPath: string) {
Expand All @@ -20,7 +23,7 @@ export class DatabaseNode implements INode {
label: this.database,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue: "database",
iconPath: path.join(__filename, "..", "..", "..", "resources", "database.svg"),
iconPath: path.join(__filename, "..", "..", "..", "resources", this.keyword ? "b_search.png" : "database.svg"),
};
}

Expand All @@ -33,8 +36,8 @@ export class DatabaseNode implements INode {
database: this.database,
certPath: this.certPath,
});

return Utility.queryPromise<any[]>(connection, `SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '${this.database}' LIMIT ${Utility.maxTableCount}`)
const filter = this.keyword ? `TABLE_NAME LIKE '%${this.keyword}%'` : "";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Miss AND

return Utility.queryPromise<any[]>(connection, `SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '${this.database}' ${filter} LIMIT ${Utility.maxTableCount}`)
.then((tables) => {
return tables.map<TableNode>((table) => {
return new TableNode(this.host, this.user, this.password, this.port, this.database, table.TABLE_NAME, this.certPath);
Expand Down
14 changes: 14 additions & 0 deletions src/mysqlTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Constants } from "./common/constants";
import { Global } from "./common/global";
import { IConnection } from "./model/connection";
import { ConnectionNode } from "./model/connectionNode";
import { DatabaseNode } from "./model/databaseNode";
import { INode } from "./model/INode";

export class MySQLTreeDataProvider implements vscode.TreeDataProvider<INode> {
Expand Down Expand Up @@ -76,6 +77,19 @@ export class MySQLTreeDataProvider implements vscode.TreeDataProvider<INode> {
AppInsightsClient.sendEvent("addConnection.end");
}

public async keywordFilter(node: DatabaseNode | ConnectionNode) {
vscode.window.showInputBox({
prompt: "" , placeHolder: "keyword", value: node.keyword,
validateInput: (keyword: string) => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It this by design? It will trigger this.refresh(node) every time user input or delete a character. For the better practice, it should be only trigger when user press Enter

if (node.keyword !== keyword) {
node.keyword = keyword;
this.refresh(node);
}
return "";
},
});
}

public refresh(element?: INode): void {
this._onDidChangeTreeData.fire(element);
}
Expand Down