Synphonyte / leptos-struct-table

Easily create Leptos table components from structs
Apache License 2.0
164 stars 24 forks source link

implement sqlx compatibility in uuid type #26

Closed lukashermansson closed 6 months ago

lukashermansson commented 6 months ago

This pull request is an attempt to make something like this work:

#[derive(leptos_struct_table::TableRow, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "ssr", derive(sqlx::FromRow))]
#[table(sortable, classes_provider = ClassesPreset)]
pub struct User {
    pub id: leptos_struct_table::uuid::Uuid,
    pub name: String,
}

note that the Uuid here is the newtype from this library to support the leptos_struct_table::TableRow derive

This adds feature flags and implementations for the required sqlx stuff for the above to work on postgres hopefully also mysql and sqlite (I have not tested these ones myself yet tho) from what i can tell these are the database providers with an imementation for these in the sqlx library.

While the above seems to work i have no idea if this pr is a good idea (does feel like it could be a slippery slope to begin these kinds of extentions to the newtypes this library has to provide for convenient rendering) An alternative instead of placing this responsibility within this library would be to map from an sqlx struct (with FromRow implemented) to a leptos_struct_table struct (with appropriate newtypes instead of the uuid::Uuid type) feel free to close this pr if this is more of the direction you want this library to go. (if that is the case i would be happy to try to provide a pr with documentation (or extend the sqlx example with information on how to map a uuid type that works with sqlx::FromRow to a type that works with the leptos_struct_table::TableRow derive)

maccesch commented 6 months ago

Thanks for putting so much thought into this. I have indeed mixed feelings about this. On the one hand this might be sth that is useful to many people. On the other hand I think this is a bit out of scope for this crate.

So yes, an example of how to do this would be highly appreciated.