Database
Connect your ShipAhead app to PostgreSQL with Drizzle ORM. Learn how to configure the database, manage schemas, and store users, sessions, and app data.
Tools
- Drizzle ORM: Provides a lightweight, type-safe way to interact with PostgreSQL databases.
Setup
- Sign up / Sign in for a PostgreSQL database at Supabase, Neon, or another provider.
- Copy the Database URL / Connection String from your provider’s dashboard (e.g.,
postgres://user:password@host:port/dbname). - Set environment variable:
.env
DATABASE_URL="your-postgresql-database-url" - Generate schema migrations:
Terminal
npm run db:generate - Apply migrations to your database:
Terminal
npm run db:migrate
Usage
- Database Connection: The database is initialized in
server/db/init.tsusingDATABASE_URLand connects to tables defined inserver/db/schema/. - Query Data: Use Drizzle ORM in server services, e.g., insert records.server/service/contact.ts
import { useDatabase } from '~~/server/db/init'; import * as schema from '~~/server/db/schema'; export const contactServices = { async submit(body: { name: string; email: string; message: string }) { const db = useDatabase(); await db.insert(schema.contact).values({ id: crypto.randomUUID(), name: body.name, email: body.email, message: body.message, }); }, }; - Manage Schemas: Update
server/db/schema/to add or modify tables. Runnpm run db:generateandnpm run db:migrateafter changes. - Verify Setup: Check your database provider’s dashboard (e.g., Supabase or Neon) to confirm tables are created.
Setup
Get your ShipAhead Nuxt app running locally. Follow the setup guide to install dependencies, configure environment variables, and start building your SaaS.
Authentication
Set up authentication in your ShipAhead app with Better Auth. Configure sign-in methods, user sessions, and account management for your SaaS product.