Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cloudflare workers #337

Open
vedantroy opened this issue Apr 28, 2022 · 11 comments · May be fixed by #867
Open

Support Cloudflare workers #337

vedantroy opened this issue Apr 28, 2022 · 11 comments · May be fixed by #867

Comments

@vedantroy
Copy link

It would be nice if the Edge DB JS client supported Cloudflare workers: https://workers.cloudflare.com/

To do this, any references to unsupported node polyfills would need to be removed.
It seems like there is only one? (Buffer)

@vedantroy vedantroy changed the title Cloudflare workers Support Cloudflare workers Apr 28, 2022
@elprans elprans transferred this issue from edgedb/edgedb Apr 28, 2022
@colinhacks
Copy link
Contributor

I believe this would require a ground-up rewrite, since we rely on a ton of Node.js APIs from crypto, fs, path, os, net, tls, readline, and stream. Unless I'm missing something? cc @tailhook

@elprans
Copy link
Member

elprans commented May 4, 2022

What about Deno? I've read somewhere that Deno is explicitly compatible with Cloudflare workers.

@tailhook
Copy link
Contributor

tailhook commented May 4, 2022

I believe this would require a ground-up rewrite, since we rely on a ton of Node.js APIs from crypto, fs, path, os, net, tls, readline, and stream. Unless I'm missing something? cc @tailhook

I think most of that is possible to get rid of (fs and path are probably by disabling that feature), but the biggest issue is raw network sockets. I think CloudFlare workers don't support them. So we need some WebSocket mapping of the protocol, which I think we didn't implement yet.

@elprans
Copy link
Member

elprans commented May 4, 2022

We actually already implement protocol tunneling over the Fetch API. The only thing that isn't supported is transaction blocks.

@haikyuu
Copy link

haikyuu commented Oct 21, 2022

Is transaction support coming in the near future (4-8 months) for cf workers?

@elprans
Copy link
Member

elprans commented Oct 21, 2022

Transactions are supported in edgedb+http, just only the all-at-once kind. I.e you can send a bunch of statements together and they'll be executed atomically. But you can't start a transaction and keep it open. The difficulty of implementing open-ended transactions over a stateless protocol like HTTP is that you need sticky sessions, which introduces lots of complexity to the stack.

@haikyuu, do you have an use case example that can't be done as a single db roundtrip?

@haikyuu
Copy link

haikyuu commented Oct 21, 2022

@haikyuu, do you have an use case example that can't be done as a single db roundtrip?

No that's probably plenty enough for the foreseeable future 😅

@scotttrinh
Copy link
Collaborator

Related to #387

@PastelStoic
Copy link
Contributor

From what I understand of the HttpClient, both this and #387 can be closed.

@bdematt
Copy link

bdematt commented Jan 5, 2024

@PastelStoic Is this resolved? I'm trying to call createHttpClient in a Cloudflare Function and still getting the error ReferenceError: process is not defined.

@TreeOfLearning
Copy link

TreeOfLearning commented Jan 15, 2024

@PastelStoic Is this resolved? I'm trying to call createHttpClient in a Cloudflare Function and still getting the error ReferenceError: process is not defined.

Yep - also running into this, specifically from a call to getEnv in parseConnectDsnAndArgs; so my guess is this is not resolved :/ Sample:

const e = edgedb.createHttpClient({
    dsn: env.EDGEDB_DSN,
    tlsSecurity: "insecure",
});

const res = await e.querySingle<number>("SELECT 1");

@scotttrinh scotttrinh linked a pull request Feb 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants