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

Loading Data from tables with bytea columns fails due missing FromSqlRow implementation #1552

Closed
MattsSe opened this Issue Feb 11, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@MattsSe

MattsSe commented Feb 11, 2018

Versions

  • Rust:
    nightly-x86_64-apple-darwin (default)
    rustc 1.25.0-nightly (bd98fe0c0 2018-02-06)
  • Diesel:
    1.1.1
  • Database:
    psql (PostgreSQL) 9.6.7
  • Operating System
    MacOs High Sierra

Feature Flags

  • diesel: chrono, postgresql

Problem Description

I'm trying to load data from a postgresql table that contains a Bytea column. This fails due missing implementations for FromSqlRow, even if the targeted type doesn't contain a field for that column. Inserting, however works fine. This occurs for all tables that contain at least a bytea column.

What are you trying to accomplish?

Loading data from tables with columns of binary types. How to fetch Binary data?

What is the actual output?

error[E0277]: the trait bound `(i32, std::string::String): diesel::deserialize::FromSqlRow<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Binary>), _>` is not satisfied
  --> diesel-test/src/lib.rs:38:19
   |
38 |     let x = dummy.load::<Dummy>(conn);
   |                   ^^^^ the trait `diesel::deserialize::FromSqlRow<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Binary>), _>` is not implemented for `(i32, std::string::String)`
   |
   = help: the following implementations were found:
             <(A, B) as diesel::deserialize::FromSqlRow<(SA, SB), DB>>
             <(std::collections::Bound<T>, std::collections::Bound<T>) as diesel::deserialize::FromSqlRow<diesel::sql_types::Range<ST>, diesel::pg::Pg>>
   = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Binary>), _>` for `Dummy`
   = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<_, Dummy>` for `dummy::table`

Steps to reproduce

#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_codegen;
extern crate serde;
#[macro_use]
extern crate serde_derive;

use diesel::pg::PgConnection;
table! {
    dummy (id) {
        id -> Int4,
        name -> Varchar,
        image -> Nullable<Bytea>,
    }
}

#[derive(Queryable, Insertable, Debug, Clone)]
#[table_name = "dummy"]
pub struct Dummy {
    pub id: i32,
    pub name: String,
}

fn test(conn: &PgConnection) {
    use dummy::dsl::*;
    use diesel::prelude::*;
    use diesel::*;
    use diesel::dsl::*;
    use diesel::query_dsl::*;

    let insert_value = Dummy {
        id: 5,
        name: "".to_owned(),
    };

    insert_into(dummy).values(&insert_value).execute(conn);

    let result = dummy.load::<Dummy>(conn);
}
@Eijebong

This comment has been minimized.

Member

Eijebong commented Feb 11, 2018

You're missing the image column in your Dummy struct. Here diesel is telling you that it can't deserialize a (Int4, Varchar, Nullable<Bytea>)into a (i32, String) (which is a tuple representation of your Dummy struct.
Adding a image: Vec<u8> line to your struct should fix this.

@MattsSe

This comment has been minimized.

MattsSe commented Feb 11, 2018

Got it, thanks. Thought that diesel could omit the nullable field.
Guess I'll use tuple types if I don't need the image data.

@MattsSe MattsSe closed this Feb 11, 2018

@Eijebong

This comment has been minimized.

Member

Eijebong commented Feb 11, 2018

You could also do that. But if you still want your structure, the common thing is two have two different structs, one that is Insertable and one Queryable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment