cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.6k stars 282 forks source link

[Feature] ORM Support for Rust Workers #612

Open ChihweiLHBird opened 3 months ago

ChihweiLHBird commented 3 months ago

Is there an existing issue for this?

Description

JavaScript workers are capable of Prisma ORM to query Cloudflare D1 database: https://developers.cloudflare.com/d1/tutorials/d1-and-prisma-orm/

It would be very nice to have a similar ORM support in the Rust workers as well.

Brayan-724 commented 3 months ago

Hi @ChihweiLHBird, we (@RustLangES) are planning to do an implementation of an agnostic ORM focused on Cloudflare Workers in Rust. You can follow our progress in this discussion. We are an spanish community, but we accept people who speak any language.

kflansburg commented 3 months ago

We've discussed an integration with something like SQLx, but the API surface that we would need to implement is quite daunting.

Brayan-724 commented 3 months ago

@kflansburg We already have an experimental ORM for one of our project (The api is not the best). As I said it is so experimental, but we are working on to build a library to extend Cloudflare Workers. It will have a lot of utilities to do the best developer experience.

The same as @ChihweiLHBird, I invite you to our discussion or discord to share us your ideas.

extraymond commented 3 months ago

While not a full a ORM, I created a PR to allow cornucopia to be used within cloudflare-worker. Since all the query are build in compile time, the only thing I need to do is allow tokio-postgres to compile in wasm.

https://github.com/cornucopia-rs/cornucopia/pull/256


cornucopia is a SQL first query-builder to generate rust query.

extraymond commented 1 month ago

Just found this in the sea-orm repo https://github.com/SeaQL/sea-orm/blob/039e4423d3ef2fe4959c0b19c2b37bbd3f90d9b9/examples/proxy_cloudflare_worker_example/README.md

By creating proxy-backend allows one to use sea-orm that calls D1, maybe the same can be made for postgres that calls the socket.connect without having to rely on sqlx(used by sea-orm) for providing the connection.

kflansburg commented 1 month ago

Just found this in the sea-orm repo https://github.com/SeaQL/sea-orm/blob/039e4423d3ef2fe4959c0b19c2b37bbd3f90d9b9/examples/proxy_cloudflare_worker_example/README.md

By creating proxy-backend allows one to use sea-orm that calls D1, maybe the same can be made for postgres that calls the socket.connect without having to rely on sqlx(used by sea-orm) for providing the connection.

This does look like a pretty simple interface to implement. I haven't used Sea ORM. Pulling this in for D1, as well as supporting Hyperdrive (behind a crate feature) seems pretty interesting.

Upbolt commented 6 days ago

this is an issue i first posted @ https://github.com/SeaQL/sea-query/issues/838, but i'll just copy over the contents here in case it has any relevance

trying to use cloudflare d1 with sea-orm through the example proxy integration, but

https://github.com/SeaQL/sea-orm/blob/5f1a9d2a46c9b0776c57311782e72dab8e5c6948/examples/proxy_cloudflare_worker_example/src/orm.rs#L63-L97

null values hit the _ case since internally D1Result::results() returns a javascript array which will treat null values as their own type when deserialized through serde, making it incompatible with sea-query's Value enum, which requires to know the type ahead of time

https://github.com/SeaQL/sea-query/blob/b91ba14f680e11a2e813880b775299a44d279c66/src/value.rs#L127-L216

is there a reasonable way to accommodate for this?