by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    matrixbot
    @matrixbot
    jangid Yes. The helper derive macros.
    pksunkara Yup, will definitely share them.
    Daniel Sanchez
    @danielSanchezQ

    Hello. It is my first time here, so sorry if I cause any disturbance.
    I have a problem I dont know how to solve. Im trying to abstrac the creation of a query wrapped by a tokio::task:

    pub async fn query_all_proposals<Conn>(db_conn: &Conn) -> Vec<Proposal>
        where
            Conn: Connection,
    {
        tokio::task::spawn_blocking(move || -> Vec<Proposal> {
            proposals
                .load::<Proposal>(db_conn)
                .expect("Error loading proposals")
        })
            .await
            .expect("Error loading proposals")
    }

    But it complains with this error:

    error[E0271]: type mismatch resolving `<<Conn as diesel::Connection>::Backend as diesel::backend::Backend>::RawValue == [u8]`
      --> src\db\queries.rs:12:14
       |
    12 |             .load::<Proposal>(db_conn)
       |              ^^^^ expected associated type, found slice `[u8]`
       |
       = note: expected associated type `<<Conn as diesel::Connection>::Backend as diesel::backend::Backend>::RawValue`
                            found slice `[u8]`
       = note: consider constraining the associated type `<<Conn as diesel::Connection>::Backend as diesel::backend::Backend>::RawValue` to `[u8]` or calling a method that returns `<<Conn as diesel::Connection>::Backend as diesel::backend::Backend>::RawValue`
       = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
       = note: required because of the requirements on the impl of `diesel::deserialize::FromSql<diesel::sql_types::Integer, <Conn as diesel::Connection>::Backend>` for `i32`
       = note: required because of the requirements on the impl of `diesel::Queryable<diesel::sql_types::Integer, <Conn as diesel::Connection>::Backend>` for `i32`
       = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::BigInt, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::Text), <Conn as diesel::Connection>::Backend>` for `(i32, std::string::String, std::string::String, std::string::String, std::string::String, std::string::String, std::string::String, i64, std::string::String, std::string::String, std::string::String, std::string::String, std::string::String, std::string::String, std::string::String, i64, i64, i64, i64, std::string::String)`
       = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::BigInt, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::Text, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::BigInt, diesel::sql_types::Text), <Conn as diesel::Connection>::Backend>` for `db::models::Proposal`
       = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<Conn, db::models::Proposal>` for `db::schema::proposals::table`

    I've been running in circles trying stuff but I cannot get what is really happening here. Any help is more than welcome. Thanks in advance

    Daniel Neuhäuser
    @dneuhaeuser-zalando
    how would I go about addressing this?
    $ cargo check
        Checking adr v0.1.0 (/Users/dneuhaeuser/dev/adr)
    error[E0271]: type mismatch resolving `<schema::uploads::columns::upload_triggered_at as diesel::Expression>::SqlType == diesel::sql_types::Timestamptz`
       --> src/application/uploads.rs:178:46
        |
    178 |                 .and(adr_batches::created_at.lt(schema::uploads::upload_triggered_at)),
        |                                              ^^ expected struct `diesel::sql_types::Nullable`, found struct `diesel::sql_types::Timestamptz`
        |
        = note: expected struct `diesel::sql_types::Nullable<diesel::sql_types::Timestamptz>`
                   found struct `diesel::sql_types::Timestamptz`
    I want in the query to have a ...and created_at < upload_triggered_at, which is fine even if upload_triggered_at could be null so I don't get why diesel complains about this
    Creator
    @Creator
    I think that you have to call nullable on upload_triggered_at: upload_triggered_at.nullable()
    Daniel Neuhäuser
    @dneuhaeuser-zalando
    doesn't make a difference besides upload_triggered_at is already nullable
    hm, if I call .nullable() on adr_batches::created_at this error goes away but on a subsequent .load() it complains about
    expected struct `diesel::query_source::Never`, found struct `diesel::query_source::Once`
    Daniel Neuhäuser
    @dneuhaeuser-zalando
    Georg Semmler
    @weiznich
    @dneuhaeuser-zalando The last error means that one of the columns you use is belonging to a table that does not appear in the from clause
    @danielSanchezQ You will need a lot more trait bounds to make something like that work. I normally do advice not to go down that route.
    Daniel Sanchez
    @danielSanchezQ
    @weiznich ok, I can just have the already working code like that duplicated. Not so problematic. Thanks for the tip :)
    Georg Semmler
    @weiznich
    @danielSanchezQ I generally advice to make this a compile time option by having a #[cfg(feature = "postgres")] type DbConnection = PgConnection; somewhere and then just use DbConnection everywhere to prevent code duplication.
    Daniel Sanchez
    @danielSanchezQ
    @weiznich cool, that sounds good. Probably gonna do that. Thanks!
    Mindaugas Vinkelis
    @fraillt
    Hello, I'm having hard time trying to insert with select.
    What I basically want is insert into table, while joining with other table, and insert few fields in it.
    I tried this, but it doesn't work
    Nikolai Zimmermann
    @Chronophylos
    Can I setup the database without using diese_cli? I want to distribute my binary without any dependencies.
    Mindaugas Vinkelis
    @fraillt
            diesel::insert_into(idempotent_request::table)
                .values(idempotent_request::table
                    .filter(idempotent_request::client_id.eq(user.client_id)
                        .and(idempotent_request::request_id.eq(req_id.as_ref())))
                    .select((
                        idempotent_request::id,
                        body,//
                        status as i16
                    )))
                .into_columns((
                    idempotent_response::idempotent_request_id,
                    idempotent_response::response_body,
                    idempotent_response::status_code
                ))
                .execute(&conn)
    Georg Semmler
    @weiznich
    @Chronophylos You can use whatever you want to setup the database. For example there is diesel_migrations which is also used in diesel-cli internally.
    @fraillt What's exactly the problem with that? In general something like that works, so please try to add at least an error message or something like that.
    Nikolai Zimmermann
    @Chronophylos
    Yes, that is what I needed. Thank you
    Mindaugas Vinkelis
    @fraillt
    Thanks for fast reply, I probably need a bit of background as well,
    body, and status are actually non diesel generated types. maybe there is a problem
    if I comment out body and status from select (together with response_body and status_code from into_columns) it works
    but when i try to write body it get this error
    the trait bound [u8]: diesel::SelectableExpression<schema::idempotent_request::table> is not satisfied
    --> infrastructure/src/adapters/diesel/idempotencyrepository.rs:77:25
    |
    77 | .select((
    | __
    ^
    78 | | idempotent_request::id,
    79 | | body,// this is &[u8]
    80 | | // status as i16
    81 | | )))
    I also get this error in the same place
    the trait bound[u8]: diesel::expression::NonAggregateis not satisfied
    Mindaugas Vinkelis
    @fraillt
    This error about NonAggregate is shown on every line basically in values, into_columns, execute functions
    Georg Semmler
    @weiznich
    Yes that's the problem. What are the types of body and status?
    Mindaugas Vinkelis
    @fraillt
    body: &[u8], status: u16 (but i cast it to i16, and it works in other places)
    Georg Semmler
    @weiznich
    So the explain the issue there: select expects some sql query ast not, not an arbitrary rust expression. To insert a rust value there you need to create a bind via .as_expression()/.into_sql()that maps to the corresponding sql type. For status this is just (status as i16).into_sql::<SmallInt>() for body whatever sql type you want there.
    Mindaugas Vinkelis
    @fraillt
    thank you! it works!
    sunnysab
    @sunnysab
    image.png
    Hello everyone! I got into trouble when I used diesel-cli. I need some help now.
    My commands are:
    sunnysab
    @sunnysab
    In the target schema, I have three tables. One I have not altered for a long time. However, when I use --only-tables parameter to set target table, the error always occurs. I have no idea about it.
    sunnysab
    @sunnysab
    moreover, I have all data in databse(postgresql) removed.
    sunnysab
    @sunnysab
    Well, I got one clue from diesel-rs/diesel#1535. It's about foreign key.
    But I still confused about the reason.
    Adam Chalmers
    @adam_chal_twitter
    Hello! I've just posted a question about filters on joined tables on Stack Overflow. I figured I'd link it here to see if any of y'all know the answer: https://stackoverflow.com/questions/62140096/apply-diesel-filters-to-either-single-table-or-join
    Nicholas von Klitzing
    @3699n
    Hi everyone I have a very quick question. I have approximately 15,000 tables and compiling the Diesel schema for 15,000 tables crashes my computer after 30 minutes and using over 8 GB of RAM. Any advice on using Diesel to work with thousands of tables?
    matrixbot
    @matrixbot
    grabmoix Hi. Do I understand correctly, that for the query builder .conatains() (to build a @> in SQL where clause) can only be used on Array<Int4>, not Nullable<Array<Int4>> (as this results in an Option<Vec<....)? Any way to work with contains in a .filter() with a Nullable<Array<Int4>>? .
    grabmoix (I am trying to construct the Query "select * from table where (audience @> '{5}' OR audience is null)");
    Georg Semmler
    @weiznich
    @3699n Diesel generates at least a struct/type per table and one for each column in this table. That means if you have 15.000 tables you have quite a lot structs. As we implement a bunch of traits for all of those types rustc needs to do quite a lot of checking there. In the end I don't thing that using that many tables with diesel will scale well. That's the price you need to pay for a lot of type safety.
    Depending on your actual use case you can try the following workarounds:
    • Only generate table! macros for tables you actually use (There are flags for diesel-cli to do that)
    • Split up the definitions into multiple crates
    @sunnysab Without information about your schema it is not possible to answer why exactly this is happening.
    grabmoix: That's basically diesel-rs/diesel#2066. It's fixed on master, but not released yet.
    Georg Semmler
    @weiznich
    @adam_chal_twitter The short answer is: It is not possible to have an concrete type there, that allows to apply the filter to both queries.
    The probably easiest solution here is to just apply the filters before you are doing the join.
    matrixbot
    @matrixbot
    grabmoix Georg Semmler (Gitter): Thanks for the pointer and the help.
    Guy Korland
    @gkorland
    Is there a way to map an HashMap to table?
    Georg Semmler
    @weiznich
    What do you exactly mean by mapping to a table?
    1 reply
    Adam Chalmers
    @adam_chal_twitter
    @weiznich Thank you for your advice above! I've managed to narrow the problem down and I can get it to compile. But now I'm trying to write one generic function that can operate either on table1 or table1 LEFT JOIN table2 and I'm nearly there but can't figure it out. https://stackoverflow.com/questions/62161446/diesel-boxableexpressions-generic-over-a-table-and-its-joins
    Minimal example pushed up to github.com/adamchalmers/diesel-generic-filters :)