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:

  1. First we install two dependencies needed for Prisma to work with our application:
npm i prisma --save-dev
npm i @prisma/client
  1. Then we can initialize Prisma, causing it to create a 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.

  1. First, change the datasource provider from the default value to sqlite, as seen below:
datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}
  1. Then lets create a schema model for our todos:
model Todo {
  id        String   @id @default(uuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  content   String
  dueDate   DateTime
  completed Boolean  @default(false)
}
  1. Last step, let’s update our .env file to contain the correct DATABSE_URL:
DATABASE_URL="file:./dev.db"