cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.56k stars 278 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 2 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 2 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 2 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 2 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.