Replies: 1 comment
-
This won't be a complete answer, just pointing out a few things:
This attribute isn't available at any released diesel version yet, so maybe just don't expect a full guide to be written for unreleased stuff. You should likely also state very clearly as part of your question which diesel master revision you are using. Otherwise it may be hard to answer some points in detail.
Both
This can be derived by deriving
Putting everything behind one derive is just not an option as there are a lot of cases where only a subset of the conversions offered by the different derives are valid or even possible. Therefore the split into different derives. That written: Diesel there tries to offer a basic interface that allows all possible usages, not the most ergonomic interface. If you want you can implement a more opinionated take on this as third party derive.
Contributions to the guides are always welcome. Feel free to submit a PR if you feel that something is missing. |
Beta Was this translation helpful? Give feedback.
-
Hi there, I've been getting great usage out of Diesel's ORM, but I've been having troubling finding a good and ergonomic way to implement these various traits for my custom types. I've searched around quite a bit, but I haven't been able to find a best practices document describing this pretty central workflow.
Here's an example of what my code looks like.
Here's the data type I want to use in the ORM. For reference, I'm supporting the SQLite backend.
Don't worry about the semantics of the specific data type here, there are many other data types to which this question applies, and my question is about the derivation/implementation of the diesel traits themselves.
And of course the from/into implementations:
And finally, here are my trait implementations:
These implementations are all boilerplate that theoretically should be automatically derivable, but my attempts to do so using
#[diesel(deserialize_as = "NaiveDateTime")]
and#[diesel(serialize_as = "NaiveDateTime")]
attributes don't seem to be sufficient (but they are necessary).I believe I've tried various derive macros for my data types but haven't found the one that clicks into place and makes this as trivial as it seems like it should be. In particular, it seems like if there are From/Into implementations into a type that Diesel knows how to handle, then deriving the traits should be as trivial as specifying deserialize_as and serialize_as.
Can anyone show me where I'm going wrong?
A best-practices guide for implementing the Diesel ORM traits would be a great and much sought-after addition to http://diesel.rs/guides/
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions