-
While porting to 2.0.0 I stumble about a huge monster query (original). A simplified version #[macro_use] extern crate diesel as _;
use diesel::*;
diesel::table! {
upload (id) {
collection -> Nullable<Int4>,
file -> Int4,
ftime -> Nullable<Timestamp>,
ftype -> Int2,
id -> Int4,
package -> Nullable<Int4>,
project_ref -> Int4,
scmrev -> Nullable<Text>,
session -> Nullable<Int4>,
tags -> Nullable<Text>,
utime -> Timestamp,
}
}
diesel::table! {
permissions (id) {
can_push -> Bool,
can_read -> Bool,
id -> Int4,
project -> Int4,
user -> Int4,
}
}
diesel::table! {
package (id) {
id -> Int4,
pn -> Nullable<Text>,
}
}
diesel::table! {
package_version (id) {
id -> Int4,
package -> Int4,
pe -> Nullable<Text>,
pr -> Nullable<Text>,
pv -> Nullable<Text>,
}
}
diesel::table! {
project_ref (id) {
baseref -> Nullable<Text>,
branch -> Nullable<Text>,
corename -> Nullable<Text>,
distro -> Nullable<Text>,
id -> Int4,
lsb -> Nullable<Text>,
project -> Int4,
user -> Int4,
}
}
diesel::table! {
file (id) {
ctime -> Timestamp,
data -> Int4,
id -> Int4,
rcount -> Int4,
rtime -> Nullable<Timestamp>,
wcount -> Int4,
wtime -> Timestamp,
}
}
diesel::table! {
file_data (id) {
compr_type -> Int2,
digest -> Text,
digest_type -> Int2,
fsize -> Int8,
id -> Int4,
storage_name -> Text,
}
}
diesel::joinable!(upload -> file (file));
diesel::joinable!(upload -> package_version (package));
diesel::joinable!(upload -> project_ref (project_ref));
diesel::joinable!(package_version -> package (package));
diesel::joinable!(file -> file_data (data));
diesel::joinable!(permissions -> project_ref (project));
diesel::allow_tables_to_appear_in_same_query!(
file,
file_data,
package,
package_version,
permissions,
project_ref,
upload,
);
#[derive(Queryable, Debug)]
pub struct CandidateResult
{
pub upload_id: i32,
pub upload_file: i32,
pub file_data_id: i32,
pub pn: Option<String>,
pub pnve_id: Option<i32>,
pub project_ref: i32,
pub project: i32,
pub uploader: i32,
}
fn foo(conn: &diesel::pg::PgConnection)
{
let _query = upload::table
.inner_join(project_ref::table
.inner_join(permissions::table))
.left_join(package_version::table
.inner_join(package::table))
.inner_join(file::table
.inner_join(file_data::table))
.select((upload::dsl::id, upload::dsl::file,
file::dsl::data,
package::dsl::pn,
upload::dsl::package,
project_ref::dsl::id,
project_ref::dsl::project,
project_ref::dsl::user))
.load::<CandidateResult>(conn);
}
fn main() {
} builds fine with 1.4.6 but fails on diesel master with
How can I fix this? |
Beta Was this translation helpful? Give feedback.
Answered by
weiznich
May 14, 2021
Replies: 1 comment
-
As a blind guess I would say you need to change |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ensc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As a blind guess I would say you need to change
package::dsl::pn
topackage::dsl::pn.nullable()
as this column coming in via a left join. This implies that you need to change the corresponding field to an option. This was accepted by diesel 1.x, because of a bug.