Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Georg Semmler
    @weiznich
    That shouldn't mean that this wouldn't be something that can be useful for anyone. I'm just not sure if this should be really part of diesel itself, or should there be some kind of "high-level" crate that uses diesel internally and provides an interface that matches more classical ORM 's. If someone steps up to write such an crate I would definitively try to over some advice and help for implementation there.
    Andrew Wheeler(Genusis)
    @genusistimelord
    @weiznich I would step up but I lack experience in Rust macros. I find them very hard to use right now as i really don't fully understand them.
    Georg Semmler
    @weiznich
    I think you doesn't need that much macros for such a project. More likely that you need to define a whole lot of traits and write some generic code + maybe one or two "simple" derive macros (but they are really simple, just take some rust code and generate some rust code, that's not any more complex than writing normal rust code)
    I think the more complex part is to decide how the "public" API of such a crate should look like and how to avoid common ORM problems like N+1 queries in such an API.
    I think @pksunkara Is working on something like that as well, so maybe you could ask them on their approach and join forces there?
    Andrew Wheeler(Genusis)
    @genusistimelord
    the n+1 issue is very hard to avoid XD
    Georg Semmler
    @weiznich
    At least diesel provides some API's that allow you to write queries without running in such issues. (See diesel::associations for example :wink:)
    Andrew Wheeler(Genusis)
    @genusistimelord
    I think maybe for something like this rather that relying on a full blown query hierarchy it be better to just add a derive that builds a players::table.select((players.uid, players.name)) that the end user could simply just use the rest of regular diesel along with it
    so you could do
    PGPlayerWithID::select() and the rest would be regular diesel commands
    Georg Semmler
    @weiznich
    For that see #2367. As written before: It's not a priority for myself, but I would be happy to accept a complete PR there.
    Andrew Wheeler(Genusis)
    @genusistimelord
    @weiznich Looking over that PR and i don't see anything wrong with why it hasn't been pushed yet?
    Georg Semmler
    @weiznich
    Because the CI is failing and something seems to be wrong with some type mapping there. As written there: I do currently not have the time or capacity to work on that. So if someone figures out what's wrong I will try to find some time to do a final review.
    Andrew Wheeler(Genusis)
    @genusistimelord
    ok i can probably look into it and see.
    Pavan Kumar Sunkara
    @pksunkara

    I think maybe for something like this rather that relying on a full blown query hierarchy it be better to just add a derive that builds a players::table.select((players.uid, players.name)) that the end user could simply just use the rest of regular diesel along with it

    I have actually finished implementing support for the above in my ORM lib (on top of diesel) using rust macros. I am currently working on solving this issue for INSERT and UPDATE. And then will move on to associations (I have a vague idea on how to solve the n+1 problem)

    Andrew Wheeler(Genusis)
    @genusistimelord
    @pksunkara have you posted this anywhere yet?
    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