diesel-derive-enum
diesel-derive-enum copied to clipboard
Release for diesel 2.0.0?
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?
Think there is still a bit of work to be done - https://github.com/adwhit/diesel-derive-enum/pull/79
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 Got it! I don't exactly understand what it implies, but I realized the guides for PG and MySQL are different. Why is that?
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 I'm currently using the RC version and will keep my ears peeled on these issues
@adwhit Is there anything we can do to help?
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
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.