Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport union / intersect / except #33
Comments
sgrif
added
accepted
needs milestone
labels
Nov 29, 2015
This comment has been minimized.
|
Definitely reasonable to support. Not going to assign it a milestone just yet, but if anyone wants to tackle it, feel free. Shouldn't be hard to implement, just need to make sure that |
sgrif
added
the
enhancement
label
Nov 29, 2015
This comment has been minimized.
Meyermagic
commented
Apr 19, 2016
|
I'm going to start working on this soon (those livestreams are good advertising). I'm not familiar with your codebase, though, and want to make sure I have the right idea of how this will work. I haven't yet started coding, but I see two main issues right now:
My high-level plan is then: Introduce a Introduce three new DSL methods UnionDsl, IntersectDsl, and ExceptDsl which also require the trait added to satisfy 1. Add a new bound to the other DSL methods, something like NotCompoundQuery, to satisfy 2. Is there a Contribution Guide or architecture document or similar? I feel like a higher-level perspective might be helpful. Disclaimer: I haven't put down any code for this yet, only poking around on GitHub. This might be way off-base. |
This comment has been minimized.
|
There's some random scattered thoughts with regards to contributing here. #120 I'd avoid having the types returned by these methods implement any of the DSLs, really, and instead require a fully built query. We want to avoid things like enums if possible, as they carry runtime information that can't always be inlined, and can't be reasoned about at the type level. Go ahead and rely on Keep in mind that anything adding support for something like this would need to be thoroughly tested. |
This comment has been minimized.
|
Gave this a little thought. It actually should be extremely straightforward, just needs a lot of tests. trait UnionDsl<Other: AsQuery<SqlType=Self::SqlType>>: AsQuery {
type Output = Query<SqlType=Self::SqlType>;
fn union(self, other: Other) -> Self::Output;
}
impl<T, U> UnionDsl<U> for T where
T: AsQuery,
U: AsQuery<SqlType=T::SqlType>,
{
type Output = UnionQuery<T::Query, U::Query>;
fn union(self, other: U) -> Self::Output {
UnionQuery::new(self.as_query(), other.as_query())
}
}
pub struct UnionQuery<T, U> {
left: T,
right: U,
}
impl<T, U, DB> QueryFragment<DB> for UnionQuery<T, U> where
// you know the drill
{
// impls...
}
impl<T, U> Query for UnionQuery<T, U> where
T: Query,
U: Query<SqlType=T::SqlType>,
{
type SqlType = T::SqlType;
}Note: We may want to drop the constraints on |
This comment has been minimized.
|
And while I'd have |
This comment has been minimized.
|
It seems that both SQLite and Pg support |
This comment has been minimized.
Meyermagic
commented
Apr 30, 2016
|
Yes, I noticed that too. Should have a patch by Monday if I have time. |
Meyermagic commentedNov 29, 2015
http://www.postgresql.org/docs/current/static/queries-union.html
These are quite useful for set-like queries.