mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 13:53:59 +00:00
using sql-select instead of query-data
This commit is contained in:
@@ -136,6 +136,13 @@ module.exports = {
|
|||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
sqlSelect_meta: true,
|
||||||
|
async sqlSelect({ conid, database, select }) {
|
||||||
|
const opened = await this.ensureOpened(conid, database);
|
||||||
|
const res = await this.sendRequest(opened, { msgtype: 'sqlSelect', select });
|
||||||
|
return res;
|
||||||
|
},
|
||||||
|
|
||||||
runScript_meta: true,
|
runScript_meta: true,
|
||||||
async runScript({ conid, database, sql }) {
|
async runScript({ conid, database, sql }) {
|
||||||
console.log(`Processing script, conid=${conid}, database=${database}, sql=${sql}`);
|
console.log(`Processing script, conid=${conid}, database=${database}, sql=${sql}`);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const connectUtility = require('../utility/connectUtility');
|
|||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
const { SqlGenerator } = require('dbgate-tools');
|
const { SqlGenerator } = require('dbgate-tools');
|
||||||
const generateDeploySql = require('../shell/generateDeploySql');
|
const generateDeploySql = require('../shell/generateDeploySql');
|
||||||
|
const { dumpSqlSelect } = require('dbgate-sqltree');
|
||||||
|
|
||||||
let systemConnection;
|
let systemConnection;
|
||||||
let storedConnection;
|
let storedConnection;
|
||||||
@@ -172,6 +173,13 @@ async function handleQueryData({ msgid, sql }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleSqlSelect({ msgid, select }) {
|
||||||
|
const driver = requireEngineDriver(storedConnection);
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dumpSqlSelect(dmp, select);
|
||||||
|
return handleQueryData({ msgid, sql: dmp.s });
|
||||||
|
}
|
||||||
|
|
||||||
async function handleDriverDataCore(msgid, callMethod) {
|
async function handleDriverDataCore(msgid, callMethod) {
|
||||||
await waitConnected();
|
await waitConnected();
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
@@ -283,6 +291,7 @@ const messageHandlers = {
|
|||||||
syncModel: handleSyncModel,
|
syncModel: handleSyncModel,
|
||||||
generateDeploySql: handleGenerateDeploySql,
|
generateDeploySql: handleGenerateDeploySql,
|
||||||
loadFieldValues: handleLoadFieldValues,
|
loadFieldValues: handleLoadFieldValues,
|
||||||
|
sqlSelect: handleSqlSelect,
|
||||||
// runCommand: handleRunCommand,
|
// runCommand: handleRunCommand,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -463,7 +463,10 @@ export abstract class GridDisplay {
|
|||||||
const orderColumnName = columns[0].columnName;
|
const orderColumnName = columns[0].columnName;
|
||||||
const select: Select = {
|
const select: Select = {
|
||||||
commandType: 'select',
|
commandType: 'select',
|
||||||
from: { name, alias: 'basetbl' },
|
from: {
|
||||||
|
name: _.pick(name, ['schemaName', 'pureName']),
|
||||||
|
alias: 'basetbl',
|
||||||
|
},
|
||||||
columns: columns.map(col => ({
|
columns: columns.map(col => ({
|
||||||
exprType: 'column',
|
exprType: 'column',
|
||||||
alias: col.columnName,
|
alias: col.columnName,
|
||||||
@@ -558,8 +561,9 @@ export abstract class GridDisplay {
|
|||||||
else if (this.dialect.rowNumberOverPaging && offset > 0)
|
else if (this.dialect.rowNumberOverPaging && offset > 0)
|
||||||
select = this.getRowNumberOverSelect(select, offset, count);
|
select = this.getRowNumberOverSelect(select, offset, count);
|
||||||
else if (this.dialect.limitSelect) select.topRecords = count;
|
else if (this.dialect.limitSelect) select.topRecords = count;
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
// const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
||||||
|
// return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
getExportQuery(postprocessSelect = null) {
|
getExportQuery(postprocessSelect = null) {
|
||||||
@@ -629,8 +633,9 @@ export abstract class GridDisplay {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
// const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
||||||
|
// return sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
compileFilters(): Condition {
|
compileFilters(): Condition {
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
import { FormViewDisplay } from './FormViewDisplay';
|
import { FormViewDisplay } from './FormViewDisplay';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { GridDisplay, ChangeCacheFunc, DisplayColumn, DisplayedColumnInfo, ChangeConfigFunc } from './GridDisplay';
|
import { ChangeCacheFunc, DisplayColumn, ChangeConfigFunc } from './GridDisplay';
|
||||||
import { TableInfo, EngineDriver, ViewInfo, ColumnInfo, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
import { EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
|
||||||
import { GridConfig, GridCache, createGridCache } from './GridConfig';
|
import { GridConfig, GridCache } from './GridConfig';
|
||||||
import {
|
import { mergeConditions, Condition, OrderByExpression } from 'dbgate-sqltree';
|
||||||
Expression,
|
|
||||||
Select,
|
|
||||||
treeToSql,
|
|
||||||
dumpSqlSelect,
|
|
||||||
mergeConditions,
|
|
||||||
Condition,
|
|
||||||
OrderByExpression,
|
|
||||||
} from 'dbgate-sqltree';
|
|
||||||
import { TableGridDisplay } from './TableGridDisplay';
|
import { TableGridDisplay } from './TableGridDisplay';
|
||||||
import stableStringify from 'json-stable-stringify';
|
import stableStringify from 'json-stable-stringify';
|
||||||
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
|
||||||
@@ -160,8 +152,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
|||||||
if (!select) return null;
|
if (!select) return null;
|
||||||
|
|
||||||
select.where = mergeConditions(select.where, this.getPrimaryKeyEqualCondition());
|
select.where = mergeConditions(select.where, this.getPrimaryKeyEqualCondition());
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCountSelect() {
|
getCountSelect() {
|
||||||
@@ -183,8 +174,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
|||||||
if (!this.driver) return null;
|
if (!this.driver) return null;
|
||||||
const select = this.getCountSelect();
|
const select = this.getCountSelect();
|
||||||
if (!select) return null;
|
if (!select) return null;
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getBeforeCountQuery() {
|
getBeforeCountQuery() {
|
||||||
@@ -192,8 +182,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
|||||||
const select = this.getCountSelect();
|
const select = this.getCountSelect();
|
||||||
if (!select) return null;
|
if (!select) return null;
|
||||||
select.where = mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
select.where = mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
navigate(row) {
|
navigate(row) {
|
||||||
@@ -242,8 +231,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sql = treeToSql(this.driver, select, dumpSqlSelect);
|
return select;
|
||||||
return sql;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getChangeSetRow(row): ChangeSetRowDefinition {
|
getChangeSetRow(row): ChangeSetRowDefinition {
|
||||||
|
|||||||
@@ -14,9 +14,7 @@ export async function loadChartStructure(driver: EngineDriver, conid, database,
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const dmp = driver.createDumper();
|
const resp = await apiCall('database-connections/sql-select', { conid, database, select });
|
||||||
dumpSqlSelect(dmp, select);
|
|
||||||
const resp = await apiCall('database-connections/query-data', { conid, database, sql: dmp.s });
|
|
||||||
if (resp.errorMessage) throw new Error(resp.errorMessage);
|
if (resp.errorMessage) throw new Error(resp.errorMessage);
|
||||||
return resp.columns.map(x => x.columnName);
|
return resp.columns.map(x => x.columnName);
|
||||||
}
|
}
|
||||||
@@ -72,9 +70,7 @@ export async function loadChartData(driver: EngineDriver, conid, database, sql,
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const dmp = driver.createDumper();
|
const resp = await apiCall('database-connections/sql-select', { conid, database, select });
|
||||||
dumpSqlSelect(dmp, select);
|
|
||||||
const resp = await apiCall('database-connections/query-data', { conid, database, sql: dmp.s });
|
|
||||||
let { rows, columns, errorMessage } = resp;
|
let { rows, columns, errorMessage } = resp;
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
throw new Error(errorMessage);
|
throw new Error(errorMessage);
|
||||||
|
|||||||
@@ -30,12 +30,12 @@
|
|||||||
async function loadDataPage(props, offset, limit) {
|
async function loadDataPage(props, offset, limit) {
|
||||||
const { display, conid, database } = props;
|
const { display, conid, database } = props;
|
||||||
|
|
||||||
const sql = display.getPageQuery(offset, limit);
|
const select = display.getPageQuery(offset, limit);
|
||||||
|
|
||||||
const response = await apiCall('database-connections/query-data', {
|
const response = await apiCall('database-connections/sql-select', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql,
|
select,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
@@ -44,19 +44,19 @@
|
|||||||
|
|
||||||
function dataPageAvailable(props) {
|
function dataPageAvailable(props) {
|
||||||
const { display } = props;
|
const { display } = props;
|
||||||
const sql = display.getPageQuery(0, 1);
|
const select = display.getPageQuery(0, 1);
|
||||||
return !!sql;
|
return !!select;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadRowCount(props) {
|
async function loadRowCount(props) {
|
||||||
const { display, conid, database } = props;
|
const { display, conid, database } = props;
|
||||||
|
|
||||||
const sql = display.getCountQuery();
|
const select = display.getCountQuery();
|
||||||
|
|
||||||
const response = await apiCall('database-connections/query-data', {
|
const response = await apiCall('database-connections/sql-select', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql,
|
select,
|
||||||
});
|
});
|
||||||
|
|
||||||
return parseInt(response.rows[0].count);
|
return parseInt(response.rows[0].count);
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
async function loadRow(props, sql) {
|
async function loadRow(props, select) {
|
||||||
const { conid, database } = props;
|
const { conid, database } = props;
|
||||||
|
|
||||||
if (!sql) return null;
|
if (!select) return null;
|
||||||
|
|
||||||
const response = await apiCall('database-connections/query-data', {
|
const response = await apiCall('database-connections/sql-select', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql,
|
select,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.errorMessage) return response;
|
if (response.errorMessage) return response;
|
||||||
|
|||||||
@@ -99,14 +99,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
dumpSqlSelect(dmp, select);
|
|
||||||
|
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
const response = await apiCall('database-connections/query-data', {
|
const response = await apiCall('database-connections/sql-select', {
|
||||||
conid,
|
conid,
|
||||||
database,
|
database,
|
||||||
sql: dmp.s,
|
select
|
||||||
});
|
});
|
||||||
|
|
||||||
rows = response.rows;
|
rows = response.rows;
|
||||||
|
|||||||
Reference in New Issue
Block a user