Prisma in Next.js - My Fav Way to Work with Databases (CRUD, Dev/Prod Workflow, Relations, Indexes)

👉 Check out Prisma: www.prisma.io/?via=bytegrad (paid sponsorship & I get commission from your purchases)
Disclaimer: this is a sponsored video (paid). It's your responsibility to evaluate safety, accuracy and other relevant parts of the reviewed product.
👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
Hi, I'm Wesley. I'm a brand ambassador for Kinde (paid sponsorship).
👉 Check out Kinde for auth and more bit.ly/3QOe1Bh
👉 NEW React & Next.js Course: bytegrad.com/courses/professi...
👉 Professional JavaScript Course: bytegrad.com/courses/professi...
👉 Professional CSS Course: bytegrad.com/courses/professi...
👉 Web development roadmap 2024 & 2025: email.bytegrad.com
👉 Email newsletter (BIG update soon): email.bytegrad.com
👉 Discord: all my courses have a private Discord
⏱️ Timestamps:
00:00 Intro
01:07 Next.js architecture
02:02 Example app overview
03:15 Setup Prisma
06:09 Schema fundamentals
07:36 Prisma extension + defaultFormatter
08:34 Schema fundamentals (continued)
10:09 Create database
12:38 View database content (Prisma Studio)
14:13 GET data on page (findMany)
16:50 Prisma Client instantiation
18:29 GET data on page (findUnique)
22:18 Changing schema (Slug) - npx prisma db push
25:38 @unique
27:42 @map
28:04 @index
28:53 Filtering (where)
29:55 Ordering
30:18 Select
31:00 Pagination
32:29 Count
33:42 Writing data (POST / PUT / DELETE)
42:03 Relations (one-to-many)
43:54 Many-to-many
44:27 One-to-one
46:50 include & connect (relations queries)
49:12 Seeding database
51:10 Prisma types
53:13 Seeding database (continued)
55:50 Error handling
57:35 Caching in Next.js
59:59 Prisma Accelerate caching
1:00:34 Going to production
1:04:32 Migrations
1:06:15 npx prisma migrate
1:08:18 postinstall (prisma generate)
1:08:42 Push to Vercel
1:10:19 Serverless vs Edge
1:10:59 Middleware (edge)
1:13:07 Prisma Pulse
#webdevelopment #reactjs #nextjs

Пікірлер: 89

  • @Ssmb-qj4df
    @Ssmb-qj4df17 күн бұрын

    Man is the best teacher who doesn't give me anxiety while learning

  • @josephito27
    @josephito2710 сағат бұрын

    10 mins in and it is already solving me a lot of doubts about Next js omg, thank you

  • @rohitkochikkatfrancis
    @rohitkochikkatfrancisАй бұрын

    THIS IS THE BEST EXPLAINED VIDEO FOR PRISMA !!!!! Thank you so much for dwelling into even the minor details so that people who dont even have a clue bout what it is can easily understand it.

  • @rtx50700
    @rtx50700Ай бұрын

    Bro read my mind, yesterday I was thinking about when you will make a video on Prisma..and here it is 🙏

  • @enn_nj

    @enn_nj

    Ай бұрын

    😂same with me bro..i love you so much bro, you read our mind😂🙏🏻🙏🏻🙏🏻 that's what i need..thankyou so muchh💐💐💐♥️

  • @CleverGeneration
    @CleverGenerationАй бұрын

    I'm only half way through and I've already learnt so many new things, thank you!!! Brilliant video ❤

  • @PrismaData
    @PrismaDataАй бұрын

    Incredible video!

  • @ByteGrad

    @ByteGrad

    Ай бұрын

    Any time!

  • @Saradomin65
    @Saradomin65Ай бұрын

    Was planning to get back to full-stack dev using prisma with Nextjs to create some side projects and this video comes in. Definitely will help a ton, thanks! 😁

  • @mistersir3185
    @mistersir3185Ай бұрын

    The timing of this video is divinely. Love you bro.

  • @olusanyaolamide9764
    @olusanyaolamide9764Ай бұрын

    Nice one, will definitely check it out when I have time, I'm excited already, but we'll also love you to do a NodeJs Express course

  • @RoyTjuh
    @RoyTjuhАй бұрын

    dankjewel voor de video kerel

  • @mostafashahat9760
    @mostafashahat9760Ай бұрын

    Awesome, keep up the great work 💖

  • @abeybruck151
    @abeybruck151Ай бұрын

    very very very awesome. you sir is a natural born teacher. respect

  • @vt1tov
    @vt1tovАй бұрын

    I love you man. Thanks! Great content :)

  • @ptk_001
    @ptk_001Ай бұрын

    Thanks for this amazing content!

  • @PolatjonQurbonov
    @PolatjonQurbonovАй бұрын

    It is a very informative lesson! Thank you!

  • @JackTheZuluman
    @JackTheZulumanАй бұрын

    Man,I really thought I can use Prisma. Thanks a lot for this🔥🔥🔥

  • @mlavinb
    @mlavinbАй бұрын

    Great content! thanks for sharing

  • @JacobPhillips-rf5db
    @JacobPhillips-rf5dbАй бұрын

    THANK YOU! You're AWESOME!

  • @u.chaudhry2147
    @u.chaudhry2147Ай бұрын

    @ByteGrad can you next do tRPC with Next.js App Router? Also, you are the best teacher of the t3 stack out there. The way you teach us in such depth is awesome!

  • @alarafatsiddique9362
    @alarafatsiddique9362Ай бұрын

    Could you please make a tutorial specifically on how to use Prisma from development, and testing to production with some concrete examples?

  • @ashfaqkabir
    @ashfaqkabirАй бұрын

    Awesome Video, Please Do a video On Dashboard Tutorial with Next Auth, SeverActions, Prisma and Mongodb

  • @jfhandfield
    @jfhandfieldАй бұрын

    Wow great video Byte. Really well explained. The only question I have is what if I have 2 different database to access. How are you going to make your clients? Is it going to be in the same db.ts?

  • @parkerboling666
    @parkerboling666Ай бұрын

    Hey bytegrad I really enjoy your content and recently have been following along in some of your content, and I like kinde authentication. I’m building a full stack application for a childcare company and it would be a good video idea to show admin authorization and interacting with the kinde API to manage users from a secured back end admin panel this would help me out tremendously! I really enjoy the content though keep up the good work!

  • @R3nxt
    @R3nxtАй бұрын

    Great video. You were right, caching deserves its own video. Could you please upload a video that handles caching?

  • @ByteGrad

    @ByteGrad

    Ай бұрын

    Yes, coming soon!

  • @armaandhanji2112

    @armaandhanji2112

    Ай бұрын

    Looking forward to the caching video alot too!

  • @AK-kq1mk
    @AK-kq1mkСағат бұрын

    Useful stuff

  • @Sagarclips
    @Sagarclips2 күн бұрын

    When creating post, why client component was not used

  • @vipernext2190
    @vipernext2190Ай бұрын

    as always greate video ❤❤

  • @enn_nj

    @enn_nj

    Ай бұрын

    The best video from the best teacher 🙏🏻🙏🏻🙏🏻🙏🏻i really like this Chanel.

  • @GhostHack_1
    @GhostHack_1Ай бұрын

    One warning about prisma that most developers (including myself) overlook, it does not support optimistic rowlocking API calls. You will have to use Raw SQL for that and it gets very messy / hard to do when accounting for race conditions in production.

  • @juliusgrisette
    @juliusgrisetteАй бұрын

    Thank you

  • @nasko235679
    @nasko235679Ай бұрын

    NICE!

  • @zainn7336
    @zainn7336Ай бұрын

    Sir make a full video of supabase and next js as backend

  • @a4tech357
    @a4tech35711 күн бұрын

    Helpful video! Can we get a github repo?

  • @iukeay
    @iukeayАй бұрын

    I have a large database relational database with 30+ tables. Does Prisma still have issues doing relationship joins without having to scan the whole table - I have been looking into drizzle Just because we do a lot of relational joins. Just at the very small community and not as much documentation / examples. Love love love all your videos !!!!!! Keep it up king

  • @irfansaeedkhan7242
    @irfansaeedkhan7242Ай бұрын

    thank you

  • @jeffinj7707
    @jeffinj7707Ай бұрын

    Please also consider the fact that there are use cases where we have a standalone node/nestjs backend with an ORM, a nextjs app maybe one of the clients using the APIs. so no point in implementing the ORM in the nextjs too. what would be a better solution here? RQ?

  • @TenzDelek
    @TenzDelek21 күн бұрын

    i am about to start out, should i go with Prisma or drizzle?

  • @kdstudiogames3602
    @kdstudiogames3602Ай бұрын

    sir your video is very helpfull to me. i have compleated the above video. but i have issue with the update post which i have tried in same way as server acton use for create post. how to pass the id in action={updatePost}. how to pass the id? please help

  • @assassingob7315
    @assassingob7315Ай бұрын

    Hey, everybody! Can someone explain why after the application build, the updated data in the database is not updated on the client? The component is server-side

  • @darz_k.
    @darz_k.8 күн бұрын

    Hey man - as an aside to this video being related to prisma - I'm looking at a new hosting provider, and they are only offering sql databases for the backend - would you recommend using regular sql databases with nextjs and react? Projects would be small to medium in terms of requests and users. If you could give us your advice on that, it would be much appreciated!

  • @nunzioasisto
    @nunzioasistoАй бұрын

    What would you suggest if the revalidatePath is not refreshing the input and content boxes after submitting a post? The new post appears but the data is not cleared from input nor content.

  • @asmitkhanal834
    @asmitkhanal834Ай бұрын

    i m new on nextJs so help me to use delete and update operation in the frontend ui code.How to execute the created function in the UI form?help me plzzz

  • @true227
    @true2277 күн бұрын

    i can't find data type cuid() in the description postgre, it's have only uuid()

  • @user-vd5kp6jz7d
    @user-vd5kp6jz7d10 күн бұрын

    Does anyone have a problem with form fields not reset after submission?

  • @teetanrobotics5363
    @teetanrobotics5363Ай бұрын

    Could you please make a project on credentials and social oauth using Auth.js, Supabase. We can also use resend for sign up confirmation and forgot password.

  • @indimerz
    @indimerzАй бұрын

    can you make a video to show recommended way of doing filtering, sorting, search with nextjs and prisma??

  • @alaskandonut

    @alaskandonut

    Ай бұрын

    The prisma documentation is pretty easy to read on search and filter. It’s really not bad at all.

  • @nasko235679
    @nasko235679Ай бұрын

    When you need to get data from db to a client component would you say the best way is by fetching the data in a parent server component and then passing it down to the client as props?

  • @ByteGrad

    @ByteGrad

    Ай бұрын

    That would be pretty typical yes

  • @ianc6418
    @ianc6418Ай бұрын

    I am stuck on trying to figure out how sqlite runs on apple silicon. home-brew doesn't seem to work edit: It seems to come preinstalled on macOS. How weird is that!

  • @gttrackpro9433
    @gttrackpro9433Ай бұрын

    hey @bytegrad, this workflow & advance tutorial is available on your course?

  • @ByteGrad

    @ByteGrad

    Ай бұрын

    We also use Prisma in the course, but not super advanced or something like that

  • @gttrackpro9433

    @gttrackpro9433

    Ай бұрын

    ​@@ByteGrad ok got it. going to purchase your course asap 🎉

  • @abdelrahmanmostafa9489
    @abdelrahmanmostafa9489Ай бұрын

    Github link?

  • @krishpatel3632
    @krishpatel3632Ай бұрын

    What vs code theme do you use? It's great

  • @umernasir4217

    @umernasir4217

    Ай бұрын

    Please tell me as well.

  • @AvikNayak_

    @AvikNayak_

    Ай бұрын

    Maybe Andromeda

  • @heismyke

    @heismyke

    Ай бұрын

    He doesnt like to tell people what theme he uses. i have been asking him too for a long time

  • @haikelareff
    @haikelareffАй бұрын

    god bless you...

  • @eliyir
    @eliyirАй бұрын

    🙏

  • @viundesign
    @viundesignАй бұрын

    6:33 Why doesn't it appear to me the autocomplete? I have the Prisma extension already installed

  • @mustafamufeed1666

    @mustafamufeed1666

    Ай бұрын

    +1

  • @viundesign

    @viundesign

    Ай бұрын

    Still wondering

  • @viundesign

    @viundesign

    23 күн бұрын

    @@mustafamufeed1666 Git Hub Copilot

  • @viundesign

    @viundesign

    20 күн бұрын

    @@mustafamufeed1666 Git Hub Copilot

  • @suphawatwong9438

    @suphawatwong9438

    9 күн бұрын

    @@viundesign it's co-pilot feature, i guess

  • @A28480
    @A28480Ай бұрын

    Would be very helpful to understand why the data sometimes disappears when the schema is changed? Anyone know why it happens? Thanks a lot

  • @emad_naeim

    @emad_naeim

    Ай бұрын

    if the old data violates the new schema you make then it will be deleted (it will tell you and warn you before that), like if you are going to add new column and that column is required.. and you didn't specify the default value.. then by default old data will be deleted because they don't have value for this new colum. as a hack when you are playing with schema and you want to add new column.. specify a default value.. then it won't delete old data

  • @A28480

    @A28480

    Ай бұрын

    @@emad_naeim thank you very much

  • @emad_naeim

    @emad_naeim

    Ай бұрын

    @@A28480 😇🤍

  • @imkeyi
    @imkeyiАй бұрын

    what if a post could have multiple categories and tags

  • @victormustin2547
    @victormustin2547Ай бұрын

    I may be wrong but I don't think you talked about security and authorization which would have been great

  • @ivangeorge4478
    @ivangeorge4478Ай бұрын

    45:52 what was that sound :)

  • @blazi_0
    @blazi_0Ай бұрын

    The hardest thing that i dealt with prisma schmea until now was adding multi language support. Tried so many ways and ended up with using json for storing the values Not happy with this solution and looking for better ways, ill be appreciated if someone can help me with this

  • @sorenbs1

    @sorenbs1

    Ай бұрын

    I’ve always implemented this by loading the full translation file as json and caching it in memory on the server. That way loading the replacements is super cheap.

  • @ahmadullahnikzad2850
    @ahmadullahnikzad285022 күн бұрын

    revalidatePath does not work

  • @jellyfish1772
    @jellyfish1772Ай бұрын

    why not drizzle

  • @bibblebabl

    @bibblebabl

    Ай бұрын

    If you think you ready to try it - go for it. It’s not exactly the same and it has less abstractions AFAICT. So basically you will need better understanding of SQL because drizzle gives you more control since it’s more a query builder. Now it becomes more popular but I guess not all people understand that it requires some entry level when with prisma you don’t have to care about a lot of things

  • @jonbharrell

    @jonbharrell

    Ай бұрын

    @bibblebabl is completely right. Prisma and Drizzle are similar tools at different levels of abstraction. If you prefer the Drizzle way of defining your models and querying, then it is the right tool for you.

  • @richardnorris9256
    @richardnorris925615 күн бұрын

    This guy must be Dutch to speak English this clearly and quickly while multitasking. He definitely isn't British or American anyway, his English is too good.

  • @beyourahi
    @beyourahiАй бұрын

    alright let's start the war 🚀 Prisma VS Drizzle

  • @giuseppebosco5813
    @giuseppebosco5813Ай бұрын

    Pls drizzle

  • @vuyyururajashekarreddy493
    @vuyyururajashekarreddy493Ай бұрын

    Switched to drizzle

  • @dukim632
    @dukim63217 күн бұрын

    i find primsa to be pretty horrible tool, the fact that we all opt out writing SQL is just mad. ORM creates stupid developers which cannot write proper SQL which creates TONS of problems later on

  • @true227

    @true227

    7 күн бұрын

    i'm totally agree