Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Pavan Kumar Sunkara
    @pksunkara
    It uses diesel master
    Andrew Wheeler(Genusis)
    @genusistimelord
    looks really clean.
    1 reply
    Shao Chenyang
    @tzsword
    how to re-export diesel macros in workspace crate?
    Shao Chenyang
    @tzsword
    I implemented paging in the utils workspace, so I want to export diesel in utils to avoid version conflicts.
    The current solution is to add diesel to the dependencies in each workspace used
    Georg Semmler
    @weiznich
    @tzsword Have you tried to put a #[macro_export] on your reexport?
    Lee Bousfield
    @PlasmaPower
    It seems like a bug that you can use [u8; 8] in a derive Queryable struct but not a derive Insertable struct (you get an error about it not implementing Expression for the latter). I've worked around it with a serialize_as wrapper for now. Should I file a github issue or is there an underlying cause here I haven't thought about?
    Georg Semmler
    @weiznich
    @PlasmaPower Can you provide the a complete reproducing example for that before opening an issue?
    Lee Bousfield
    @PlasmaPower
    With diesel features=["postgres"] :
    #[macro_use]
    extern crate diesel;
    
    table! {
        examples (id) {
            id -> Int4,
            bytes -> Bytea,
        }
    }
    
    // Compiles
    #[derive(Queryable)]
    struct Example {
        id: i32,
        bytes: [u8; 8],
    }
    
    // Doesn't compile
    #[derive(Insertable)]
    #[table_name = "examples"]
    struct NewExample {
        bytes: [u8; 8],
    }
    let me look at an example without postgres..
    Georg Semmler
    @weiznich
    Have you tried to actually use your struct implementing Queryable? That won't work.
    Lee Bousfield
    @PlasmaPower
    oh, shoot. That's too bad. I guess I'll need a wrapper on both sides then.
    thanks
    Georg Semmler
    @weiznich
    The "underlying" issue is that we cannot guarantee that the returned Bytea field is exactly 8 byte. It also can contain more than 8 bytes for the general case.
    Lee Bousfield
    @PlasmaPower
    would this work with a mysql engine BYTES(8)?
    Georg Semmler
    @weiznich
    As diesel only has a general Bytea type this won't help directly. You would probably need to define your own sql type for that and then your definitively back to writing your own conversions there.
    Lee Bousfield
    @PlasmaPower
    alright, thanks
    Shao Chenyang
    @tzsword

    @tzsword Have you tried to put a #[macro_export] on your reexport?

    thank you very very very much for reply. I gave up, I added diesel to the required workspace, and gave up paging hahaha~~

    for now, my code looks like:

           table
          .filter(available.eq(query.available()))
                .limit(query.limit())
                .offset(query.offset());

    diesel is AWESOME~~~

    Georg Semmler
    @weiznich
    :+1:
    Pavan Kumar Sunkara
    @pksunkara
    @tzsword I have actually been looking into this issue last week. The issue is that diesel uses some derive macros inside it non proc macros which is why re-exporting doesn't work. I am planning to solve it soon.
    Pavan Kumar Sunkara
    @pksunkara
            #[derive(Debug, Clone, Copy, $crate::query_builder::QueryId, Default)]
            pub struct $column_name;
    is the offender
    Miguel Ping
    @mping
    Hi
    Anders Blenstrup-Pedersen
    @KatsuoRyuu
    Hi
    matrixbot
    @matrixbot
    Boblazar Алексей Пастухов (Gitter): йоу
    Shao Chenyang
    @tzsword
    @tzsword I have actually been looking into this issue last week. The issue is that diesel uses some derive macros inside it non proc macros which is why re-exporting doesn't work. I am planning to solve it soon.
    Awesomeeeeeeeeeeeeee this is very cool, can I help? I'm a rookie~~
    Pavan Kumar Sunkara
    @pksunkara
    @tzsword You can try to take a stab at it. I am currently a little busy with other stuff. In the file, https://github.com/diesel-rs/diesel/blob/master/diesel/src/macros/mod.rs, we need to remove all $crate::query_builder::QueryId by adding the derived code locally
    Pavan Kumar Sunkara
    @pksunkara
    You know what, I just finished it, diesel-rs/diesel#2579
    Just 10 mins work :D
    Shao Chenyang
    @tzsword
    Just 10 mins work :D
    :+1:
    Pavan Kumar Sunkara
    @pksunkara
    Looks like nightly is failing for both your "group by" and my PRs. Seems to be an issue with the nightly
    Georg Semmler
    @weiznich
    @pksunkara Can you please open an issue in rust-lang/rust for that? (Maybe we should work on getting diesel into their test suite. It happens quite often lately that they break diesel :disappointed: )
    Georg Semmler
    @weiznich
    @pksunkara I've opened rust-lang/rust#79459
    Pavan Kumar Sunkara
    @pksunkara
    Sorry, I didn't see this before you created the issue
    Pavan Kumar Sunkara
    @pksunkara

    Diesel doesn't currently provide a way to explicitly assign a field to its default value, though it may be provided in the future.

    I have been meaning to ask about this. I find that I need to specify DEFAULT in INSERT. I looked at the docs and it looks like it is not supported and this is the closest info I could find. Can you please confirm?

    CREATE TABLE users (
        id SERIAL,
        name VARCHAR(255),
        email VARCHAR(255) DEFAULT NULL
    );
    
    INSERT INTO users (name, email) VALUES ('John', 'john@gmail.com'), ('Sean', DEFAULT);
    Georg Semmler
    @weiznich
    @pksunkara I wouldn't call that not supported, but more like not exposed as part of the public API. See here for example. Seems like someone need to write some query dsl to expose that publicly.
    Erlend Langseth
    @Ploppz
    Minor problem with the solution of my previous question: m::measurement.count().filter(m::plate_id.eq(p::id)).single_value() turns out to be diesel::sql_types::Nullable<diesel::sql_types::BigInt>. Why is it nullable I wonder. If no such measurements are found it should be 0?
    Georg Semmler
    @weiznich
    In that case it should return 0 for entries, but .single_value() is designed to be used with all subqueries and there some queries return null where no entries are returned.
    Erlend Langseth
    @Ploppz
    hmm ok, then I'll just unwrap
    Pavan Kumar Sunkara
    @pksunkara
    @weiznich I can do that. But wouldn't table! need to know which column has DEFAULT and which doesn't?

    That way the following will work.

    diesel::insert_into(users).values(&(name.eq("Sean"), email.default)).execute(&conn);

    will work. Notice the email.default

    Georg Semmler
    @weiznich
    Probably. I think there must be reason why this is not exposed yet, but I haven't looked in detail yet
    Pavan Kumar Sunkara
    @pksunkara
    I am actually stuck on this so I can immediately start working on this. If you can look into it and give me a bit guidance, that would be great
    Georg Semmler
    @weiznich
    I would probably start with adding some wrapper like struct DefaultValue<C>(C) and implement Insertable<C::Table> for that resulting in Values beingDefault`. Then write some tests and see if it work
    Ibraheem Ahmed
    @ibraheemdev
    How can I build a query like this?
    let mut posts_query = schema::posts::table.into_boxed::<Pg>();
    
    if let Some(foo_id) = foo.id {
          posts_query = posts.filter(id.eq(foo_id));
    }
    
    if let Some(foo_title) = foo.title {
          posts_query = posts.filter(title.eq(foo_title));
    }
    
    if let Some(foo_name) = foo.name {
          posts_query = posts.filter(name.eq(foo_name));
    }
    I'm getting errors:
      --> src/main.rs:54:21
       |
    54 |       posts_query = posts.filter(name.eq(foo_name));
       |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `diesel::query_builder::BoxedSelectStatement`, found struct `diesel::query_builder::SelectStatement`
    Ibraheem Ahmed
    @ibraheemdev
    Oh, looks like I have to do: posts_query = posts.filter(id.eq(foo_id)).into_boxed();
    The example in the docs does not mention this
    Why is it different?