DEV Community

Azad Shukor
Azad Shukor

Posted on • Edited on

7 1 1 1 2

Setting up Next.js 13 with Prisma and SQLite

In this tutorial, we will demonstrate how to set up a Next.js 13 application with Prisma as the ORM and SQLite as the database.

Prerequisites

  • Node.js
  • npm

Step 1: Creating a Next.js application

First, let's create a new Next.js application using the create-next-app command:

npx create-next-app my-app --yes
Enter fullscreen mode Exit fullscreen mode

This command will create a new Next.js application in the my-app directory. When prompted, choose No for TypeScript and No for the experimental app/ directory.

Next, change into the project directory:

cd my-app
Enter fullscreen mode Exit fullscreen mode

Step 2: Setting up SQLite

To set up a SQLite database for our Next.js application, we need to install the sqlite3 package and create a new dev.db file:

npm install sqlite3
Enter fullscreen mode Exit fullscreen mode

Step 3: Setting up Prisma

Next, we need to install the Prisma and initialize a new Prisma project:

npm install prisma --save-dev && prisma init
Enter fullscreen mode Exit fullscreen mode

This will initialize a new Prisma project in our application directory. Then, we can paste the following code into the schema.prisma file:

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db"
}

generator client {
  provider = "prisma-client-js"
}

model User {
  id    Int    @id @default(autoincrement())
  email String @unique
}
Enter fullscreen mode Exit fullscreen mode

Don't forget to create dev.db file inside prisma folder

cd prisma
touch dev.db
Enter fullscreen mode Exit fullscreen mode

Step 4: Pushing the Prisma schema and starting the Prisma Studio

Finally, we need to push our schema to the database and start the Prisma Studio to view the database:

prisma db push && prisma studio
Enter fullscreen mode Exit fullscreen mode

Conclusion

Congratulations, you have successfully set up a Next.js 13 application with Prisma as the ORM and SQLite as the database. You can now use Prisma to query the SQLite database in your Next.js application.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay