Тёмный

How to set up Prisma with Next.js and Postgres! 

Build SaaS with Ethan
Подписаться 7 тыс.
Просмотров 36 тыс.
50% 1

Опубликовано:

 

3 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 88   
@GianlucaCassol-jz4ek
@GianlucaCassol-jz4ek 4 месяца назад
I've been searching for a way to use Postgres with Next.js. Amongst more than 20 videos, this was the best explained one and the only that actually helped me. Thank you so much, you gained a loyal follower
@AngusGaukrogerDev
@AngusGaukrogerDev 5 месяцев назад
Nice one Ethan, my project is now ready for success. Thanks for the in depth run down and explanation, really helped me
@alexandergarzo9415
@alexandergarzo9415 Год назад
I found the perfect channel with the perfect stack for my Saas! Thank you!!!
@ethan_mick
@ethan_mick Год назад
🥹 Thank you! Can't wait to see you around!
@Mantenner
@Mantenner Год назад
Mate you are a legend, so many tutorials I watched focused so much around vercel, supabase etc and not actually setting up the whole process, your tutorial is the first one that I successfully connected to my own locally hosted postgres DB. Thanks so much. The way you explain every step of the way is just brilliant too.
@ethan_mick
@ethan_mick Год назад
Thank you so much for the kind words!! I think it's really important for people to understand the fundamentals and to be able to build software without specific vendors -- being able to drop down and use just regular Postgres gives you the most power and flexibility.
@stephanpaul8954
@stephanpaul8954 Год назад
I've been wanting to learn more about next and there has been SOOO many changes extremely recently. So im watching videos from 3 weeks ago and they just don't apply anymore 🤣 I am also wanting to learn prisma so this was extremely helpful!! Thanks a ton
@ethan_mick
@ethan_mick Год назад
Thanks for watching! Yeah, it's kinda crazy. We're watching in real-time as Vercel iterates on the app directory, and each release changes things pretty dramatically. That being said, they've warned it's still beta, so they can be pretty dramatic with the changes. Let me know what else you'd like to see!
@y2b5
@y2b5 Год назад
Same here - that's why I find it so useful when Ethan elaborates on the recent changes in his examples.
@firattech
@firattech 11 месяцев назад
Very helpful video and greate explanation. I was having very hard time getting data from my database to be displayed. Thank you for the video!
@GabrielMartinez-ez9ue
@GabrielMartinez-ez9ue 11 месяцев назад
just ran into your channel. Great stuff mate. You are introducing some new valuable stuff which i am incorporating to my apps.
@h13q18
@h13q18 2 месяца назад
If you are trying to use prisma with supabase add in .env file variable with name DIRECT_URL, which will be the same as DATABASE_URL, but will have a 5432 port, instead of 6543. After that update your schema.prisma file and add directUrl after url. It will look like this: datasource db { provider = "postgresql" url = env("DATABASE_URL") directUrl= env("DIRECT_URL") }
@ranatariqnajam
@ranatariqnajam Месяц назад
Hi, Mate i saw your video about postgres it is very nice and informative, i understand it well, But when you entered the command into terminal , please also mention the command for windows users. Thanks
@H3llT33HoW
@H3llT33HoW 10 месяцев назад
Very helpful, thanks
@zoki5388
@zoki5388 Год назад
Hey Ethan any tips on how to save image urls to prisma?
@ethan_mick
@ethan_mick Год назад
Sure! Do you want to save the image data itself or just a URL that points to the image? If you're saving just the URL, treat it as a string and use String. If you are saving the image data itself (fine for small images, not recommended for large/lots of images) use bytes: www.prisma.io/docs/reference/api-reference/prisma-schema-reference#bytes If you're looking to save a lot of images, consider using blob storage either in the cloud (S3, etc.) or with a Postgres Extension (www.postgresql.org/docs/current/lo.html), and then just save the lookup string/url in the table. Let me know if you want a more detailed walkthrough and what you're aiming to achieve!
@zoki5388
@zoki5388 Год назад
​@@ethan_mick Hey, I'm sorry for late replay I was sick. I went with your first suggestion, turning image to string and sending it to cloudinary API and returning string. I hope you got one of those two jobs, and I hope you will keep making videos. If you need any video suggestions let us know.
@ethan_mick
@ethan_mick Год назад
No worries at all, I hope you feel better! Glad you got it working, I think your solution is dead on. And yes, I did get one of the two jobs 😁 !! Very excited to keep making videos!
@appduldaily
@appduldaily 11 дней назад
Stright to the point, easy to follow, clear explanations, thank you so much, have a nice day !
@joylodralive
@joylodralive Год назад
Hey Ethan, thanks for making this video! Do you know what's the most cost-efficient option to host PostgreSQL database, yet still scalable? Or, what’s your personal preference?
@ethan_mick
@ethan_mick Год назад
Hello and thanks! I think this heavily depends on your needs. Generally "cost-efficient" and "scalable" are orthogonal. You're sacrificing one for the other. For small side projects I run a Postgres instance on a VPS ($6/mo) and that works great. For clients in production I use a cloud provider, either AWS+RDS, Supabase, or Digital Ocean's Databases. It's more important to have backups and redundancy than be super cheap. Generally, I think just running your own Database (ethanmick.com/how-to-install-and-setup-postgresql-14-on-ubuntu-20-04/) it good until you want to really take your project and scale it. Then I move to a cloud provider.
@joylodralive
@joylodralive Год назад
@@ethan_mick Hey thanks for your response. I've been hearing a lot about hosting on Docker. Any thoughts?
@ethan_mick
@ethan_mick Год назад
​@@joylodralive Hosting Next.js or Postgres in docker? I run Next.js in docker all the time, and I think this works well. I don't recommend Postgres in docker except for local development. It adds additional complexity with connecting, scaling IO, and expanding storage. Docker is fantastic for 12 factor ephemeral apps. Databases are meant to be started and never stopped and should be rock solid. Adding docker into the mix causes more things to break for that layer. You can do it, of course, but need to be very careful that you aren't losing data.
@Fabbaist11
@Fabbaist11 3 месяца назад
I noticed you searching through a long list of commands when searching for docker postgres in the terminal. What are you using to do that?
@robb7148
@robb7148 17 дней назад
Great tutorial! Short and to the point. Thanks!
@rutx122
@rutx122 6 месяцев назад
So with this can I build a small ecommerce just with prisma and maybe cloudinary to save the images?
@rutambhagat4556
@rutambhagat4556 Год назад
I tried to use this with postgres db from railway app and supabase but on both of them i cannot seem to be able to seed the database for some reason, I have followed everthing else from the tutorial
@ethan_mick
@ethan_mick Год назад
What was the particular error? When connecting to a remote database make sure the DATABASE_URL is correctly set to use that database and then Prisma should pick it up automatically.
@rutambhagat4556
@rutambhagat4556 Год назад
@@ethan_mick pnpx prisma db seed .../share/pnpm/store/v3/tmp/dlx-20194 | +2 + .../share/pnpm/store/v3/tmp/dlx-20194 | Progress: resolved 2, reused 2, downloaded 0, added 2, done Environment variables loaded from .env Running seed command `ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts` ... An error occurred while running the seed command: Error: Command failed with ENOENT: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts spawn ts-node ENOENT  ERROR  Command failed with exit code 1: prisma db seed pnpm: Command failed with exit code 1: prisma db seed at makeError (/home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:23074:17) at handlePromise (/home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:23645:33) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.handler [as dlx] (/home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:219303:7) at async /home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:227043:21 at async main (/home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:227010:34) at async runPnpm (/home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:227242:5) at async /home/voldemort/.local/share/pnpm/global/5/.pnpm/pnpm@7.29.1/node_modules/pnpm/dist/pnpm.cjs:227234:7
@rutambhagat4556
@rutambhagat4556 Год назад
I tried both connection strings from supabase and railway app. I also copied files from your git repo to avoid any syntax errors but didnt work
@ethan_mick
@ethan_mick Год назад
@@rutambhagat4556 Are you on the latest version of Prisma? Double check that and if you have installed "typescript ts-node @types/node" locally as well.
@rutambhagat4556
@rutambhagat4556 Год назад
@@ethan_mick This is my package.json file { "name": "next_auth", "version": "0.1.0", "private": true, "scripts": { "dev": "next dev", "build": "prisma generate && next build", "start": "next start", "lint": "next lint" }, "prisma": { "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" }, "dependencies": { "@prisma/client": "^4.11.0", "@types/node": "18.15.3", "@types/react": "18.0.28", "@types/react-dom": "18.0.11", "next": "13.2.4", "react": "18.2.0", "react-dom": "18.2.0", "typescript": "4.9.5" }, "devDependencies": { "prisma": "^4.11.0", "ts-node": "^10.9.1" } }
@rezaamya6444
@rezaamya6444 8 месяцев назад
Thanks. running `npx prisma generate` on 9:13, is not doing anything and making any effect in my system. I ran `npx prisma migrate dev --name add unique` and it build a migration file for me. It is strange how you updated your init migration file. Isn't it against the concept of migration?
@ronaldpaek
@ronaldpaek Год назад
is npx vs pnpm dlx any difference for prisma init? i notice you're using pnpm
@ethan_mick
@ethan_mick Год назад
I'll write an article about this, but basically they are the same, but `pnpm` caches things in a central cache and only downloads things once, ever. It's fast and saves disk space.
@codedwebs
@codedwebs 9 месяцев назад
is it possible to get data from db without declaring schema ? as my db was prebuilt having data...now i want to connect it with next prisma, what should i do ?
@treva383
@treva383 7 месяцев назад
When am in development mode results from database are showing up but when I deployed on vercel, it is failing to fetch
@adehenry9591
@adehenry9591 Год назад
You’re a very good teacher 👍🏾....smashing that subscribe button!
@ethan_mick
@ethan_mick Год назад
Thank you so much!! I means so much hearing that :)
@sayazdir
@sayazdir 11 месяцев назад
thanks Jim
@lhfskal
@lhfskal 3 месяца назад
THANK YOU
@benyamin4634
@benyamin4634 9 месяцев назад
thanks
@issiagaconde
@issiagaconde Год назад
thank you ❤❤❤❤❤❤
@ethan_mick
@ethan_mick Год назад
Of course! Glad I could help!
@ijuji_codes-gz3iv
@ijuji_codes-gz3iv 9 месяцев назад
very helpful video, unlocked my hands :)
@ThunderboltPath
@ThunderboltPath 8 месяцев назад
This is fantastic! I've been looking for such bite-site tutorials no longer than 15 minutes because that's just how much my brain can handle. State-of-the-art tech stack and clear cut explanation, are you kidding me. Your channel is way too underrated! I sure will build saas with you, Ethan!!
@KiranKumar-or5uy
@KiranKumar-or5uy 4 месяца назад
Nice Lesson, Thank you Ethan.
@devcore1
@devcore1 10 месяцев назад
14:47 pages directory example
@mcFishXtraMayo
@mcFishXtraMayo 11 месяцев назад
insanely perfect tutorial, liked and subscribed dude thanks a lot
@jona171998
@jona171998 Год назад
Thanks for this tutorial, it what I was looking with the app exp folder of next13. Could I do the same as pages/example.tsx in app/example/page.tsx?
@ethan_mick
@ethan_mick Год назад
Yes you can. In a React Server Component (in the app dir) you can just use Prisma directly: github.com/ethanmick/prisma-next-postgres-example/blob/main/app/page.tsx#L4-L8. Otherwise you need to use getServerSideProps: github.com/ethanmick/prisma-next-postgres-example/blob/main/pages/example.tsx#L13
@luckystrike5882
@luckystrike5882 Год назад
Hey Ethan, I've been loving your videos. It's rare that someone breaks down everything and shows best practices. I was following along and everythig worked until you got to the part using the Pages method. When I import prisma from lib, I get an error saying "PrismaClient is unable to run in the browser." I fixed it by turning it into a client component with 'use client' but wondering what exactly Vercel changed. Thanks again!
@ethan_mick
@ethan_mick Год назад
When you are using Prisma in the `pages` directory, make sure you are only using it within a function that runs on the server, eg: getServerSideProps. You can't use it anywhere else. Next.js will code split that out for you so it won't be included in the client.
@agcodes
@agcodes Год назад
damn, this was so informative and well explained, thanks a lot ! waiitng for new videos on Nextjs prisma and maybe tRPC tysm. (+1 subscriber)
@ethan_mick
@ethan_mick Год назад
Thank you! I'm planning on playing around with tRPC. The Server Actions in Next.js might change that though...
@keithjackson4552
@keithjackson4552 7 месяцев назад
If I am trying to follow your Set up Next-Auth with Next.js and Prisma video and I can not seem to get the User to be defined when Next-Auth is validating so when it redirects I get a 404. Can you recommend possible fixes, tutorials or possibly meet up for a screen share? Thanks have a nice day.
@ALVIERIDEVELOPER
@ALVIERIDEVELOPER 2 месяца назад
hey, you found any fixes yet?
@keithjackson4552
@keithjackson4552 2 месяца назад
@@ALVIERIDEVELOPER I did not find a fix for Next-Auth but I switched to clerk and everything works great now.
@sujathareddyp9444
@sujathareddyp9444 Год назад
really superb explanation sir i am from India I usually watch your videos. thank you so much
@ethan_mick
@ethan_mick Год назад
Thank you! I love helping people out from all over :)
@fujisan0388
@fujisan0388 Год назад
Thank you for the video and what is the DB graphical tool you're using?
@ethan_mick
@ethan_mick Год назад
Yep, it's eggerapps.at/postico2/ ! It costs ~$60, so not cheap, but it's so helpful when working with Postgres.
@hanyafifi2906
@hanyafifi2906 Год назад
what app is used by Ethan to check out the postgres db tables as shown in minute 6:42
@ethan_mick
@ethan_mick Год назад
I use: eggerapps.at/postico2/ It is not free however.
@icongrindsetsfj
@icongrindsetsfj Год назад
Fantastic explanation. Cleared so many doubts. Please keep making long form contents like for learners like us. Thank You Boss
@ethan_mick
@ethan_mick Год назад
Thank you, I will! Glad I could help :)
@White_cow_story
@White_cow_story Год назад
thx bro,i feel i'm somwhere close to the ture with your videos
@ethan_mick
@ethan_mick Год назад
Heck ya, keep crushing it
@austinwhitbeck3362
@austinwhitbeck3362 Год назад
Haven't been a dev very long and I've been wanting to try and practice some fullstack skills to better communicate with the backend devs on my team. This was a great tutorial to help me get started and I appreciate the time and effort to show both the /app directory way and the /pages way! Thank you!
@ethan_mick
@ethan_mick Год назад
Glad I could help! Let me know if you need anything else :)
@SuperR09er
@SuperR09er Год назад
I just want to commend you that your videos are one of the most informative, focused and easy to understand of all the instructors on youtube. Continue like that :)
@ethan_mick
@ethan_mick Год назад
Thank you so much! I plan to!
@akebu6
@akebu6 Год назад
This is truly helpful, saved me a lot of time searching online how to do this. Thanks Ethan!
@ethan_mick
@ethan_mick Год назад
So glad it helped! You are very welcome, hope to see you around!
@akebu6
@akebu6 Год назад
@@ethan_mick I'm gonna stick around after this to learn more!
@ekchills6948
@ekchills6948 Год назад
Thank you soo much ❤️
@ethan_mick
@ethan_mick Год назад
Any time!
@abrahimzaman360
@abrahimzaman360 Год назад
👀
@ethan_mick
@ethan_mick Год назад
👋
@oii0712
@oii0712 3 месяца назад
VERY HELPFUL THANKS ethen @Build SaaS with Ethan
@y2b5
@y2b5 Год назад
Perfect!
@ethan_mick
@ethan_mick Год назад
👌
Далее
🦊🔥
00:16
Просмотров 584 тыс.
У КОТЯТ ОТКРЫЛИСЬ ГЛАЗКИ#cat
00:26
I tried 8 different Postgres ORMs
9:46
Просмотров 414 тыс.
Next.js + Postgres Setup Walkthrough: Dev/Production
36:24
Prisma - лучшая ORM для Node.js
23:45
Просмотров 31 тыс.
Fetching Data Doesn't Get Better Than This
6:58
Просмотров 121 тыс.
Is Drizzle Really Better Than Prisma?
20:15
Просмотров 81 тыс.
Implement Clean Architecture in Next.js
53:07
Просмотров 23 тыс.
Learn Drizzle ORM in 13 mins (crash course)
14:00
Просмотров 28 тыс.