compatability layer
This commit is contained in:
parent
dbafd568dd
commit
e08b7e8683
1 changed files with 6 additions and 3 deletions
|
@ -2,6 +2,7 @@ import { Brackets, DataSource, NotBrackets, ObjectLiteral, SelectQueryBuilder, W
|
|||
import { dataSource } from "../data-source";
|
||||
import { ConditionStructure, DynamicQueryStructure, FieldType, QueryResult } from "../type/dynamicQueries";
|
||||
import { TableMeta } from "../type/tableMeta";
|
||||
import { StringHelper } from "./stringHelper";
|
||||
|
||||
export default abstract class DynamicQueryBuilder {
|
||||
public static allowedTables: Array<string> = [
|
||||
|
@ -62,14 +63,15 @@ export default abstract class DynamicQueryBuilder {
|
|||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}): SelectQueryBuilder<ObjectLiteral> {
|
||||
let affix = queryObj.id;
|
||||
let affix = queryObj.id ?? StringHelper.random(10);
|
||||
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(`${affix}_${queryObj.table}`);
|
||||
|
||||
this.buildDynamicQuery(query, queryObj, affix);
|
||||
|
||||
if (queryObj.orderBy) {
|
||||
queryObj.orderBy.forEach((order) => {
|
||||
query.addOrderBy(`${order.id}_${order.table}.${order.column}`, order.order);
|
||||
// compatability layer for none id (old) queries
|
||||
if (order.id) query.addOrderBy(`${order.id}_${order.table}.${order.column}`, order.order);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -114,7 +116,7 @@ export default abstract class DynamicQueryBuilder {
|
|||
|
||||
if (queryObject.join) {
|
||||
for (const join of queryObject.join) {
|
||||
let subaffix = join.id;
|
||||
let subaffix = join.id ?? StringHelper.random(10);
|
||||
query.leftJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
|
||||
|
||||
this.buildDynamicQuery(query, join, subaffix, depth + 1);
|
||||
|
@ -379,6 +381,7 @@ export default abstract class DynamicQueryBuilder {
|
|||
count: noLimit ? total : count,
|
||||
};
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return {
|
||||
stats: "error",
|
||||
sql: error.sql,
|
||||
|
|
Loading…
Add table
Reference in a new issue