diff --git a/packages/web/src/query/codeCompletion.ts b/packages/web/src/query/codeCompletion.ts index 12dcc85d4..889beed55 100644 --- a/packages/web/src/query/codeCompletion.ts +++ b/packages/web/src/query/codeCompletion.ts @@ -47,11 +47,15 @@ export function mountCodeCompletion({ conid, database, editor }) { const sources = analyseQuerySources(editor.getValue(), [ ...dbinfo.tables.map(x => x.pureName), ...dbinfo.views.map(x => x.pureName), + ...dbinfo.matviews.map(x => x.pureName), + // ...dbinfo.functions.map(x => x.pureName), + // ...dbinfo.procedures.map(x => x.pureName), ]); const sourceObjects = sources.map(src => { const table = dbinfo.tables.find(x => x.pureName == src.name); const view = dbinfo.views.find(x => x.pureName == src.name); - return { ...(table || view), alias: src.alias }; + const matview = dbinfo.matviews.find(x => x.pureName == src.name); + return { ...(table || view || matview), alias: src.alias }; }); if (colMatch) { @@ -74,7 +78,7 @@ export function mountCodeCompletion({ conid, database, editor }) { ]; } - const view = dbinfo.views.find(x => x.pureName == source.name); + const view = [...(dbinfo.views || []), ...(dbinfo.matviews || [])].find(x => x.pureName == source.name); if (view) { list = [ ...view.columns.map(x => ({ @@ -90,36 +94,68 @@ export function mountCodeCompletion({ conid, database, editor }) { } else { const onlyTables = lastKeyword == 'FROM' || lastKeyword == 'JOIN' || lastKeyword == 'UPDATE' || lastKeyword == 'DELETE'; - list = [ - ...(onlyTables ? [] : list), - ...dbinfo.tables.map(x => ({ + const onlyProcedures = lastKeyword == 'EXEC' || lastKeyword == 'EXECUTE' || lastKeyword == 'CALL'; + if (onlyProcedures) { + list = dbinfo.procedures.map(x => ({ name: x.pureName, value: x.pureName, caption: x.pureName, - meta: 'table', + meta: 'procedure', score: 1000, - })), - ...dbinfo.views.map(x => ({ - name: x.pureName, - value: x.pureName, - caption: x.pureName, - meta: 'view', - score: 1000, - })), - ...(onlyTables - ? [] - : _.flatten( - sourceObjects.map(obj => - obj.columns.map(col => ({ - name: col.columnName, - value: obj.alias ? `${obj.alias}.${col.columnName}` : col.columnName, - caption: obj.alias ? `${obj.alias}.${col.columnName}` : col.columnName, - meta: 'column', - score: 1200, - })) - ) - )), - ]; + })); + } else { + list = [ + ...(onlyTables ? [] : list), + ...dbinfo.tables.map(x => ({ + name: x.pureName, + value: x.pureName, + caption: x.pureName, + meta: 'table', + score: 1000, + })), + ...dbinfo.views.map(x => ({ + name: x.pureName, + value: x.pureName, + caption: x.pureName, + meta: 'view', + score: 1000, + })), + ...dbinfo.matviews.map(x => ({ + name: x.pureName, + value: x.pureName, + caption: x.pureName, + meta: 'matview', + score: 1000, + })), + ...dbinfo.functions.map(x => ({ + name: x.pureName, + value: x.pureName, + caption: x.pureName, + meta: 'function', + score: 1000, + })), + ...dbinfo.procedures.map(x => ({ + name: x.pureName, + value: x.pureName, + caption: x.pureName, + meta: 'procedure', + score: 1000, + })), + ...(onlyTables + ? [] + : _.flatten( + sourceObjects.map(obj => + obj.columns.map(col => ({ + name: col.columnName, + value: obj.alias ? `${obj.alias}.${col.columnName}` : col.columnName, + caption: obj.alias ? `${obj.alias}.${col.columnName}` : col.columnName, + meta: `column (${obj.pureName})`, + score: 1200, + })) + ) + )), + ]; + } } } @@ -147,7 +183,7 @@ export function mountCodeCompletion({ conid, database, editor }) { editor.execCommand('startAutocomplete'); } - if (e.args == ' ' && /((from)|(join)|(update))\s*$/i.test(line)) { + if (e.args == ' ' && /((from)|(join)|(update)|(call)|(exec)|(execute))\s*$/i.test(line)) { editor.execCommand('startAutocomplete'); } } diff --git a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js index 065434bf4..9e0cd1023 100644 --- a/plugins/dbgate-plugin-postgres/src/frontend/drivers.js +++ b/plugins/dbgate-plugin-postgres/src/frontend/drivers.js @@ -72,6 +72,7 @@ const postgresDriverBase = { getNewObjectTemplates() { return [ { label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }, + { label: 'New materialized view', sql: 'CREATE MATERIALIZED VIEW myview\nAS\nSELECT * FROM table1' }, { label: 'New procedure', sql: `CREATE PROCEDURE myproc (arg1 INT)