mirror of
https://github.com/diesel-rs/diesel.git
synced 2024-10-04 09:39:24 +03:00
Pass the right hand side to JoinTo
This is a refactoring in preparation for ad-hoc join clauses. I'm imagining the API being roughly `lhs.inner_join(rhs.on(on_clause))`, which will mean we will have a struct containing the rhs and the on clause. The `JoinTo` impl for this struct will need to just destructure it and return those pieces, so this sets up the trait changes for all existing implementations. I had to bump clippy as part of this change, as it hits a rustc bug that was fixed on more recent nightlies. However, I couldn't bump to the *latest* clippy, as recent nightlies are broken for us due to https://github.com/rust-lang/rust/issues/43153
This commit is contained in:
parent
2296d23abd
commit
34891a6563
@ -40,7 +40,7 @@ matrix:
|
|||||||
allow_failures:
|
allow_failures:
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
include:
|
include:
|
||||||
- rust: nightly-2017-04-25
|
- rust: nightly-2017-06-06
|
||||||
env: CLIPPY_AND_COMPILE_TESTS=YESPLEASE
|
env: CLIPPY_AND_COMPILE_TESTS=YESPLEASE
|
||||||
script:
|
script:
|
||||||
- (cd diesel && cargo rustc --no-default-features --features "lint unstable sqlite postgres mysql extras" -- -Zno-trans)
|
- (cd diesel && cargo rustc --no-default-features --features "lint unstable sqlite postgres mysql extras" -- -Zno-trans)
|
||||||
|
@ -14,7 +14,7 @@ categories = ["database"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.0"
|
byteorder = "1.0"
|
||||||
chrono = { version = "0.4", optional = true }
|
chrono = { version = "0.4", optional = true }
|
||||||
clippy = { optional = true, version = "=0.0.126" }
|
clippy = { optional = true, version = "=0.0.138" }
|
||||||
libc = { version = "0.2.0", optional = true }
|
libc = { version = "0.2.0", optional = true }
|
||||||
libsqlite3-sys = { version = ">=0.8.0, <0.9.0", optional = true, features = ["min_sqlite_version_3_7_16"] }
|
libsqlite3-sys = { version = ">=0.8.0, <0.9.0", optional = true, features = ["min_sqlite_version_3_7_16"] }
|
||||||
mysqlclient-sys = { version = ">=0.1.0, <0.3.0", optional = true }
|
mysqlclient-sys = { version = ">=0.1.0, <0.3.0", optional = true }
|
||||||
|
@ -114,6 +114,7 @@ impl<DB, Statement> StatementCache<DB, Statement> where
|
|||||||
DB::QueryBuilder: Default,
|
DB::QueryBuilder: Default,
|
||||||
StatementCacheKey<DB>: Hash + Eq,
|
StatementCacheKey<DB>: Hash + Eq,
|
||||||
{
|
{
|
||||||
|
#[cfg_attr(feature="clippy", allow(new_without_default_derive))]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
StatementCache {
|
StatementCache {
|
||||||
cache: RefCell::new(HashMap::new())
|
cache: RefCell::new(HashMap::new())
|
||||||
|
@ -648,10 +648,12 @@ macro_rules! table_body {
|
|||||||
impl<T> JoinTo<T> for table where
|
impl<T> JoinTo<T> for table where
|
||||||
T: JoinTo<table> + JoinTo<PleaseGenerateInverseJoinImpls<table>>,
|
T: JoinTo<table> + JoinTo<PleaseGenerateInverseJoinImpls<table>>,
|
||||||
{
|
{
|
||||||
type JoinOnClause = <T as JoinTo<table>>::JoinOnClause;
|
type FromClause = T;
|
||||||
|
type OnClause = <T as JoinTo<table>>::OnClause;
|
||||||
|
|
||||||
fn join_on_clause() -> Self::JoinOnClause {
|
fn join_target(rhs: T) -> (Self::FromClause, Self::OnClause) {
|
||||||
<T as JoinTo<table>>::join_on_clause()
|
let (_, on_clause) = T::join_target(table);
|
||||||
|
(rhs, on_clause)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,15 +805,16 @@ macro_rules! joinable_inner {
|
|||||||
primary_key_expr = $primary_key_expr:expr,
|
primary_key_expr = $primary_key_expr:expr,
|
||||||
) => {
|
) => {
|
||||||
impl $crate::JoinTo<$right_table_ty> for $left_table_ty {
|
impl $crate::JoinTo<$right_table_ty> for $left_table_ty {
|
||||||
type JoinOnClause = $crate::expression::helper_types::Eq<
|
type FromClause = $right_table_ty;
|
||||||
|
type OnClause = $crate::expression::helper_types::Eq<
|
||||||
$crate::expression::nullable::Nullable<$foreign_key>,
|
$crate::expression::nullable::Nullable<$foreign_key>,
|
||||||
$crate::expression::nullable::Nullable<$primary_key_ty>,
|
$crate::expression::nullable::Nullable<$primary_key_ty>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn join_on_clause() -> Self::JoinOnClause {
|
fn join_target(rhs: $right_table_ty) -> (Self::FromClause, Self::OnClause) {
|
||||||
use $crate::{ExpressionMethods, NullableExpressionMethods};
|
use $crate::{ExpressionMethods, NullableExpressionMethods};
|
||||||
|
|
||||||
$foreign_key.nullable().eq($primary_key_expr.nullable())
|
(rhs, $foreign_key.nullable().eq($primary_key_expr.nullable()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ pub struct RawBytesBindCollector<DB: Backend + TypeMetadata> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<DB: Backend + TypeMetadata> RawBytesBindCollector<DB> {
|
impl<DB: Backend + TypeMetadata> RawBytesBindCollector<DB> {
|
||||||
|
#[cfg_attr(feature="clippy", allow(new_without_default_derive))]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
RawBytesBindCollector {
|
RawBytesBindCollector {
|
||||||
metadata: Vec::new(),
|
metadata: Vec::new(),
|
||||||
|
@ -306,9 +306,10 @@ impl<F, S, D, W, O, L, Of, G, Rhs> JoinTo<Rhs>
|
|||||||
for SelectStatement<F, S, D, W, O, L, Of, G> where
|
for SelectStatement<F, S, D, W, O, L, Of, G> where
|
||||||
F: JoinTo<Rhs>,
|
F: JoinTo<Rhs>,
|
||||||
{
|
{
|
||||||
type JoinOnClause = F::JoinOnClause;
|
type FromClause = F::FromClause;
|
||||||
|
type OnClause = F::OnClause;
|
||||||
|
|
||||||
fn join_on_clause() -> Self::JoinOnClause {
|
fn join_target(rhs: Rhs) -> (Self::FromClause, Self::OnClause) {
|
||||||
F::join_on_clause()
|
F::join_target(rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,13 @@ pub trait JoinWithImplicitOnClause<Rhs, Kind> {
|
|||||||
|
|
||||||
impl<Lhs, Rhs, Kind> JoinWithImplicitOnClause<Rhs, Kind> for Lhs where
|
impl<Lhs, Rhs, Kind> JoinWithImplicitOnClause<Rhs, Kind> for Lhs where
|
||||||
Lhs: JoinTo<Rhs>,
|
Lhs: JoinTo<Rhs>,
|
||||||
Lhs: InternalJoinDsl<Rhs, Kind, <Lhs as JoinTo<Rhs>>::JoinOnClause>,
|
Lhs: InternalJoinDsl<<Lhs as JoinTo<Rhs>>::FromClause, Kind, <Lhs as JoinTo<Rhs>>::OnClause>,
|
||||||
{
|
{
|
||||||
type Output = <Lhs as InternalJoinDsl<Rhs, Kind, Lhs::JoinOnClause>>::Output;
|
type Output = <Lhs as InternalJoinDsl<Lhs::FromClause, Kind, Lhs::OnClause>>::Output;
|
||||||
|
|
||||||
fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output {
|
fn join_with_implicit_on_clause(self, rhs: Rhs, kind: Kind) -> Self::Output {
|
||||||
self.join(rhs, kind, Lhs::join_on_clause())
|
let (from, on) = Lhs::join_target(rhs);
|
||||||
|
self.join(from, kind, on)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,9 +154,11 @@ impl<From, T> SelectableExpression<SelectStatement<From>>
|
|||||||
/// the [association annotations](../associations/index.html) from codegen.
|
/// the [association annotations](../associations/index.html) from codegen.
|
||||||
pub trait JoinTo<T> {
|
pub trait JoinTo<T> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
type JoinOnClause;
|
type FromClause;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn join_on_clause() -> Self::JoinOnClause;
|
type OnClause;
|
||||||
|
#[doc(hidden)]
|
||||||
|
fn join_target(rhs: T) -> (Self::FromClause, Self::OnClause);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
@ -228,20 +230,22 @@ impl<DB: Backend> QueryFragment<DB> for LeftOuter {
|
|||||||
impl<Left, Mid, Right, Kind> JoinTo<Right> for Join<Left, Mid, Kind> where
|
impl<Left, Mid, Right, Kind> JoinTo<Right> for Join<Left, Mid, Kind> where
|
||||||
Left: JoinTo<Right>,
|
Left: JoinTo<Right>,
|
||||||
{
|
{
|
||||||
type JoinOnClause = Left::JoinOnClause;
|
type FromClause = Left::FromClause;
|
||||||
|
type OnClause = Left::OnClause;
|
||||||
|
|
||||||
fn join_on_clause() -> Self::JoinOnClause {
|
fn join_target(rhs: Right) -> (Self::FromClause, Self::OnClause) {
|
||||||
Left::join_on_clause()
|
Left::join_target(rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Join, On, Right> JoinTo<Right> for JoinOn<Join, On> where
|
impl<Join, On, Right> JoinTo<Right> for JoinOn<Join, On> where
|
||||||
Join: JoinTo<Right>,
|
Join: JoinTo<Right>,
|
||||||
{
|
{
|
||||||
type JoinOnClause = Join::JoinOnClause;
|
type FromClause = Join::FromClause;
|
||||||
|
type OnClause = Join::OnClause;
|
||||||
|
|
||||||
fn join_on_clause() -> Self::JoinOnClause {
|
fn join_target(rhs: Right) -> (Self::FromClause, Self::OnClause) {
|
||||||
Join::join_on_clause()
|
Join::join_target(rhs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ clap = "2.20.3"
|
|||||||
diesel = { version = "0.14.0", default-features = false }
|
diesel = { version = "0.14.0", default-features = false }
|
||||||
dotenv = ">=0.8, <0.11"
|
dotenv = ">=0.8, <0.11"
|
||||||
diesel_infer_schema = "0.14.0"
|
diesel_infer_schema = "0.14.0"
|
||||||
clippy = { optional = true, version = "=0.0.126" }
|
clippy = { optional = true, version = "=0.0.138" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.4"
|
tempdir = "0.3.4"
|
||||||
|
@ -16,7 +16,7 @@ quote = "0.3.12"
|
|||||||
dotenv = { version = ">=0.8, <0.11", optional = true }
|
dotenv = { version = ">=0.8, <0.11", optional = true }
|
||||||
diesel = { version = "0.14.0", default-features = false }
|
diesel = { version = "0.14.0", default-features = false }
|
||||||
diesel_infer_schema = { version = "0.14.0", default-features = false, optional = true }
|
diesel_infer_schema = { version = "0.14.0", default-features = false, optional = true }
|
||||||
clippy = { optional = true, version = "=0.0.126" }
|
clippy = { optional = true, version = "=0.0.138" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.4"
|
tempdir = "0.3.4"
|
||||||
|
@ -13,7 +13,7 @@ keywords = ["orm", "database", "postgres", "postgresql", "sql"]
|
|||||||
diesel = { version = "0.14.0", default-features = false }
|
diesel = { version = "0.14.0", default-features = false }
|
||||||
syn = "0.11.4"
|
syn = "0.11.4"
|
||||||
quote = "0.3.1"
|
quote = "0.3.1"
|
||||||
clippy = { optional = true, version = "=0.0.126" }
|
clippy = { optional = true, version = "=0.0.138" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dotenv = ">=0.8, <0.11"
|
dotenv = ">=0.8, <0.11"
|
||||||
|
Loading…
Reference in New Issue
Block a user