For this course we will use SQLite, as it is the easiest to setup. We will do that using Prisma, a modern database ORM (Object-Relational Mapping) that simplifies data modeling, schema migrations, and data access for all types of databases.
To get started with Prisma, you'll need to have Node.js installed on your machine. Follow these steps to install and configure Prisma in your Next.js project:
npm i prisma --save-dev
npm i @prisma/client
prisma
directory on the root of our app:npx prisma init
Now Prisma has generated a default schema file, which we are going to overwrite.
sqlite
, as seen below:datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model Todo {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
content String
dueDate DateTime
completed Boolean @default(false)
}
.env
file to contain the correct DATABSE_URL:DATABASE_URL="file:./dev.db"