cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Flag for generating Serde deserialize trait #203

Open farazfazli opened 1 year ago

farazfazli commented 1 year ago

Hi @LouisGariepy,

I have been trying out Cornucopia and am really enjoying the developer experience. Currently, I am using it as a REST API (with JSON) on top of Postgres.

I see that #86 added support for serialization of JSON, but not deserialization. I went into the generated Rust file out of curiosity and noticed that the serde::Deserialize trait is indeed missing. Any plans to support this? What I was thinking is that we could add a ---deserialize switch which adds the trait, similar to the --serialize switch. Or, the same switch could add both traits if you feel that would be a better workflow.

My thought process is that abstractions can be created on top of SQL tables using views and this is a use-case where both serialization and deserialization would be helpful. Exposing views to an API is what PostgREST recommends and I like the approach.

Thank you for creating this awesome project and I am looking forward to hearing your thoughts on this.

Sincerely, Faraz

farazfazli commented 1 year ago

Hi @LouisGariepy,

Wanted to know your thoughts on this proposal.

Thanks, Faraz

farazfazli commented 1 year ago

@LouisGariepy is this possible?

blowback commented 3 months ago

I find myself in need of something similar...having used Cornucopia to generate code for a Leptos backend, I'd like to have all the structs available for the front-end too without manually defining duplicates.