-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Use associated types for SelectableExpression
#709
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,6 @@ impl<'a, Expr> Aliased<'a, Expr> { | |
} | ||
} | ||
|
||
#[derive(Debug, Copy, Clone)] | ||
pub struct FromEverywhere; | ||
|
||
impl<'a, T> Expression for Aliased<'a, T> where | ||
T: Expression, | ||
{ | ||
|
@@ -57,7 +54,9 @@ impl<'a, T> QueryId for Aliased<'a, T> { | |
// FIXME This is incorrect, should only be selectable from WithQuerySource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still true. |
||
impl<'a, T, QS> SelectableExpression<QS> for Aliased<'a, T> where | ||
Aliased<'a, T>: Expression, | ||
T: SelectableExpression<QS>, | ||
{ | ||
type SqlTypeForSelect = T::SqlTypeForSelect; | ||
} | ||
|
||
impl<'a, T: Expression + Copy> QuerySource for Aliased<'a, T> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,29 +104,30 @@ impl<T: Expression> AsExpression<T::SqlType> for T { | |
} | ||
} | ||
|
||
/// Indicates that an expression can be selected from a source. The second type | ||
/// argument is optional, but is used to indicate that the right side of a left | ||
/// outer join is nullable, even if it wasn't before. | ||
/// Indicates that an expression can be selected from a source. The associated | ||
/// type is usually the same as `Expression::SqlType`, but is used to indicate | ||
/// that a column is always nullable when it appears on the right side of a left | ||
/// outer join, even if it wasn't nullable to begin with. | ||
/// | ||
/// Columns will implement this for their table. Certain special types, like | ||
/// `CountStar` and `Bound` will implement this for all sources. All other | ||
/// expressions will inherit this from their children. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Only noticed this now. Nicely put, will make people used to classical OOP with inheritance nervous, though 😄 |
||
pub trait SelectableExpression< | ||
QS, | ||
Type = <Self as Expression>::SqlType, | ||
>: Expression { | ||
pub trait SelectableExpression<QS>: Expression { | ||
type SqlTypeForSelect; | ||
} | ||
|
||
impl<T: ?Sized, ST, QS> SelectableExpression<QS, ST> for Box<T> where | ||
T: SelectableExpression<QS, ST>, | ||
impl<T: ?Sized, QS> SelectableExpression<QS> for Box<T> where | ||
T: SelectableExpression<QS>, | ||
Box<T>: Expression, | ||
{ | ||
type SqlTypeForSelect = T::SqlTypeForSelect; | ||
} | ||
|
||
impl<'a, T: ?Sized, ST, QS> SelectableExpression<QS, ST> for &'a T where | ||
T: SelectableExpression<QS, ST>, | ||
impl<'a, T: ?Sized, QS> SelectableExpression<QS> for &'a T where | ||
T: SelectableExpression<QS>, | ||
&'a T: Expression, | ||
{ | ||
type SqlTypeForSelect = T::SqlTypeForSelect; | ||
} | ||
|
||
/// Marker trait to indicate that an expression does not include any aggregate | ||
|
@@ -147,24 +148,24 @@ use query_builder::{QueryFragment, QueryId}; | |
/// Helper trait used when boxing expressions. This exists to work around the | ||
/// fact that Rust will not let us use non-core types as bounds on a trait | ||
/// object (you could not return `Box<Expression+NonAggregate>`) | ||
pub trait BoxableExpression<QS, ST, DB> where | ||
pub trait BoxableExpression<QS, DB> where | ||
DB: Backend, | ||
Self: Expression, | ||
Self: SelectableExpression<QS, ST>, | ||
Self: SelectableExpression<QS>, | ||
Self: NonAggregate, | ||
Self: QueryFragment<DB>, | ||
{} | ||
|
||
impl<QS, T, ST, DB> BoxableExpression<QS, ST, DB> for T where | ||
impl<QS, T, DB> BoxableExpression<QS, DB> for T where | ||
DB: Backend, | ||
T: Expression, | ||
T: SelectableExpression<QS, ST>, | ||
T: SelectableExpression<QS>, | ||
T: NonAggregate, | ||
T: QueryFragment<DB>, | ||
{ | ||
} | ||
|
||
impl<QS, ST, DB> QueryId for BoxableExpression<QS, ST, DB, SqlType=ST> { | ||
impl<QS, ST, STS, DB> QueryId for BoxableExpression<QS, DB, SqlType=ST, SqlTypeForSelect=STS> { | ||
type QueryId = (); | ||
|
||
fn has_static_query_id() -> bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, was this ever used for anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be, yeah. I don't know when it stopped being used.