using sql-select instead of query-data

This commit is contained in:
Jan Prochazka 2022-03-17 10:32:57 +01:00
parent 0d7bfd5f90
commit 9c7a130ee4
8 changed files with 50 additions and 48 deletions

View File

@ -136,6 +136,13 @@ module.exports = {
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,
async runScript({ conid, database, sql }) {
console.log(`Processing script, conid=${conid}, database=${database}, sql=${sql}`);

View File

@ -7,6 +7,7 @@ const connectUtility = require('../utility/connectUtility');
const { handleProcessCommunication } = require('../utility/processComm');
const { SqlGenerator } = require('dbgate-tools');
const generateDeploySql = require('../shell/generateDeploySql');
const { dumpSqlSelect } = require('dbgate-sqltree');
let systemConnection;
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) {
await waitConnected();
const driver = requireEngineDriver(storedConnection);
@ -283,6 +291,7 @@ const messageHandlers = {
syncModel: handleSyncModel,
generateDeploySql: handleGenerateDeploySql,
loadFieldValues: handleLoadFieldValues,
sqlSelect: handleSqlSelect,
// runCommand: handleRunCommand,
};

View File

@ -463,7 +463,10 @@ export abstract class GridDisplay {
const orderColumnName = columns[0].columnName;
const select: Select = {
commandType: 'select',
from: { name, alias: 'basetbl' },
from: {
name: _.pick(name, ['schemaName', 'pureName']),
alias: 'basetbl',
},
columns: columns.map(col => ({
exprType: 'column',
alias: col.columnName,
@ -558,8 +561,9 @@ export abstract class GridDisplay {
else if (this.dialect.rowNumberOverPaging && offset > 0)
select = this.getRowNumberOverSelect(select, offset, count);
else if (this.dialect.limitSelect) select.topRecords = count;
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
// const sql = treeToSql(this.driver, select, dumpSqlSelect);
// return sql;
}
getExportQuery(postprocessSelect = null) {
@ -629,8 +633,9 @@ export abstract class GridDisplay {
},
];
}
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
// const sql = treeToSql(this.driver, select, dumpSqlSelect);
// return sql;
}
compileFilters(): Condition {

View File

@ -1,17 +1,9 @@
import { FormViewDisplay } from './FormViewDisplay';
import _ from 'lodash';
import { GridDisplay, ChangeCacheFunc, DisplayColumn, DisplayedColumnInfo, ChangeConfigFunc } from './GridDisplay';
import { TableInfo, EngineDriver, ViewInfo, ColumnInfo, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
import { GridConfig, GridCache, createGridCache } from './GridConfig';
import {
Expression,
Select,
treeToSql,
dumpSqlSelect,
mergeConditions,
Condition,
OrderByExpression,
} from 'dbgate-sqltree';
import { ChangeCacheFunc, DisplayColumn, ChangeConfigFunc } from './GridDisplay';
import { EngineDriver, NamedObjectInfo, DatabaseInfo } from 'dbgate-types';
import { GridConfig, GridCache } from './GridConfig';
import { mergeConditions, Condition, OrderByExpression } from 'dbgate-sqltree';
import { TableGridDisplay } from './TableGridDisplay';
import stableStringify from 'json-stable-stringify';
import { ChangeSetFieldDefinition, ChangeSetRowDefinition } from './ChangeSet';
@ -160,8 +152,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
if (!select) return null;
select.where = mergeConditions(select.where, this.getPrimaryKeyEqualCondition());
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
}
getCountSelect() {
@ -183,8 +174,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
if (!this.driver) return null;
const select = this.getCountSelect();
if (!select) return null;
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
}
getBeforeCountQuery() {
@ -192,8 +182,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
const select = this.getCountSelect();
if (!select) return null;
select.where = mergeConditions(select.where, this.getPrimaryKeyOperatorCondition('<'));
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
}
navigate(row) {
@ -242,8 +231,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
break;
}
const sql = treeToSql(this.driver, select, dumpSqlSelect);
return sql;
return select;
}
getChangeSetRow(row): ChangeSetRowDefinition {

View File

@ -14,9 +14,7 @@ export async function loadChartStructure(driver: EngineDriver, conid, database,
},
};
const dmp = driver.createDumper();
dumpSqlSelect(dmp, select);
const resp = await apiCall('database-connections/query-data', { conid, database, sql: dmp.s });
const resp = await apiCall('database-connections/sql-select', { conid, database, select });
if (resp.errorMessage) throw new Error(resp.errorMessage);
return resp.columns.map(x => x.columnName);
}
@ -72,9 +70,7 @@ export async function loadChartData(driver: EngineDriver, conid, database, sql,
],
};
const dmp = driver.createDumper();
dumpSqlSelect(dmp, select);
const resp = await apiCall('database-connections/query-data', { conid, database, sql: dmp.s });
const resp = await apiCall('database-connections/sql-select', { conid, database, select });
let { rows, columns, errorMessage } = resp;
if (errorMessage) {
throw new Error(errorMessage);

View File

@ -30,12 +30,12 @@
async function loadDataPage(props, offset, limit) {
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,
database,
sql,
select,
});
if (response.errorMessage) return response;
@ -44,19 +44,19 @@
function dataPageAvailable(props) {
const { display } = props;
const sql = display.getPageQuery(0, 1);
return !!sql;
const select = display.getPageQuery(0, 1);
return !!select;
}
async function loadRowCount(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,
database,
sql,
select,
});
return parseInt(response.rows[0].count);

View File

@ -1,13 +1,13 @@
<script lang="ts" context="module">
async function loadRow(props, sql) {
async function loadRow(props, select) {
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,
database,
sql,
select,
});
if (response.errorMessage) return response;

View File

@ -99,14 +99,11 @@
}
}
// @ts-ignore
dumpSqlSelect(dmp, select);
isLoading = true;
const response = await apiCall('database-connections/query-data', {
const response = await apiCall('database-connections/sql-select', {
conid,
database,
sql: dmp.s,
select
});
rows = response.rows;