diesel-derive-enum icon indicating copy to clipboard operation
diesel-derive-enum copied to clipboard

Release for diesel 2.0.0?

Open lsunsi opened this issue 1 year ago • 3 comments

Since the release of diesel 2.0.0, I've been anxious to see this lib getting updated. I've tried master against diesel 2 with a big project I have and everything seems good! Is there anything between us and a new release?

lsunsi avatar Sep 02 '22 20:09 lsunsi

Think there is still a bit of work to be done - https://github.com/adwhit/diesel-derive-enum/pull/79

adwhit avatar Sep 03 '22 09:09 adwhit

Also TBH I'm not very happy with this crate in its current state. Relying on print-schema to get the correct Postgres types is fine, it works, but I think it should be optional. This crate should fully create the Postgres types similarly to MySQL, if asked to

adwhit avatar Sep 03 '22 09:09 adwhit

@adwhit Got it! I don't exactly understand what it implies, but I realized the guides for PG and MySQL are different. Why is that?

lsunsi avatar Sep 03 '22 20:09 lsunsi

There is a change with 2.0 which is tricky to handle. For postgres only, diesel 2.0 will now detect enum types within the database and create corresponding rust types in the generated schema.rs file. This library needs to be tweaked to optionally use these generated types if specified, and otherwise to generate them as before. At the moment we are not quite in the right place - if the postgres feature is activated, it will always look for this generated type, and otherwise it won't. This needs fixing.

(cc #79 #82 #83)

adwhit avatar Sep 22 '22 09:09 adwhit

@adwhit I'm currently using the RC version and will keep my ears peeled on these issues

lsunsi avatar Sep 22 '22 14:09 lsunsi

@adwhit Is there anything we can do to help?

nox avatar Oct 17 '22 10:10 nox

I tried to write some better tests today prior to release, and got bitten by https://github.com/diesel-rs/diesel/issues/3386 - probably should wait for an update

adwhit avatar Oct 30 '22 16:10 adwhit

I have a PR #85 which attempts to improve the current situation. Now, if you use postgres and the diesel CLI to generate your schema.rs, then when you create your enum you annotate it with ExistingTypePath like so:

#[derive(diesel_derive_enum::DbEnum, Debug, Copy, Clone, PartialEq, Eq)]
#[ExistingTypePath = "crate::schema::sql_types::MyEnum"]
pub enum MyEnum {
    Foo,
    Bar,
    BazQuxx,
}

If you don't add the annotation, this crate ignores any generated types and creates its own Mapping type.

Does anyone have opinions on whether this is reasonable? My main reservation is that the 'happy path' (where the CLI does the heavy lifting) now requires extra work for the user. On the other hand, it does make this crate less magical.

adwhit avatar Nov 10 '22 16:11 adwhit