Skip to content
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

MySQL UNION #83

Open
geraldus opened this issue Nov 11, 2014 · 3 comments
Open

MySQL UNION #83

geraldus opened this issue Nov 11, 2014 · 3 comments

Comments

@geraldus
Copy link

Consider following question on StackOverflow: http://stackoverflow.com/questions/4230780/mysql-query-with-multiple-limits
I have similar task, but I can't find union function in Esqueleto. Can I introduce similar single query using Esqueleto or should I make several queries?
Thank you.

@ocharles
Copy link
Contributor

ocharles commented Dec 3, 2015

I am also surprised at the lack of UNION - any idea roughly how hard this would be?

@meteficha
Copy link
Member

I don't foresee any problems, @ocharles, it shouldn't be too hard. Most work is probably going to be on the test suite :).

@meteficha
Copy link
Member

I took a stab at this issue and it's actually a lot more complicated than I anticipated :). I've tried adding:

union :: [query a] -> query a -- resp. unionAll

My first approach was morphing SideData into a monster GADT that basically amounted to:

    RealSideData {...as beore...}
  | UnionSideData [(a, RealSideData)]

This approach failed because of the SqlSelect typeclass. The one available at toRawSql can't be used because it's not available when UnionSideData is created. And we don't have a SqlSelect constraint on union.

I was planning on adding an an associated type family to the Esqueleto type class in order to change the type of union to UnionConstraint a => [query a] -> query a, which I think would solve the issue.

Then I realize that the whole SideData contraption could be removed in favor of adding a new constructor to SqlExpr and calling toRawSql directly on union's implementation. At this point I've put this endeavor to a pause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants