iconSuperDir

Database

How the database and ORM are configured in SuperDir.

By default, SuperDir uses Neon as its database provider and Drizzle as its ORM. Allow you to query the database with ease using Javascript/Typescript

Fell free to use any provider you like , such as:

Setup

Create a Neon DB Account

  • Go to the Neon and sign up for an account.

  • Create a New Database: Once logged in, create a new database instance. Note down the connection details (host, database name, username, password).

Get your URI

postgresql://username:password@hostname:port/database?sslmode=require

It is just a sample, please replace the values with your own

Set the environment variables in your .env file:

.env
DATABASE_URL=postgresql://username:password@hostname:port/database?sslmode=require

Schema Definition

The database schema is defined in /drizzle/db/schema.ts. This schema file uses Prisma's schema definition language to describe your database tables, relationships, and types.

Adding a new model

Let's say we want to add a new model called Post, describing a blog post. To do this, we would add the following to your schema:

/drizzle/db/schema.ts
model Post {
  id        String   @id @default(cuid())
  title     String
  content   Json
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}

Deploying changes

To deploy your schema changes, run the following command:

Terminal
    pnpm db:generate
    pnpm db:migrate
    pnpm db:push

Visual database editor

SuperDir includes Drizzle Studio, which is a visual editor for your database. To start it, run the following command:

Terminal
pnpm db:studio
The studio application runs on https://local.drizzle.studio.

On this page