mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-02 03:13:58 +00:00
new object templates (generic+mssql)
This commit is contained in:
@@ -40,4 +40,10 @@ export const driverBase = {
|
|||||||
await this.query(pool, sqlItem, { discardResult: true });
|
await this.query(pool, sqlItem, { discardResult: true });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getNewObjectTemplates() {
|
||||||
|
if (!this.dialect?.nosql) {
|
||||||
|
return [{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' }];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
6
packages/types/engines.d.ts
vendored
6
packages/types/engines.d.ts
vendored
@@ -37,6 +37,11 @@ export interface ReadCollectionOptions {
|
|||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NewObjectTemplate {
|
||||||
|
label: string;
|
||||||
|
sql: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EngineDriver {
|
export interface EngineDriver {
|
||||||
engine: string;
|
engine: string;
|
||||||
title: string;
|
title: string;
|
||||||
@@ -81,6 +86,7 @@ export interface EngineDriver {
|
|||||||
createDatabase(pool: any, name: string): Promise;
|
createDatabase(pool: any, name: string): Promise;
|
||||||
getQuerySplitterOptions(usage: 'stream' | 'script'): any;
|
getQuerySplitterOptions(usage: 'stream' | 'script'): any;
|
||||||
script(pool: any, sql: string): Promise;
|
script(pool: any, sql: string): Promise;
|
||||||
|
getNewObjectTemplates(): NewObjectTemplate[];
|
||||||
|
|
||||||
analyserClass?: any;
|
analyserClass?: any;
|
||||||
dumperClass?: any;
|
dumperClass?: any;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
import CloseSearchButton from '../elements/CloseSearchButton.svelte';
|
import CloseSearchButton from '../elements/CloseSearchButton.svelte';
|
||||||
import { findEngineDriver } from 'dbgate-tools';
|
import { findEngineDriver } from 'dbgate-tools';
|
||||||
import { extensions } from '../stores';
|
import { extensions } from '../stores';
|
||||||
|
import newQuery from '../query/newQuery';
|
||||||
|
|
||||||
export let conid;
|
export let conid;
|
||||||
export let database;
|
export let database;
|
||||||
@@ -64,11 +65,24 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function createAddMenu() {
|
function createAddMenu() {
|
||||||
|
const res = [];
|
||||||
if (driver?.dialect?.nosql) {
|
if (driver?.dialect?.nosql) {
|
||||||
return [{ label: 'New collection', command: 'new.collection' }];
|
res.push({ command: 'new.collection' });
|
||||||
} else {
|
} else {
|
||||||
return [{ label: 'New table', command: 'new.table' }];
|
res.push({ command: 'new.table' });
|
||||||
}
|
}
|
||||||
|
if (driver)
|
||||||
|
res.push(
|
||||||
|
...driver.getNewObjectTemplates().map(tpl => ({
|
||||||
|
text: tpl.label,
|
||||||
|
onClick: () => {
|
||||||
|
newQuery({
|
||||||
|
initialData: tpl.sql,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,15 @@ const driver = {
|
|||||||
title: 'Microsoft SQL Server',
|
title: 'Microsoft SQL Server',
|
||||||
defaultPort: 1433,
|
defaultPort: 1433,
|
||||||
defaultAuthTypeName: 'tedious',
|
defaultAuthTypeName: 'tedious',
|
||||||
|
|
||||||
|
getNewObjectTemplates() {
|
||||||
|
return [
|
||||||
|
{ label: 'New view', sql: 'CREATE VIEW myview\nAS\nSELECT * FROM table1' },
|
||||||
|
{ label: 'New procedure', sql: 'CREATE PROCEDURE myproc (@arg1 INT)\nAS\nBEGIN\n SELECT * FROM table1\nEND' },
|
||||||
|
{ label: 'New function', sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS INT\nAS\nBEGIN\n RETURN 1;\nEND' },
|
||||||
|
{ label: 'New table valued function', sql: 'CREATE FUNCTION myfunc (@arg1 INT) RETURNS TABLE \nAS\nRETURN SELECT * FROM table1' },
|
||||||
|
];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = driver;
|
module.exports = driver;
|
||||||
|
|||||||
Reference in New Issue
Block a user