This commit is contained in:
Jan Prochazka 2024-08-19 13:16:13 +02:00
parent 64e770f51e
commit 12d60c7ed9
5 changed files with 21 additions and 10 deletions

View File

@ -9,7 +9,15 @@ import type {
TableInfo,
ViewInfo,
} from 'dbgate-types';
import { detectSqlFilterBehaviour, equalFullName, isCollectionInfo, isTableInfo, isViewInfo, stringFilterBehaviour } from 'dbgate-tools';
import {
detectSqlFilterBehaviour,
equalFullName,
isCollectionInfo,
isTableInfo,
isViewInfo,
mongoFilterBehaviour,
stringFilterBehaviour,
} from 'dbgate-tools';
import {
ChangePerspectiveConfigFunc,
createPerspectiveNodeConfig,
@ -346,7 +354,7 @@ export abstract class PerspectiveTreeNode {
const base = this.getBaseTableFromThis() as TableInfo | ViewInfo;
if (!base) return null;
try {
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'string');
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, stringFilterBehaviour);
if (condition) {
const orCondition: CompoudCondition = {
conditionType: 'or',
@ -380,7 +388,7 @@ export abstract class PerspectiveTreeNode {
const pattern = this.dataProvider?.dataPatterns?.[this.designerId];
if (!pattern) return null;
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, 'mongo');
const condition = parseFilter(this.nodeConfig?.multiColumnFilter, mongoFilterBehaviour);
if (!condition) return null;
const res = pattern.columns.map(col => {
return _cloneDeepWith(condition, expr => {
@ -951,7 +959,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
get filterBehaviour(): FilterBehaviour {
if (this.tableColumn) return detectSqlFilterBehaviour(this.tableColumn.dataType);
return 'mongo';
return mongoFilterBehaviour;
}
get preloadedLevelData() {
@ -1093,7 +1101,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
parseFilterCondition(source = null): {} {
const filter = this.getFilter();
if (!filter) return null;
const condition = parseFilter(filter, 'mongo');
const condition = parseFilter(filter, mongoFilterBehaviour);
if (!condition) return null;
return _cloneDeepWith(condition, expr => {
if (expr.__placeholder__) {

View File

@ -227,7 +227,9 @@ function getParser(filterBehaviour: FilterBehaviour) {
export function parseFilter(value: string, filterBehaviour: FilterBehaviour): Condition {
const parser = getParser(filterBehaviour);
console.log('value', value);
console.log('filterBehaviour', filterBehaviour);
const ast = parser.list.tryParse(value);
// console.log('AST', ast);
console.log('AST', ast);
return ast;
}

View File

@ -31,7 +31,7 @@ export const logicalFilterBehaviour: FilterBehaviour = {
};
export const datetimeFilterBehaviour: FilterBehaviour = {
compilerType: 'sqlTree',
compilerType: 'datetime',
supportNullTesting: true,
supportSqlCondition: true,
supportDatetimeSymbols: true,
@ -59,7 +59,7 @@ export const evalFilterBehaviour: FilterBehaviour = {
allowStringToken: true,
};
export const standardFilterBehaviours = {
export const standardFilterBehaviours: { [id: string]: FilterBehaviour } = {
numberFilterBehaviour,
stringFilterBehaviour,
logicalFilterBehaviour,

View File

@ -73,7 +73,7 @@ export interface ServerSummary {
}
export interface FilterBehaviourProvider {
getFilterBehaviour(dataType: string, standardFilterBehaviours: { string: FilterBehaviour }): FilterBehaviour;
getFilterBehaviour(dataType: string, standardFilterBehaviours: { [id: string]: FilterBehaviour }): FilterBehaviour;
}
export interface EngineDriver extends FilterBehaviourProvider {

View File

@ -26,7 +26,7 @@
for (const uniqueName in filters || {}) {
if (!filters[uniqueName]) continue;
try {
const ast = parseFilter(filters[uniqueName], 'mongo');
const ast = parseFilter(filters[uniqueName], mongoFilterBehaviour);
// console.log('AST', ast);
const cond = _.cloneDeepWith(ast, expr => {
if (expr.__placeholder__) {
@ -123,6 +123,7 @@
import ChangeSetGrider from './ChangeSetGrider';
import LoadingDataGridCore from './LoadingDataGridCore.svelte';
import { mongoFilterBehaviour } from 'dbgate-tools';
export let conid;
export let display;