enhancementhelp wanted
描述
I would like to propose a new method in QueryBuilder that returns a builder that is guaranteed to make no database query and return empty result set (or undefined for SingleQueryBuilder).
That will repeat what Django has been having for years: https://docs.djangoproject.com/en/4.0/ref/models/querysets/#none
The use case is creating chainable query builder functions, where one of the chains might decide that it should not return any data at all. Consider this:
function get_foos(ctx: Context) {
return ctx.allowFoos ? FooModel.query().orderBy("create_time") : FooModel.query().none()
}
httpServer.get("/foos1", (ctx) => {
return get_foos(ctx).select("data1")
})
httpServer.get("/foos2", (ctx) => {
return get_foos(ctx).select("data2").withGraphFetched(...)
})
Of course it's possible to use hacks like .filter(raw("false")) but why having hacks if this can be natively supported (and work faster).