Database
Learn how to configure and manage databases in your SaaS application.
Supported Databases
Multi-Database Support
The boilerplate supports multiple database options with automatic detection
SQLite (Default)
Zero-configuration database perfect for development and small applications.
file:./auth.db - Local SQLite fileNo environment variables required - works out of the box
Database Setup
Configuration Guide
Step-by-step guide to set up your preferred database
1. Choose Your Database
Development
Use SQLite for quick setup
Production
Use Turso for edge performance or MySQL for enterprise
2. Set Environment Variables
Add the required variables to your .env.local file:
# For Turso
TURSO_DATABASE_URL=libsql://your-db.turso.io
TURSO_AUTH_TOKEN=your-auth-token
# For MySQL
USE_MYSQL=true
MYSQL_DATABASE_URL=mysql://user:pass@host:3306/db
3. Restart Application
The database dialect is selected at server startup based on environment variables.
$ pnpm devMigrations
Database Schema Management
Better Auth handles database migrations automatically
Automatic Migrations
Better Auth automatically creates and updates database tables when your application starts. No manual migration process is required.
Tables Created
users - User accounts and profilessessions - Active user sessionsaccounts - OAuth provider accountsorganizations - Team/organization datasubscriptions - Stripe subscription dataDatabase File
For SQLite, the database file is created at ./auth.db in your project root. You can inspect this file with any SQLite browser tool.
Query Builder
Kysely Integration
Type-safe SQL query builder with excellent TypeScript support
Why Kysely?
Usage Examples
Basic Query:
const user = await db
.selectFrom('users')
.where('id', '=', userId)
.selectAll()
.executeTakeFirst()With Relations:
const userWithOrg = await db
.selectFrom('users')
.innerJoin('organizations', 'users.organizationId', 'organizations.id')
.selectAll()
.execute()Database Access
The database instance is available through the Better Auth configuration. Access it in your API routes and server components.