LaunchPad.js
Database

Database

This guide covers the database setup and configuration for your SaaS application using LaunchPadjs.

LaunchPadjs uses Prisma ORM to provide a collection of database utilities for your site. While Prisma ORM supports multiple databases, this documentation focuses on using PostgreSQL, which is the preferred setup for LaunchPadjs projects, but you can use any database you want, like PostgreSQL, MySQL, or SQLite.

Database Setup

Custom Database

The database connection is configured in lib/prisma.ts

import { PrismaClient } from '@prisma/client'
 
// Prevent multiple instances of Prisma Client in development
const globalForPrisma = global as unknown as { prisma: PrismaClient }
 
export const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    log: ['query', 'error', 'warn'],
  })
 
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
 
export type { PrismaClient }
};

Ensure that DATABASE_URL environment variable is set for the database connection to work. You can use any of the free databases like Supabase, Neon, etc and setup a new database and configure the DATABASE_URL environment variable accordingly.

For postgres you can use the following command to create a new database.

npx prisma migrate dev

It will create a new database and run the migrations. It should also generate prisma client in node_modules/@prisma/client if not you can run the following command to generate it.

npx prisma generate

To view your databse in the browser you can use the following command.

npx prisma studio

It will start a new studio in the browser.

That's it you are ready to go.

On this page