feat: triggers and stored routines in sql suggestions

This commit is contained in:
Fabio Di Stasio 2021-01-07 18:22:49 +01:00
parent 6e55f27b23
commit e351c903a8
2 changed files with 41 additions and 5 deletions

View File

@ -47,13 +47,40 @@ export default {
}, []).map(table => { }, []).map(table => {
return { return {
name: table.name, name: table.name,
comment: table.comment,
type: table.type, type: table.type,
fields: [] fields: []
}; };
}) })
: []; : [];
}, },
triggers () {
return this.workspace
? this.workspace.structure.filter(schema => schema.name === this.schema)
.reduce((acc, curr) => {
acc.push(...curr.triggers);
return acc;
}, []).map(trigger => {
return {
name: trigger.name,
type: 'trigger'
};
})
: [];
},
procedures () {
return this.workspace
? this.workspace.structure.filter(schema => schema.name === this.schema)
.reduce((acc, curr) => {
acc.push(...curr.procedures);
return acc;
}, []).map(procedure => {
return {
name: `${procedure.name}()`,
type: 'routine'
};
})
: [];
},
mode () { mode () {
switch (this.workspace.client) { switch (this.workspace.client) {
case 'mysql': case 'mysql':
@ -130,11 +157,14 @@ export default {
this.editor.completers.push({ this.editor.completers.push({
getCompletions: (editor, session, pos, prefix, callback) => { getCompletions: (editor, session, pos, prefix, callback) => {
const completions = []; const completions = [];
this.tables.forEach(table => { [
...this.tables,
...this.triggers,
...this.procedures
].forEach(el => {
completions.push({ completions.push({
value: table.name, value: el.name,
meta: table.type, meta: el.type
caption: table.comment
}); });
}); });
callback(null, completions); callback(null, completions);

View File

@ -1239,6 +1239,12 @@ ace.define('ace/autocomplete/popup', ['require', 'exports', 'module', 'ace/virtu
case 'view': case 'view':
iconClass = 'mdi-table-eye'; iconClass = 'mdi-table-eye';
break; break;
case 'trigger':
iconClass = 'mdi-table-cog';
break;
case 'routine':
iconClass = 'mdi-sync-circle';
break;
case 'keyword': case 'keyword':
iconClass = 'mdi-cube'; iconClass = 'mdi-cube';
break; break;