load field values logic moved to backend

This commit is contained in:
Jan Prochazka
2022-03-17 08:40:09 +01:00
parent 074a75075d
commit 5c4794deae
7 changed files with 98 additions and 108 deletions

View File

@@ -26,6 +26,7 @@
"devDependencies": {
"@types/node": "^13.7.0",
"dbgate-types": "^4.1.1",
"dbgate-sqltree": "^4.1.1",
"jest": "^24.9.0",
"ts-jest": "^25.2.1",
"typescript": "^4.4.3"

View File

@@ -1,5 +1,7 @@
import _compact from 'lodash/compact'
import { SqlDumper } from './SqlDumper';
import { splitQuery } from 'dbgate-query-splitter';
import { dumpSqlSelect } from 'dbgate-sqltree';
const dialect = {
limitSelect: true,
@@ -51,4 +53,56 @@ export const driverBase = {
}
return [];
},
async loadFieldValues(pool, name, columnName, search) {
const dmp = this.createDumper();
const select = {
commandType: 'select',
distinct: true,
topRecords: 100,
from: {
name,
},
columns: [
{
exprType: 'column',
columnName,
alias: 'value',
},
],
orderBy: [
{
exprType: 'column',
columnName,
},
],
};
if (search) {
const tokens = _compact(search.split(' ').map(x => x.trim()));
if (tokens.length > 0) {
// @ts-ignore
select.where = {
conditionType: 'and',
conditions: tokens.map(token => ({
conditionType: 'like',
left: {
exprType: 'column',
columnName,
},
right: {
exprType: 'value',
value: `%${token}%`,
},
})),
};
}
}
// @ts-ignore
dumpSqlSelect(dmp, select);
const resp = await this.query(pool, dmp.s);
return resp.rows;
},
};