Extend Find Options and Query Builder functionality
See original GitHub issueThe following code:
const qb = this.manager.createQueryBuilder(PostEntity, "post");
if (filter.tagIds && filter.tagIds.length > 0)
qb.innerJoin("post.tags", "tags", "tags.id IN (:...tagIds)")
.setParameters({ tagIds: filter.tagIds });
if (filter.conceptType)
qb.innerJoin("post.tags", "tags", "tags.conceptType = :conceptType")
.setParameters({ conceptType: filter.conceptType });
if (filter.keyword)
qb.andWhere("post.name ILIKE :name", { name: "%" + filter.keyword + "%" });
if (filter.skipIds && filter.skipIds.length > 0)
qb.andWhere("post.id NOT IN (:...skipIds)", { skipIds: filter.skipIds });
if (filter.sortBy === "my" && this.sessionUser)
qb.andWhere("post.authorId = :userId", { userId: this.sessionUser.personId });
switch (filter.sortBy) {
case "last":
qb.orderBy("post.id", "DESC");
break;
case "popular":
qb.orderBy("post.widgetCounter.score", "DESC");
break;
case "active":
qb.orderBy("post.lastActiveDate", "DESC");
break;
default:
qb.orderBy("post.id", "DESC");
}
if (filter.offset)
qb.skip(filter.offset);
if (filter.limit)
qb.take(filter.limit);
return qb;
can be translated into:
return this.manager
.createQueryBuilder(PostEntity, "post")
.where({
tags: {
id: If(filter.tagIds && filter.tagIds.length > 0, In(filter.tagIds)),
conceptType: If(filter.conceptType, filter.conceptType),
},
name: If(filter.keyword, Like("%" + filter.keyword + "%")),
id: If(filter.skipIds && filter.skipIds.length > 0, Not(In(filter.skipIds))),
authorId: If(this.sessionUser, this.sessionUser.personId)
})
.orderBy(Switch(filter.sortBy, {
last: { id: "DESC" },
popular: { widgetCounter: { score: "DESC" } },
active: { lastActiveDate: "DESC" },
_: { id: "DESC" },
}))
This functionality is an extension of find options and will work with find
operators as well.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:16
- Comments:18 (12 by maintainers)
Top Results From Across the Web
How to enable query builder for advanced filter/search in ...
In the Options dialog box, go to the Others tab, and check the Restore “Query Builder” tab in Outlook Advanced Find Dialog box,...
Read more >Extend search functionality | Adobe Experience Manager
Extend the search capabilities of Adobe Experience Manager Assets ... Searching is done via the QueryBuilder interface so the search can be ...
Read more >Custom query builder (extending the query builder) | Objection.js
You can extend the QueryBuilder returned by query(), relatedQuery(), $relatedQuery() and $query() methods (and all other methods that create a QueryBuilder) ...
Read more >Customize Query Options with Data Query Builder
The OData expand options are added to the query by invoking the DataQueryBuilder expand API. This variadic method accepts a comma-separated ...
Read more >Query options overview - OData | Microsoft Learn
The $search system query option allows clients to request items within a collection matching a free-text search expression. The $search query ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is what I have done at the moment:
With following model:
We’ll have following completely type-safe query:
@pleerock Do you want to cover “OR” operator in where statement? In your example I see only “AND”.