ormx
ormx copied to clipboard
Derive Serialize and Deserialize for the generated insert structs
I added a new feature called serde to derive serde's Serialize and Deserialize traits for the generated insert structs when enabled.
This way, these structs can be easily used in web applications built with frameworks or libraries that require the structs that represent a request's body to be serializable to and deserializable from a JSON document.
I find the idea interesting but I'm concerned about the fact that activating the serde feature will implement Serialize and Deserialize indiscrimately for all Insert structs.
I think there should be additional attributes to opt-in to this, eg (naming for these attributes is bad but I only thought about it for 30sec 😅):
#[derive(Debug, ormx::Table)]
#[ormx(table = "foo", id = id, insertable, insertable_derive_deserialize, insertable_derive_serialize)]
struct Foo {
id: i32,
bar: String,
}
Oh, I just assumed this would always be desirable. Whoops!
I'll follow your suggestion!