cornucopia-rs / cornucopia

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

can cornucopia work with rust frontend framework, like Leptos? #238

Open yingweixiang opened 3 months ago

yingweixiang commented 3 months ago

It would be great to show the query result on the webpage. like use Loptos to build a web UI and show the result in a table, like leptos-struct-table.

Hope there will be a simple demo to make cornucopia and Leptos work together.

blowback commented 3 months ago

It can work with leptos fine, but it is not entirely frictionless in SSR mode: you have to define all the query types twice, once for the backend (these types are generated by cornucopia) and once for the front-end (manually re-define all the types you're interested in).

You can't currently use cornucopia's generated types in the front-end directly because of all the additional dependencies on futures, GenericClient, tokio_postgres etc. which will break the front-end build with the dreaded slew of mio errors.

As an alternative to WET, you could maybe write a macro to extract the front-end types, but that would be quite brittle to cornucopia changes.

My strategy is to wait for PR#211 to land and hope that in its final form I can use the types from that (not possible in its current state).

Seems like this is no different from sqlx with leptos: in leptos-heavy-metal-stack you can see where Todo is declared twice (lines 22, 29).

yingweixiang commented 3 months ago

Thanks for your comment. That's very helpful.