mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 23:06:00 +00:00
handle $oid
This commit is contained in:
@@ -5,6 +5,7 @@ import _difference from 'lodash/difference';
|
||||
import debug from 'debug';
|
||||
import stableStringify from 'json-stable-stringify';
|
||||
import { PerspectiveDataPattern } from './PerspectiveDataPattern';
|
||||
import { perspectiveValueMatcherSimple } from './perspectiveTools';
|
||||
|
||||
const dbg = debug('dbgate:PerspectiveCache');
|
||||
|
||||
@@ -17,7 +18,9 @@ export class PerspectiveBindingGroup {
|
||||
bindingValues: any[];
|
||||
|
||||
matchRow(row) {
|
||||
return this.table.bindingColumns.every((column, index) => row[column] == this.bindingValues[index]);
|
||||
return this.table.bindingColumns.every((column, index) =>
|
||||
perspectiveValueMatcherSimple(row[column], this.bindingValues[index])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +72,11 @@ export class PerspectiveCacheTable {
|
||||
}
|
||||
|
||||
storeGroupSize(props: PerspectiveDataLoadProps, bindingValues: any[], count: number) {
|
||||
const originalBindingValue = props.bindingValues.find(v => _zip(v, bindingValues).every(([x, y]) => x == y));
|
||||
const originalBindingValue = props.bindingValues.find(v =>
|
||||
_zip(v, bindingValues).every(([x, y]) => perspectiveValueMatcherSimple(x, y))
|
||||
);
|
||||
// console.log('storeGroupSize NEW', bindingValues);
|
||||
// console.log('storeGroupSize ORIGINAL', originalBindingValue);
|
||||
if (originalBindingValue) {
|
||||
const key = stableStringify(originalBindingValue);
|
||||
// console.log('SET SIZE', originalBindingValue, bindingValues, key, count);
|
||||
|
||||
@@ -47,6 +47,7 @@ export class PerspectiveDataProvider {
|
||||
|
||||
async loadDataNested(props: PerspectiveDataLoadProps): Promise<{ rows: any[]; incomplete: boolean }> {
|
||||
const tableCache = this.cache.getTableCache(props);
|
||||
// console.log('loadDataNested', props);
|
||||
|
||||
const uncached = tableCache.getUncachedBindingGroups(props);
|
||||
if (uncached.length > 0) {
|
||||
|
||||
@@ -39,7 +39,11 @@ import { Condition, Expression, Select } from 'dbgate-sqltree';
|
||||
// import { getPerspectiveDefaultColumns } from './getPerspectiveDefaultColumns';
|
||||
import uuidv1 from 'uuid/v1';
|
||||
import { PerspectiveDataPatternColumn } from './PerspectiveDataPattern';
|
||||
import { getPerspectiveMostNestedChildColumnName, getPerspectiveParentColumnName } from './perspectiveTools';
|
||||
import {
|
||||
getPerspectiveMostNestedChildColumnName,
|
||||
getPerspectiveParentColumnName,
|
||||
perspectiveValueMatcher,
|
||||
} from './perspectiveTools';
|
||||
|
||||
export interface PerspectiveDataLoadPropsWithNode {
|
||||
props: PerspectiveDataLoadProps;
|
||||
@@ -1248,9 +1252,14 @@ export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
|
||||
}
|
||||
|
||||
matchChildRow(parentRow: any, childRow: any): boolean {
|
||||
console.log('MATCH ROW', parentRow, childRow);
|
||||
// console.log('MATCH ROW', parentRow, childRow);
|
||||
for (const column of this.customJoin.columns) {
|
||||
if (parentRow[getPerspectiveMostNestedChildColumnName(column.baseColumnName)] != childRow[column.refColumnName]) {
|
||||
if (
|
||||
!perspectiveValueMatcher(
|
||||
parentRow[getPerspectiveMostNestedChildColumnName(column.baseColumnName)],
|
||||
childRow[column.refColumnName]
|
||||
)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,3 +8,15 @@ export function getPerspectiveMostNestedChildColumnName(columnName: string) {
|
||||
const path = columnName.split('::');
|
||||
return path[path.length - 1];
|
||||
}
|
||||
|
||||
export function perspectiveValueMatcher(value1, value2): boolean {
|
||||
if (value1?.$oid && value2?.$oid) return value1.$oid == value2.$oid;
|
||||
if (Array.isArray(value1)) return !!value1.find(x => perspectiveValueMatcher(x, value2));
|
||||
if (Array.isArray(value2)) return !!value2.find(x => perspectiveValueMatcher(value1, x));
|
||||
return value1 == value2;
|
||||
}
|
||||
|
||||
export function perspectiveValueMatcherSimple(value1, value2): boolean {
|
||||
if (value1?.$oid && value2?.$oid) return value1.$oid == value2.$oid;
|
||||
return value1 == value2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user