prisma icon indicating copy to clipboard operation
prisma copied to clipboard

Support for Cloudflare's new SQLite database D1

Open mikecann opened this issue 3 years ago • 41 comments

Cloudflare have just announced their first relational DB D1 which is based on SQLite.

https://blog.cloudflare.com/introducing-d1/

Would be awesome if Prisma could support it one day..

mikecann avatar May 12 '22 04:05 mikecann

That would be a really great feature to have

mkuchak avatar May 21 '22 22:05 mkuchak

Just came here for this. This will be epic!

jgb-solutions avatar Jun 04 '22 16:06 jgb-solutions

D1 is based on SQLite so it may work by default?

Edit: nevermind (see this HN comment)

liamross avatar Jun 15 '22 03:06 liamross

Can we expect to see a first iteration in the near future, or should we not hold our breath? I am planning to port a few projects to run fully on Cloudflare D1 in the coming months, and no support from Prisma would mean that I have to start using other ORMs.

fredgig avatar Aug 02 '22 20:08 fredgig

Can we expect to see a first iteration in the near future, or should we not hold our breath? I am planning to port a few projects to run fully on Cloudflare D1 in the coming months, and no support from Prisma would mean that I have to start using other ORMs.

As far as im aware D1 still isnt GA

mikecann avatar Aug 03 '22 01:08 mikecann

Can we expect to see a first iteration in the near future, or should we not hold our breath? I am planning to port a few projects to run fully on Cloudflare D1 in the coming months, and no support from Prisma would mean that I have to start using other ORMs.

As far as im aware D1 still isnt GA

It's still closed beta.

marcus-sa avatar Aug 03 '22 08:08 marcus-sa

D1 is based on SQLite so it may work by default?

Edit: nevermind (see this HN comment)

As per the new blog post from cloudflare at https://blog.cloudflare.com/whats-new-with-d1/

When running wrangler dev -–local -–persist, an SQLite file will be created inside .wrangler/state. You can then use a local GUI program for managing it, like SQLiteFlow (https://www.sqliteflow.com/) or Beekeeper (https://www.beekeeperstudio.io/).

So, we can get the sqlite db locally & using that, we should be able to use prisma without any additional setup only on development. Just need to implement a connection for production

DaniAkash avatar Oct 10 '22 10:10 DaniAkash

Any guidance on how to create a connection for production?

buzinas avatar Oct 18 '22 22:10 buzinas

Any guidance on how to create a connection for production?

I could imagine creating a separate worker to act as a network adapter between Prisma and D1. Other option, if possible at all, is to pass the instance of D1 (provided via binding) directly to the prisma client.

Notice, the first approach would allow to use D1 outside workers as well, so probably a more scalable option) At the same time, because the solution would involve workers, I could imagine Cloudflare recognising the need for network connections to the D1 and rolling out a more optimised solution. So, let’s wait a bit and watch where things move.

Right now there is not much on guidance, because D1 is still in closed beta.

[Now I've read their recent blog post on procedures, maybe there could be a way to provide Prisma client via the procedures binding, although, I believe the whole idea of procedures could be used as a more fine tuned abstraction then a simple ORM. To me it seems that a connector to D1 would be not worth its value. As of now, it does not seem like Cloudflare team would have something traditional and down to earth in mind. They work on their own serverless edge world which an ORM like Prisma would certainly limit a lot. Build new tools or wait for new tools to be built)]

alexandrutocar avatar Nov 08 '22 08:11 alexandrutocar

It looks like Cloudflare opened up the D1 beta today to more users. This would provide a lot of value. If anyone needs me to test anything and/or work on the adapter let me know.

damianesteban avatar Nov 16 '22 17:11 damianesteban

+1 for D1 support from Prisma.

jgb-solutions avatar Nov 16 '22 17:11 jgb-solutions

I think uceumice's comment is practical and interesting way how to integrate prisma-client to D1. Prisma-internal has DataProxyEngine and recommends it for serverless environments like Cloudflare Workers and Deno Deploy. maybe if it can self-host Data Proxy API and develop a module to access own database, it might be the first way to integrate with D1.

laiso avatar Nov 20 '22 06:11 laiso

D1 is now available as an open alpha, i'll be looking into possible ways to use Prisma without the production driver - like extracting the underlying query from the prisma client using the approach from https://github.com/prisma/prisma/issues/5026#issuecomment-1235067013

DaniAkash avatar Nov 21 '22 12:11 DaniAkash

@DaniAkash keep us posted!

Also keen to hear official word from either Cloudflare or Prisma... I imagine, as Cloudflare offers a first-class S3 interface for R2, they would offer a first-class Prisma interface for Prisma.

Relevant reading:

  • https://www.prisma.io/docs/data-platform/data-proxy
  • https://www.prisma.io/docs/reference/database-reference/connection-urls
  • https://www.prisma.io/docs/reference/database-reference/supported-databases
  • https://github.com/koskimas/kysely
  • https://github.com/colinhacks/zod
  • https://github.com/jacob-ebey/remix-dashboard-d1
  • https://github.com/drizzle-team/drizzle-orm/tree/main/examples/cloudflare-d1 - probably what I'll go with

balupton avatar Nov 29 '22 05:11 balupton

@laiso I agree that sounds like a good approach. I’m going to play around with it next week.

damianesteban avatar Dec 21 '22 01:12 damianesteban

I would also love to have Prisma support in d1, it would let me move my entire stack into cloudflare

derekhearst avatar Dec 22 '22 02:12 derekhearst

@balupton update on my personal project,

I couldn't get the underlying Prisma queries effectively without sacrificing good DX. Ended up refactoring most of my code to kysely along with their D1 dialect. Similar approach was recommended for PlanetScale edge driver as well

Looking forward to see how Prisma will support Cloudflare D1 in the future

DaniAkash avatar Jan 11 '23 11:01 DaniAkash

+1

darasus avatar Jan 18 '23 21:01 darasus

desperately looking for it

jahir9991 avatar Jan 27 '23 20:01 jahir9991

i will die waiting for prisma

anaibol avatar Feb 02 '23 21:02 anaibol

Can someone explain, why some comments are being marked as abuse? Is it a mistake, or should it instead be marked as off topic? Does someone know?

alexandrutocar avatar Feb 03 '23 17:02 alexandrutocar

Just thought everyone coming to this thread to know that until we get D1 support, there is a decent alternative I've found that is also completely free. Prisma's data proxy has a guide to deploy prisma serverlessly on cloudflare pages, which is a bit finicky to set up but you can redirect to mongodb atlas (free) or another provider of your choosing and the latency isn't too bad. I made a test site with this stack here.

derekhearst avatar Feb 03 '23 17:02 derekhearst

@uceumice Comments that add nothing to the documentation but ping all people that replied before or are subscribed to the issue are abusive. +1 is one of those types of comments. If you want to express support for a feature request leave a 👍 on the original comment or leave a comment with your actual use case. We have to handle dozens to hundreds of these per day, and it does nothing else but waste our time and effort.

janpio avatar Feb 03 '23 17:02 janpio

Comments that add nothing to the documentation but ping all people that replied before or are subscribed to the issue are abusive. +1 is one of those types of comments.

Thank-you for remindering people how wasteful these comments are. It's an honest mistake and easy to leave a comment without understanding how many people you disrupt doing that, so a friendly reminder once in a while is apprecaited.

Thanks for your hard work @janpio, and don't take it too hard @uceumice. "+1" comments can seem harmless and GitHub doesn't do a good job of warning you how many people you're actually spamming, but they really do send me many notifications a day on high traffic issues like this, so I apprecaite the pain they cause for open source maintainers who have to deal with many more.

MarkBennett avatar Feb 03 '23 17:02 MarkBennett

There is any news about this ?

cth-latest avatar Jul 30 '23 19:07 cth-latest

No, not yet. We will post an update when we start work or have something to share or test.

janpio avatar Jul 31 '23 18:07 janpio

No, not yet. We will post an update when we start work or have something to share or test.

We hope that will be very soon! 😉

ansbr avatar Aug 03 '23 15:08 ansbr

When you announced you would be partnering with Cloudflare and called "Data DX" I was hoping this would be included

sergiocarneiro avatar Aug 03 '23 17:08 sergiocarneiro

+1

emircanerkul avatar Aug 19 '23 14:08 emircanerkul

Not to be that grumpy old person, but can I point out that commenting "+1" generates a lot of spam for those of us following many issues like this. To show your support, can you please react to the original issue with the 👍🏼 emoji?

If you're just looking to get updates, you can do so without leaving a comment by using the "Subscribe" button near the top of this issue.

Thanks for your understanding! ❤️

MarkBennett avatar Sep 07 '23 19:09 MarkBennett