-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selector SetColumns kept private #454
Comments
Hellooo @pxue :)! Is this because, in this case, you'd like the query to forget all the previously set columns and use new ones? |
hey @xiam yes that's exactly it. for example i would like to modify some original query and replace the select with a count total. query := builder.Select("products.*").From("products").Where(...)
...
countTotal := query.SetColumns(db.Raw("count(1) as _t"))... Would be more than happy to submit a PR :) |
Can't you do query := builder.
Select("products.*", db.Raw("count(1) as _t")).
From("products").
Where(...)` ? |
No because this still "selecting" the row plus some. I'd like to be able to filter previously projected columns down to ones I want in this instanc |
in the past when we had to do queries outside of the builder, we just did it a raw query .. like when we did the recursive posts query in pressly api. The builder's construct won't be able to support every kind of query, its more of a helper for ~80% of queries. It should have facilitates around it though for interpolation and struct mapping (which it does) btw, hi Pressly alum :) |
@pxue would this work for you? cond := db.Cond{} // common condition
countTotal := builder.Select(db.Raw("count(1) as _t")).From("products").Where(cond)
query := builder.Select("products.*").From("products").Where(cond) Pressly alumni PR party :D |
hey @pkieltyka! :) @VojtechVitek yes i think for now that'll be the way, we have some complex queries and it's a bit cumbersome to repeat the entire query for a count. but it's the easiest way forward without introducing changes to upper. feel free to close up the issue. thanks guys for the recommendations! |
@pxue btw, I think you could use Paginator too. https://godoc.org/upper.io/db.v3/lib/sqlbuilder#Paginator q := builder.Select("*").From("products").Where(db.Cond{"price >=", 100}).Paginate(50)
count, err := q.TotalEntries() |
@xiam Maybe |
Hey @xiam hope everything's well!
I've a quick questions regarding setColumns. Was there a design reason in keeping this method private? I would like to have it exposed on the interface so I can manually do something similar to the paginator, ie
someSelector.setColumns("count(1) _t")
Thanks!
The text was updated successfully, but these errors were encountered: