DEV Community

Cover image for Set up a free PostgreSQL database on Supabase to use with Prisma

Set up a free PostgreSQL database on Supabase to use with Prisma

Mahmoud Abdelwahab on June 11, 2021

Supabase is a backend-as-a-service built on top of open source technologies. It gives you a database, authentication, a REST API, real-time subscri...
Collapse
 
kiwicopple profile image
Copple • Edited

This is a great guide!

I'm a cofounder Would you be interested in adding this to the Supabase docs? If yes, perhaps you can message me on twitter: twitter.com/kiwicopple

Collapse
 
zernonia profile image
Zernonia

I think you have the wrong account tagged. 😂

Collapse
 
kiwicopple profile image
Copple

thanks! removed the tag

Thread Thread
 
polterguy profile image
Thomas Hansen

Psst, FYI, we've analysed the situation, and made a joint strategical decision, which is that we'll treat you guys as gentlemen. As to "the other guys", not so much. A piece of advice, go get some popcorn ^_^

Thread Thread
 
kiwicopple profile image
Copple

Thanks for the kind words Thomas. I think you should treat everyone as gentlemen 🙂 (or ladies).

Thread Thread
 
polterguy profile image
Thomas Hansen • Edited

I think you should treat everyone as gentlemen

I would share your opinion here, if it wasn't for that tiny little fact of that "somebody" registered the hyperlambda.com domain, and it wasn't us - And that company in Japan sharing our name, who happens to be "delivering cloud services" ...

I treat people the way the deserve to be treated, everything else is misunderstood love. When I'm dealing with "children" that weren't taught manners by their parents, I will raise them as such, tough luv included if called upon ...

A friend of mine said ...

Him who isn't given manners by his parents, will be given manners by the world. When the world gives you manners, it is painful

The way I see it, they should pay me for the "services" I'm about to apply to them ...

Collapse
 
rosswaycaster profile image
Ross Waycaster

Thanks for the guide! I've been interested in using Prisma with Supabase, mainly to integrate it with Blitz.js. How can we utilize Supabase Auth with Prisma? Is there a way to send the user's JWT through Prisma so we can take advantage of Supbase Auth Policies? Thanks!

Re: @thisismahmoud @kiwicopple

Collapse
 
annjkai profile image
Annika Kaiser

@kiwicopple I'd be super interested in this too - I tried using Prisma together with Supabase but there are problems importing the Auth DB and my app's DB simultaneously. Even if I did, I'd have to handle the JWT Tokens on my own, why I don't have experience doing. Would love to know if you can expand on this guide with this use case in mind. Thank you!

Collapse
 
thisismahmoud profile image
Mahmoud Abdelwahab

hey @annjkai and @rosswaycaster 👋🏼 I haven't tried using Supabase Auth with Prisma yet. If I'm able to make it work I'll write a blog post 😄

Collapse
 
zernonia profile image
Zernonia

Hi @thisismahmoud , could you explain in why should we use Prisma instead of @supabase/supabase-js directly? It feels like an extra effort just to use Supabase.

Collapse
 
aftabbuddy profile image
Aftab Alam

Hey, though you asked @thisismahmoud I think I have the answer :-)

This article is for Prisma users(and it's written from Prisma's point of view), who use it for everything ranging from DB Management, CRUD operations to Migrations. Prisma works with a PostgreSQL instance (local or cloud) and Supabase let's you connect with the DB that powers your apps directly too. So, in Supabase, Prisma has found one more great cloud-managed PostgreSQL instance that you can connect with following the instructions shared in this article.

@thisismahmoud Hope, that's an all right explanation?

Collapse
 
zernonia profile image
Zernonia

Everything make sense when you said this is for Prisma users. As I am not one of them, I got confused.

Thank you for your input yar!

Collapse
 
thisismahmoud profile image
Mahmoud Abdelwahab

Yup that's a perfect answer! thank you so much 😄

Thread Thread
 
amosbastian profile image
Amos Bastian

Then what is the benefit of using Supabase with Prisma over just having your own Postgres database on the same server as your API?

Thread Thread
 
aftabbuddy profile image
Aftab Alam

The article just shows how easy it is to use Prisma with a cloud PostgreSQL instance. Supabase letting you access the PostgreSQL instance and independently use it, is a very powerful thing. You can prefer to use Supabase client, to perform Auth, and CRUD operation, for which Supabase is known for, but if you don't want that you can also interact with the DB that powers it, to have your hand-rolled, or Prisma-rolled CRUD methods and have it behave as you like.

Prisma loves(and plays well) PostgreSQL(your instance) or PostegreSQL(cloud instance: Heroku, Supabase, Planetscale, etc.) equally. Consider this just as a reference to one more possible integration type you may chose and it's not particularly Supbase v/s. your DB.

Collapse
 
medicmen profile image
MedicMen

I Did everything like in starter, but I got an error during connection --> Error: P1001: Can't reach database server at ...

Do you know why ?

Collapse
 
peteoyable profile image
Julien Boulevart

Hey @medicmen I know it's been awhile but I had the same issue yesterday and I was able to find the solution, maybe you have the same issue.

It turns out my password had some special symbols, and when using the direct connection string, you have to percent-code those symbols. It is specified in the doc here. It should probably be said somewhere else but still, I have managed to have the connection working as expected.

Maybe it is too late but I hope you did not give up : )

Collapse
 
touhidrahman profile image
Touhid Rahman

Using id Int @id @default(autoincrement()) in prisma schema creates an id field in supabase with following function -
nextval('"Entity_id_seq"'::regclass)

Which is obviously a syntax error in supabase. Do you have any suggestion to overcome this?

Collapse
 
harcourthamsa profile image
Harcourt Hamsa

Such a great article! Thank you for creating this <3