mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 20:46:01 +00:00
load field values logic moved to backend
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user