Closed Tiscs closed 2 weeks ago
Thanks for your contribution!
However, I think Query is chainable, so could we achieve the same effect with the following approach?
db.NewSelect().Model(new(User)).Apply(fn1).Apply(fn2)
Thanks for your contribution!
However, I think Query is chainable, so could we achieve the same effect with the following approach?
db.NewSelect().Model(new(User)).Apply(fn1).Apply(fn2)
Thanks for your response.
That's right, the query can be implemented in your way.
But in my case, I build the query by passing in variadic parameters, so I need to do it like this:
q := db.NewSelect().Model(new(User))
for _, fn := range fns {
fn(q) // or `q = fn(q)`, queries are modified in-place
}
q.Scan(ctx)
So, I think chainable queries are great, and applying multiple at once is also useful.
This pull request includes updates to the
Apply
method across multiple query types to support variadic function arguments, allowing multiple functions to be applied in sequence, these changes will not break existing calls.BTW, some comments were fixed.