db
db copied to clipboard
Query builder for .Union() and .UnionAll()
Feature request for the query builder:
res1 := col.Find(db.Cond{"name": "Max"}).Limit(10).Sort("-last_name")
res2 := col.Find(db.Cond{"name": "Rex", "age >": "21"}).Limit(15).Sort("-last_name")
err := db.Union(res1, res2).All(&people)
Related: #105
I think Union() is a good thing to add to the SQL query builder, but I think in upper the generic builder via .Find()
should be reserved to a subset of features just for doing the most basic conditions and using the sql query builder for all advanced queries, which is where Union would go.
Now that the query builder supports query expansion we can add Union()/UnionAll()
methods to the builder and do something like:
sel1 := sess.SelectFrom()...
sel2 := sess.SelectFrom()...
sess.Union(sel1, sel2)
I think we can make this work with db.Result
too, as you suggested @VojtechVitek. Let's do both.
@xiam
Would be interesting to see if this feature can be implemented in the near future. I think it is worth to add Union()/UnionAll()
support to SQL-builder as it seems to be low level/custom SQL manipulation. The result would be the same Selector
interface with all cool things like pagination.
Also, seems to be logical to add Intersect/IntersectAll
and Minus/MinusAll
(aka EXCEPT in postgres) to have all result set operation in SQL-builder.