cloudflare / workers-rs

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

[Feature] D1 Support #221

Open vidiabtc opened 2 years ago

vidiabtc commented 2 years ago

Is there an existing issue for this?

Description

It would be great if workers-rs had the functionality of wrangler@d1. Although I understand that it may not be the best time to do this as D1 is still in private beta, but it would be cool if the D1 integration was ready to go by the time D1 is public!

Yrlish commented 2 years ago

I would also be interested in this. I'm also aware that the current state of D1 is in private beta so it may not be doable at the moment.

So I am curious if it is possible to have a worker using both Rust and Typescript in the meanwhile? Where the D1 code is located in Typescript and the main worker code in Rust.

zebp commented 2 years ago

So I am curious if it is possible to have a worker using both Rust and Typescript in the meanwhile? Where the D1 code is located in Typescript and the main worker code in Rust.

It is possible, but it's a bit messy. You can use wasm-bindgen snippets generated from TypeScript and then call it from your Rust or you avoid using worker-build and use esbuild yourself to bundle in some JavaScript that you do your D1 calls in. In the future I think we'll have to figure out how we're going to go about private-beta bindings, possible through an unstable feature flag?

Until then, D1 support is probably off the table for now.

Yrlish commented 2 years ago

In the future I think we'll have to figure out how we're going to go about private-beta bindings, possible through an unstable feature flag?

Yeah this sounds like a good idea, some sort of unstable branch for non-GA features.

I was also thinking of an alternative solution. Having two separate workers, one in Rust and one "normal" in Typescript and connecting them via a service binding. This would mean having to transfer stuff between them though.

yzn-h commented 1 year ago

it is now open alpha ╰(°▽°)╯

Yrlish commented 1 year ago

So do we have an status update on this?

KianNH commented 1 year ago

https://github.com/cloudflare/workers-rs/pull/246

Keavon commented 1 year ago

270

spicyzboss commented 1 year ago

I can't enable d1 feature but I have seen this commit that not released in 0.0.17. Any updates?

dev-ardi commented 1 year ago

I can't enable d1 feature but I have seen this commit that not released in 0.0.17. Any updates?

It's been released as of 0.0.18:

worker = {version = "0.0.18", features = ["d1"] }