edgedb-js icon indicating copy to clipboard operation
edgedb-js copied to clipboard

Support Cloudflare workers

Open vedantroy opened this issue 3 years ago • 22 comments

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 avatar Apr 28 '22 07:04 vedantroy

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

colinhacks avatar May 04 '22 01:05 colinhacks

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

elprans avatar May 04 '22 01:05 elprans

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.

tailhook avatar May 04 '22 13:05 tailhook

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

elprans avatar May 04 '22 15:05 elprans

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

haikyuu avatar Oct 21 '22 21:10 haikyuu

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?

elprans avatar Oct 21 '22 22:10 elprans

@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 😅

haikyuu avatar Oct 21 '22 22:10 haikyuu

Related to #387

scotttrinh avatar May 02 '23 16:05 scotttrinh

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

PastelStoic avatar Jul 05 '23 15:07 PastelStoic

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

bdematt avatar Jan 05 '24 18:01 bdematt

@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");

TreeOfLearning avatar Jan 15 '24 17:01 TreeOfLearning