change: query builder fetch all
This commit is contained in:
parent
7904a98d5f
commit
da78c17235
3 changed files with 35 additions and 21 deletions
|
@ -51,18 +51,26 @@ export default abstract class DynamicQueryBuilder {
|
|||
return this.allowedTables.map((table) => this.getTableMeta(table));
|
||||
}
|
||||
|
||||
public static buildQuery(
|
||||
queryObj: DynamicQueryStructure,
|
||||
offset: number = 0,
|
||||
count: number = 25
|
||||
): SelectQueryBuilder<ObjectLiteral> {
|
||||
public static buildQuery({
|
||||
queryObj,
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
queryObj?: DynamicQueryStructure;
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}): SelectQueryBuilder<ObjectLiteral> {
|
||||
let affix = Math.random().toString(36).substring(2);
|
||||
let query = dataSource.getRepository(queryObj.table).createQueryBuilder(`${queryObj.table}_${affix}`);
|
||||
|
||||
this.buildDynamicQuery(query, queryObj, affix);
|
||||
|
||||
query.offset(offset);
|
||||
query.limit(count);
|
||||
if (!noLimit) {
|
||||
query.offset(offset);
|
||||
query.limit(count);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
@ -281,11 +289,17 @@ export default abstract class DynamicQueryBuilder {
|
|||
return flattenedResults;
|
||||
}
|
||||
|
||||
public static async executeQuery(
|
||||
query: string | DynamicQueryStructure,
|
||||
offset: number,
|
||||
count: number
|
||||
): Promise<
|
||||
public static async executeQuery({
|
||||
query = "",
|
||||
offset = 0,
|
||||
count = 25,
|
||||
noLimit = false,
|
||||
}: {
|
||||
query: string | DynamicQueryStructure;
|
||||
offset?: number;
|
||||
count?: number;
|
||||
noLimit?: boolean;
|
||||
}): Promise<
|
||||
| {
|
||||
stats: "error";
|
||||
sql: string;
|
||||
|
@ -348,14 +362,14 @@ export default abstract class DynamicQueryBuilder {
|
|||
}
|
||||
} else {
|
||||
try {
|
||||
let [rows, total] = await this.buildQuery(query, offset, count).getManyAndCount();
|
||||
let [rows, total] = await this.buildQuery({ queryObj: query, offset, count, noLimit }).getManyAndCount();
|
||||
|
||||
return {
|
||||
stats: "success",
|
||||
rows: this.flattenQueryResult(rows),
|
||||
total: total,
|
||||
offset: offset,
|
||||
count: count,
|
||||
count: noLimit ? total : count,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue