mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 05:03:57 +00:00
select template
This commit is contained in:
@@ -61,6 +61,10 @@
|
|||||||
label: 'SQL: CREATE TABLE',
|
label: 'SQL: CREATE TABLE',
|
||||||
sqlTemplate: 'CREATE TABLE',
|
sqlTemplate: 'CREATE TABLE',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'SQL: SELECT',
|
||||||
|
sqlTemplate: 'SELECT',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
views: [
|
views: [
|
||||||
{
|
{
|
||||||
@@ -102,6 +106,10 @@
|
|||||||
label: 'SQL: CREATE TABLE',
|
label: 'SQL: CREATE TABLE',
|
||||||
sqlTemplate: 'CREATE TABLE',
|
sqlTemplate: 'CREATE TABLE',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'SQL: SELECT',
|
||||||
|
sqlTemplate: 'SELECT',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
procedures: [
|
procedures: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,14 +2,32 @@ import { getDbCore, getConnectionInfo, getSqlObjectInfo } from './metadataLoader
|
|||||||
import sqlFormatter from 'sql-formatter';
|
import sqlFormatter from 'sql-formatter';
|
||||||
import { driverBase, findEngineDriver } from 'dbgate-tools';
|
import { driverBase, findEngineDriver } from 'dbgate-tools';
|
||||||
|
|
||||||
|
async function generateTableSql(extensions, props, dumpProc, format = false) {
|
||||||
|
const tableInfo = await getDbCore(props, props.objectTypeField || 'tables');
|
||||||
|
const connection = await getConnectionInfo(props);
|
||||||
|
const driver = findEngineDriver(connection, extensions) || driverBase;
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
if (tableInfo) dumpProc(dmp, tableInfo);
|
||||||
|
return format ? sqlFormatter.format(dmp.s) : dmp.s;
|
||||||
|
}
|
||||||
|
|
||||||
export default async function applySqlTemplate(sqlTemplate, extensions, props) {
|
export default async function applySqlTemplate(sqlTemplate, extensions, props) {
|
||||||
if (sqlTemplate == 'CREATE TABLE') {
|
if (sqlTemplate == 'CREATE TABLE') {
|
||||||
const tableInfo = await getDbCore(props, props.objectTypeField || 'tables');
|
return generateTableSql(extensions, props, (dmp, tableInfo) => dmp.createTable(tableInfo));
|
||||||
const connection = await getConnectionInfo(props);
|
}
|
||||||
const driver = findEngineDriver(connection, extensions) || driverBase;
|
if (sqlTemplate == 'SELECT') {
|
||||||
const dmp = driver.createDumper();
|
return generateTableSql(
|
||||||
if (tableInfo) dmp.createTable(tableInfo);
|
extensions,
|
||||||
return dmp.s;
|
props,
|
||||||
|
(dmp, tableInfo) => {
|
||||||
|
dmp.put(
|
||||||
|
'^select %,i ^from %f',
|
||||||
|
tableInfo.columns.map(x => x.columnName),
|
||||||
|
tableInfo
|
||||||
|
);
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (sqlTemplate == 'CREATE OBJECT') {
|
if (sqlTemplate == 'CREATE OBJECT') {
|
||||||
const objectInfo = await getSqlObjectInfo(props);
|
const objectInfo = await getSqlObjectInfo(props);
|
||||||
|
|||||||
Reference in New Issue
Block a user