Skip to content

Commit

Permalink
fix: updated query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
MontaGhanmy committed Sep 20, 2023
1 parent 85bc0ad commit 75c676b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function buildSelectQuery<Entity>(
): string {
const instance = new (entityType as any)();
const { columnsDefinition, entityDefinition } = getEntityDefinition(instance);
let allowFiltering = false;

const where = Object.keys(filters)
.map(key => {
Expand All @@ -28,6 +29,7 @@ export function buildSelectQuery<Entity>(
return;
}
if (isObject(filter) && JSON.stringify(filter).includes("ne")) {
allowFiltering = true;
result = `${key} IN (NULL, false)`;
return result;
}
Expand All @@ -47,6 +49,7 @@ export function buildSelectQuery<Entity>(

result = `${key} IN (${inClause.join(",")})`;
} else {
if (key === "is_in_trash" || key === "scope") allowFiltering = true;
result = `${key} = ${transformValueToDbString(filter, columnsDefinition[key].type, {
columns: columnsDefinition[key].options,
secret: options.secret || "",
Expand Down Expand Up @@ -82,7 +85,7 @@ export function buildSelectQuery<Entity>(
whereClause.trim().length ? "WHERE " + whereClause : ""
} ${orderByClause.trim().length ? "ORDER BY " + orderByClause : ""}`
.trimEnd()
.concat(";");
.concat(allowFiltering ? " ALLOW FILTERING;" : ";");

return query;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type DriveScope = "personal" | "shared";

@Entity(TYPE, {
globalIndexes: [["company_id", "parent_id"]],
primaryKey: [["company_id"], "is_in_trash", "scope", "id"],
primaryKey: [["company_id"], "id"],
type: TYPE,
search,
})
Expand Down

0 comments on commit 75c676b

Please sign in to comment.