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
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@
"command": "mysql.selectTop1000",
"title": "Select Top 1000",
"category": "MySQL"
},
{
"command": "mysql.copy.names",
"title": "Copy Names",
"category": "MySQL"
},
{
"command": "mysql.copy.insert",
"title": "Copy for Insert",
"category": "MySQL"
},
{
"command": "mysql.copy.update",
"title": "Copy for Update",
"category": "MySQL"
}
],
"keybindings": [
Expand Down Expand Up @@ -124,6 +139,21 @@
"when": "view == mysql && viewItem == table",
"group": "mysql@0"
},
{
"command": "mysql.copy.names",
"when": "view == mysql && viewItem == table",
"group": "mysql@0"
},
{
"command": "mysql.copy.insert",
"when": "view == mysql && viewItem == table",
"group": "mysql@0"
},
{
"command": "mysql.copy.update",
"when": "view == mysql && viewItem == table",
"group": "mysql@0"
},
{
"command": "mysql.refresh",
"when": "view == mysql && viewItem == table",
Expand Down
12 changes: 12 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.commands.registerCommand("mysql.selectTop1000", (tableNode: TableNode) => {
tableNode.selectTop1000();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.copy.names", (tableNode: TableNode) => {
tableNode.copyNames();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.copy.insert", (tableNode: TableNode) => {
tableNode.copyInsert();
}));

context.subscriptions.push(vscode.commands.registerCommand("mysql.copy.update", (tableNode: TableNode) => {
tableNode.copyUpdate();
}));
}

export function deactivate() {
Expand Down
41 changes: 41 additions & 0 deletions src/model/tableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,45 @@ export class TableNode implements INode {

Utility.runQuery(sql, connection);
}
public copyNames() {
this
.getChildren()
.then((children: INode[]) => {
const childrenNames = children.map((child: any) => child.column.COLUMN_NAME);

OutputChannel.appendLine(`${this.database}.${this.table}`);
OutputChannel.appendLine(` ${childrenNames.toString().replace(/,/g, "\n ")}`);
OutputChannel.appendLine(``);

});
}
public copyInsert() {
this
.getChildren()
.then((children: INode[]) => {
const childrenNames = children.map((child: any) => child.column.COLUMN_NAME);

OutputChannel.appendLine(`insert into ${this.database}.${this.table}(${childrenNames.toString().replace(/,/g, ", ")})`);
OutputChannel.appendLine(`values`);
OutputChannel.appendLine(`(:${childrenNames.toString().replace(/,/g, ", :")})`);
OutputChannel.appendLine(`;`);
OutputChannel.appendLine(``);
});
}
public copyUpdate() {
this
.getChildren()
.then((children: INode[]) => {
const keysNames = children.filter((child: any) => child.column.COLUMN_KEY).map((child: any) => child.column.COLUMN_NAME);
const childrenNames = children.filter((child: any) => !child.column.COLUMN_KEY).map((child: any) => child.column.COLUMN_NAME);

const sets = childrenNames.map((name: string) => `${name} = :${name}`);
const where = keysNames.map((name: string) => `${name} = :${name}`);

OutputChannel.appendLine(`update ${this.database}.${this.table} \nset ${sets.toString().replace(/,/g, "\n , ")}`);
OutputChannel.appendLine(` where ${where.toString().replace(/,/g, "\n and ")}`);
OutputChannel.appendLine(``);
});
}

}