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
2 changes: 2 additions & 0 deletions src/model/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export interface IConnection {
readonly database?: string;
multipleStatements?: boolean;
readonly certPath: string;
readonly connectionName: string;

}
8 changes: 5 additions & 3 deletions src/model/connectionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import { INode } from "./INode";
export class ConnectionNode implements INode {
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) {
private readonly certPath: string, private readonly connectionName: string) {
}

public getTreeItem(): vscode.TreeItem {
return {
label: this.host,
label: this.connectionName || this.host,
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue: "connection",
iconPath: path.join(__filename, "..", "..", "..", "resources", "server.png"),
Expand All @@ -34,12 +34,13 @@ export class ConnectionNode implements INode {
password: this.password,
port: this.port,
certPath: this.certPath,
connectionName: this.connectionName,
});

return Utility.queryPromise<any[]>(connection, "SHOW DATABASES")
.then((databases) => {
return databases.map<DatabaseNode>((database) => {
return new DatabaseNode(this.host, this.user, this.password, this.port, database.Database, this.certPath);
return new DatabaseNode(this.host, this.user, this.password, this.port, database.Database, this.certPath, this.connectionName);
});
})
.catch((err) => {
Expand All @@ -57,6 +58,7 @@ export class ConnectionNode implements INode {
password: this.password,
port: this.port,
certPath: this.certPath,
connectionName: this.connectionName,
};
}

Expand Down
6 changes: 4 additions & 2 deletions src/model/databaseNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TableNode } from "./tableNode";
export class DatabaseNode implements INode {
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) {
private readonly certPath: string, private readonly connectionName: string) {
}

public getTreeItem(): vscode.TreeItem {
Expand All @@ -32,12 +32,13 @@ export class DatabaseNode implements INode {
port: this.port,
database: this.database,
certPath: this.certPath,
connectionName: this.connectionName,
});

return Utility.queryPromise<any[]>(connection, `SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = '${this.database}' 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);
return new TableNode(this.host, this.user, this.password, this.port, this.database, table.TABLE_NAME, this.certPath, this.connectionName);
});
})
.catch((err) => {
Expand All @@ -56,6 +57,7 @@ export class DatabaseNode implements INode {
port: this.port,
database: this.database,
certPath: this.certPath,
connectionName: this.connectionName,
};
}
}
4 changes: 3 additions & 1 deletion src/model/tableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { INode } from "./INode";
export class TableNode implements INode {
constructor(private readonly host: string, private readonly user: string, private readonly password: string,
private readonly port: string, private readonly database: string, private readonly table: string,
private readonly certPath: string) {
private readonly certPath: string, private readonly connectionName: string) {
}

public getTreeItem(): vscode.TreeItem {
Expand All @@ -32,6 +32,7 @@ export class TableNode implements INode {
port: this.port,
database: this.database,
certPath: this.certPath,
connectionName: this.connectionName,
});

return Utility.queryPromise<any[]>(connection, `SELECT * FROM information_schema.columns WHERE table_schema = '${this.database}' AND table_name = '${this.table}';`)
Expand All @@ -57,6 +58,7 @@ export class TableNode implements INode {
port: this.port,
database: this.database,
certPath: this.certPath,
connectionName: this.connectionName,
};
Global.activeConnection = connection;

Expand Down
9 changes: 8 additions & 1 deletion src/mysqlTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ export class MySQLTreeDataProvider implements vscode.TreeDataProvider<INode> {
connections = {};
}

const connectionName = await vscode.window.showInputBox({ prompt: "[Optional] Name of connection.", placeHolder: "If you have multiple connection with same host", ignoreFocusOut: true });
if (connectionName === undefined) {
return;
}

const id = uuidv1();
connections[id] = {
host,
user,
port,
certPath,
connectionName,
};

if (password) {
Expand All @@ -86,14 +92,15 @@ export class MySQLTreeDataProvider implements vscode.TreeDataProvider<INode> {
if (connections) {
for (const id of Object.keys(connections)) {
const password = await Global.keytar.getPassword(Constants.ExtensionId, id);
ConnectionNodes.push(new ConnectionNode(id, connections[id].host, connections[id].user, password, connections[id].port, connections[id].certPath));
ConnectionNodes.push(new ConnectionNode(id, connections[id].host, connections[id].user, password, connections[id].port, connections[id].certPath, connections[id].connectionName));
if (!Global.activeConnection) {
Global.activeConnection = {
host: connections[id].host,
user: connections[id].user,
password,
port: connections[id].port,
certPath: connections[id].certPath,
connectionName: connections[id].connectionName,
};
}
}
Expand Down