-
-
Notifications
You must be signed in to change notification settings - Fork 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
AllColumns pattern isn't compatible with BoxedQuery pattern #1979
Comments
As a workaround you need to define your own This change "fixes" the minimal example: diff --git a/src/main.rs b/src/main.rs
index ff7d64d..19129e6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,6 +14,8 @@ mod krate {
use crate::version::Version;
use diesel::pg::Pg;
use diesel::prelude::*;
+ use diesel::dsl::SqlTypeOf;
+ use diesel::query_builder::BoxedSelectStatement;
#[derive(Debug, Clone, Queryable, Identifiable, Associations, AsChangeset, QueryableByName)]
#[table_name = "crates"]
@@ -34,25 +36,32 @@ mod krate {
}
}
+ type BoxedVersionQuery<'a, Backend> =
+ BoxedSelectStatement<'a, SqlTypeOf<super::version::AllColumns>, versions::table, Backend>;
+
pub trait CrateVersions {
- fn all_versions(&self) -> versions::BoxedQuery<'_, Pg>;
+ fn all_versions(&self) -> BoxedVersionQuery<'_, Pg>;
}
impl CrateVersions for Crate {
- fn all_versions(&self) -> versions::BoxedQuery<'_, Pg> {
- Version::belonging_to(self).into_boxed()
+ fn all_versions(&self) -> BoxedVersionQuery<'_, Pg> {
+ Version::belonging_to(self)
+ .select(super::version::ALL_COLUMNS)
+ .into_boxed()
}
}
impl CrateVersions for Vec<Crate> {
- fn all_versions(&self) -> versions::BoxedQuery<'_, Pg> {
+ fn all_versions(&self) -> BoxedVersionQuery<'_, Pg> {
self.as_slice().all_versions()
}
}
impl CrateVersions for [Crate] {
- fn all_versions(&self) -> versions::BoxedQuery<'_, Pg> {
- Version::belonging_to(self).into_boxed()
+ fn all_versions(&self) -> BoxedVersionQuery<'_, Pg> {
+ Version::belonging_to(self)
+ .select(super::version::ALL_COLUMNS)
+ .into_boxed()
}
}
}
@@ -70,7 +79,7 @@ mod version {
pub num: String,
}
- type AllColumns = (versions::id, versions::crate_id, versions::num);
+ pub type AllColumns = (versions::id, versions::crate_id, versions::num);
pub const ALL_COLUMNS: AllColumns = (versions::id, versions::crate_id, versions::num); |
Thank you for the workaround! |
A workaround is needed to get the all columns pattern to work with the boxed query pattern, see diesel-rs/diesel#1979 I don't like how many places needed to be changed, going to see if I can refactor a bit.
Another update here: The |
Possibly related: #1435
Setup
Versions
edition = "2018"
Feature Flags
["postgres"]
Problem Description
What are you trying to accomplish?
In crates.io's code, I'm trying to add a column to our versions table that exists in the database but is never selected by the Queryable model, using the
AllColumns
pattern described in the composing applications diesel guide that we've successfully used for the crates table.The problem is there's a set of functions that return
versions::BoxedQuery
, using theBoxedQuery
pattern described in the same guide, and those functions stop compiling when I add theAllColumn
types.What is the expected output?
Successful compilation
What is the actual output?
Are you seeing any additional errors?
No
Steps to reproduce
I've extracted a minimal example into this repo: https://github.com/carols10cents/diesel-mvce
At this commit, with the call to the
all_versions
function commented out, the code compiles and works as I expect.At this commit, which uncomments out the call to the
all_versions
function, I get the compilation error shown above.Checklist
closed if this is not the case)
The text was updated successfully, but these errors were encountered: