perspective mongo condition

This commit is contained in:
Jan Prochazka
2022-10-01 18:50:54 +02:00
parent b3839def32
commit 08abec7c3e
4 changed files with 101 additions and 38 deletions

View File

@@ -91,7 +91,15 @@ export class PerspectiveCache {
getTableCache(props: PerspectiveDataLoadProps) { getTableCache(props: PerspectiveDataLoadProps) {
const tableKey = stableStringify( const tableKey = stableStringify(
_pick(props, ['schemaName', 'pureName', 'bindingColumns', 'databaseConfig', 'orderBy', 'condition']) _pick(props, [
'schemaName',
'pureName',
'bindingColumns',
'databaseConfig',
'orderBy',
'sqlCondition',
'mongoCondition',
])
); );
let res = this.tables[tableKey]; let res = this.tables[tableKey];

View File

@@ -8,7 +8,15 @@ export class PerspectiveDataLoader {
constructor(public apiCall) {} constructor(public apiCall) {}
buildCondition(props: PerspectiveDataLoadProps): Condition { buildCondition(props: PerspectiveDataLoadProps): Condition {
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props; const {
schemaName,
pureName,
bindingColumns,
bindingValues,
dataColumns,
orderBy,
sqlCondition: condition,
} = props;
const conditions = []; const conditions = [];
@@ -94,7 +102,16 @@ export class PerspectiveDataLoader {
} }
async loadDataSqlDb(props: PerspectiveDataLoadProps) { async loadDataSqlDb(props: PerspectiveDataLoadProps) {
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition, engineType } = props; const {
schemaName,
pureName,
bindingColumns,
bindingValues,
dataColumns,
orderBy,
sqlCondition: condition,
engineType,
} = props;
if (dataColumns?.length == 0) { if (dataColumns?.length == 0) {
return []; return [];
@@ -147,13 +164,23 @@ export class PerspectiveDataLoader {
const { pureName } = props; const { pureName } = props;
return { return {
pureName, pureName,
condition: props.mongoCondition,
skip: props.range?.offset, skip: props.range?.offset,
limit: props.range?.limit, limit: props.range?.limit,
}; };
} }
async loadDataDocDb(props: PerspectiveDataLoadProps) { async loadDataDocDb(props: PerspectiveDataLoadProps) {
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition, engineType } = props; const {
schemaName,
pureName,
bindingColumns,
bindingValues,
dataColumns,
orderBy,
sqlCondition: condition,
engineType,
} = props;
if (dataColumns?.length == 0) { if (dataColumns?.length == 0) {
return []; return [];
@@ -190,7 +217,15 @@ export class PerspectiveDataLoader {
} }
async loadRowCountSqlDb(props: PerspectiveDataLoadProps) { async loadRowCountSqlDb(props: PerspectiveDataLoadProps) {
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props; const {
schemaName,
pureName,
bindingColumns,
bindingValues,
dataColumns,
orderBy,
sqlCondition: condition,
} = props;
const select: Select = { const select: Select = {
commandType: 'select', commandType: 'select',
@@ -218,7 +253,15 @@ export class PerspectiveDataLoader {
} }
async loadRowCountDocDb(props: PerspectiveDataLoadProps) { async loadRowCountDocDb(props: PerspectiveDataLoadProps) {
const { schemaName, pureName, bindingColumns, bindingValues, dataColumns, orderBy, condition } = props; const {
schemaName,
pureName,
bindingColumns,
bindingValues,
dataColumns,
orderBy,
sqlCondition: condition,
} = props;
const options = { const options = {
...this.getDocDbLoadOptions(props), ...this.getDocDbLoadOptions(props),

View File

@@ -28,7 +28,8 @@ export interface PerspectiveDataLoadProps {
bindingValues?: any[][]; bindingValues?: any[][];
range?: RangeDefinition; range?: RangeDefinition;
topCount?: number; topCount?: number;
condition?: Condition; sqlCondition?: Condition;
mongoCondition?: any;
engineType: 'sqldb' | 'docdb'; engineType: 'sqldb' | 'docdb';
} }

View File

@@ -298,7 +298,7 @@ export abstract class PerspectiveTreeNode {
); );
} }
getChildrenCondition(source = null): Condition { getChildrenSqlCondition(source = null): Condition {
const conditions = _compact([ const conditions = _compact([
...this.childNodes.map(x => x.parseFilterCondition(source)), ...this.childNodes.map(x => x.parseFilterCondition(source)),
...this.buildParentFilterConditions(), ...this.buildParentFilterConditions(),
@@ -315,6 +315,17 @@ export abstract class PerspectiveTreeNode {
}; };
} }
getChildrenMongoCondition(source = null): {} {
const conditions = _compact([...this.childNodes.map(x => x.parseFilterCondition(source))]);
if (conditions.length == 0) {
return null;
}
if (conditions.length == 1) {
return conditions[0];
}
return { $and: conditions };
}
getOrderBy(table: TableInfo | ViewInfo | CollectionInfo): PerspectiveDataLoadProps['orderBy'] { getOrderBy(table: TableInfo | ViewInfo | CollectionInfo): PerspectiveDataLoadProps['orderBy'] {
const res = _compact( const res = _compact(
this.childNodes.map(node => { this.childNodes.map(node => {
@@ -444,7 +455,7 @@ export abstract class PerspectiveTreeNode {
conditionType: 'and', conditionType: 'and',
conditions: _compact([ conditions: _compact([
...lastNode.getParentJoinCondition(lastAlias, this.namedObject.pureName), ...lastNode.getParentJoinCondition(lastAlias, this.namedObject.pureName),
leafNode.getChildrenCondition({ alias: 'pert_0' }), leafNode.getChildrenSqlCondition({ alias: 'pert_0' }),
]), ]),
}; };
@@ -558,7 +569,7 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode {
dataColumns: this.getDataLoadColumns(), dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.refTable), orderBy: this.getOrderBy(this.refTable),
condition: this.getChildrenCondition(), sqlCondition: this.getChildrenSqlCondition(),
engineType: 'sqldb', engineType: 'sqldb',
}; };
} }
@@ -705,6 +716,7 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
refTable: TableInfo; refTable: TableInfo;
constructor( constructor(
public owner: NamedObjectInfo,
public column: PerspectiveDataPatternColumn, public column: PerspectiveDataPatternColumn,
dbs: MultipleDatabaseInfo, dbs: MultipleDatabaseInfo,
config: PerspectiveConfig, config: PerspectiveConfig,
@@ -814,31 +826,29 @@ export class PerspectivePatternColumnNode extends PerspectiveTreeNode {
// ); // );
} }
// get filterInfo(): PerspectiveFilterColumnInfo { get filterInfo(): PerspectiveFilterColumnInfo {
// return { return {
// columnName: this.columnName, columnName: this.columnName,
// filterType: this.filterType, filterType: this.filterType,
// pureName: this.column.pureName, pureName: this.owner.pureName,
// schemaName: this.column.schemaName, schemaName: this.owner.schemaName,
// foreignKey: this.foreignKey, foreignKey: this.foreignKey,
// }; };
// } }
// parseFilterCondition(source = null): Condition { parseFilterCondition(source = null): {} {
// const filter = this.getFilter(); const filter = this.getFilter();
// if (!filter) return null; if (!filter) return null;
// const condition = parseFilter(filter, this.filterType); const condition = parseFilter(filter, 'mongo');
// if (!condition) return null; if (!condition) return null;
// return _cloneDeepWith(condition, (expr: Expression) => { return _cloneDeepWith(condition, expr => {
// if (expr.exprType == 'placeholder') { if (expr.__placeholder__) {
// return { return {
// exprType: 'column', [this.columnName]: expr.__placeholder__,
// columnName: this.column.columnName, };
// source, }
// }; });
// } }
// });
// }
// get headerTableAttributes() { // get headerTableAttributes() {
// if (this.foreignKey) { // if (this.foreignKey) {
@@ -888,7 +898,7 @@ export class PerspectiveTableNode extends PerspectiveTreeNode {
dataColumns: this.getDataLoadColumns(), dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.table), orderBy: this.getOrderBy(this.table),
condition: this.getChildrenCondition(), sqlCondition: this.getChildrenSqlCondition(),
engineType: 'sqldb', engineType: 'sqldb',
}; };
} }
@@ -967,7 +977,7 @@ export class PerspectiveCollectionNode extends PerspectiveTreeNode {
dataColumns: this.getDataLoadColumns(), dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.collection), orderBy: this.getOrderBy(this.collection),
condition: this.getChildrenCondition(), mongoCondition: this.getChildrenMongoCondition(),
engineType: 'docdb', engineType: 'docdb',
}; };
} }
@@ -1129,7 +1139,7 @@ export class PerspectiveTableReferenceNode extends PerspectiveTableNode {
dataColumns: this.getDataLoadColumns(), dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.table), orderBy: this.getOrderBy(this.table),
condition: this.getChildrenCondition(), sqlCondition: this.getChildrenSqlCondition(),
engineType: 'sqldb', engineType: 'sqldb',
}; };
} }
@@ -1235,7 +1245,7 @@ export class PerspectiveCustomJoinTreeNode extends PerspectiveTableNode {
dataColumns: this.getDataLoadColumns(), dataColumns: this.getDataLoadColumns(),
databaseConfig: this.databaseConfig, databaseConfig: this.databaseConfig,
orderBy: this.getOrderBy(this.table), orderBy: this.getOrderBy(this.table),
condition: this.getChildrenCondition(), sqlCondition: this.getChildrenSqlCondition(),
engineType: 'sqldb', engineType: 'sqldb',
}; };
} }
@@ -1362,6 +1372,7 @@ export function getCollectionChildPerspectiveNodes(
parentNode, parentNode,
designerId => designerId =>
new PerspectivePatternColumnNode( new PerspectivePatternColumnNode(
collection,
col, col,
dbs, dbs,
config, config,