1. 7
    Model Data in the Prisma Schema for a Remix App
    3m 36s

Model Data in the Prisma Schema for a Remix App

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

Let’s move away from hardcoded JSON and use our own database. In this course, we’ll be using Prisma as our database but Remix doesn’t actually care about what database you’re using!

To model Posts in our Prisma database we can edit the schema.prisma file under the prisma directory. Changes can be pushed to the db by running npx prism db push in your terminal.

We’ll also be seeding the database with data using a seed file in this lesson. Data in your seed file can be pushed running npx prisma db seed. Once you have data it can be accessed directly in your components!

ed leach
~ 2 years ago

I don't see where "model Post" from schema.prisma is used. I would have thought in the seed.ts file it would specify each post in the posts array is of the model "Post" in the schema file.

Adrien
~ 2 years ago

Hi, thank you very much for the material that is awsome as always.

I had a question because my IDE were displaying a type error for 'prisma.post', but I found the solution. It seems that my IDE failed to reload prisma compiled files, I restarted it and it solved the problem.

Toni Laukka
~ 2 years ago

Chrome Canary will just render the page when reviewing the posts on Network tab. Even Name is different. On Chrome the name of the page is 'posts?_data=routes%2Fposts%2Findex' and on Chrome Canary it just posts and it preview renders the whole page.

Toni Laukka
~ 2 years ago

My bad. :) Of course I have to refresh on root route (homepage) and navigate to posts to see what we are fetching. Just refreshing the current page (posts) we will see the serverside rendered page. :D

~ 2 years ago

I was running into a typescript error in /posts/index.tsx once I switched posts mock data over to fetch via prisma. Fixed after digging through https://github.com/remix-run/remix/pull/4165

Fix was change component useLoaderData casting to:

const { posts } = useLoaderData<LoaderData>();

Diaz Febrian
~ 2 years ago

thanks noname