Login
Docs
Database

Database

ZexaNext uses Prisma as the ORM to interact with the database. Prisma is a modern database toolkit that makes it easy to interact with databases.

Prisma supports multiple databases like MySQL, PostgreSQL, SQLite, MongoDB, and others (see the full list here).

I prefer to go with PostgreSQL as it is a powerful, open-source and very popular database.

Setup

1. Set the connection string

Add the connection string in the .env file for variable DATABASE_URL. The schema of the database is defined in the schema.prisma file.

ZexaNext provides the necessary tables for the authentication. You can add more tables as per your requirement. Checkout the Prisma documentation for more details.

2. Initiate the database

To initiate the database, execute the following command in terminal:

npm i # install all dependencies
npx prisma generate # initiate prisma
npx prisma db push # push the schema to the database

3. Database operations

To query, insert, update or delete data from the database, you can use the Prisma client.

import { db } from "@/lib/db";
 
const user = await db.user.findUnique({
  where: {
    email: "john@doe.com",
  },
});