You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I have a find query that works fine in a repository, though it needs access to a QueryBuilder to create a raw SQL snippet. I think the readability in custom repositories could be enhanced if the Filter decorator has access to a configured query builder.
** Note: I am aware this particular query could have been a nested condition if the relations were defined, however I am deliberately not defining all possible relationships to better enforce domain boundaries.
productRepo.find({$or: [{orgId: qb.raw('(select za.org_id from "zone" za where za.id = ?)',[zoneId]),concurrentZoneAvailable: true,},{zones: zoneId},]})
Proposal
Add the query builder to the @Filter decorator condition callback.
@Filter<Product>({name: 'zoneId',cond: (args,type,qb)=>({$or: [{orgId: qb.raw('(select za.org_id from "zone" za where za.id = ?)',[args.zoneId,]),concurrentZoneAvailable: true,},{zones: args.zoneId,},],}),})
The text was updated successfully, but these errors were encountered:
Maybe we could have a static helper to mark a raw query instead. We could expose the QB but it lives in the knex package, the core one technically does not know about its existence.
Let's do it another way - we can expose the EM, there you can just type it yourself to the SqlEntityManager and access createQueryBuilder method, and we can as well add em.raw() shortcut.
edit: the em will need to be defined as any unfortunately, otherwise TS will complain if you try to type it in the definition as SqlEntityManager
First of all, really loving this project.
Current state
So I have a find query that works fine in a repository, though it needs access to a QueryBuilder to create a raw SQL snippet. I think the readability in custom repositories could be enhanced if the Filter decorator has access to a configured query builder.
** Note: I am aware this particular query could have been a nested condition if the relations were defined, however I am deliberately not defining all possible relationships to better enforce domain boundaries.
Proposal
Add the query builder to the
@Filter
decorator condition callback.The text was updated successfully, but these errors were encountered: