Database Setup Guide
Learn how to configure PostgreSQL, MySQL, or SQLite with Stabilize ORM
🐘PostgreSQL Setup
Recommended for production applications
1. Install PostgreSQL
# macOSbrew install postgresql@18# Ubuntu/Debiansudo apt-get install postgresql-18# Or use a managed service like Neon, Supabase, or AWS RDS
2. Create Database
# Connect to PostgreSQLpsql postgres# Create databaseCREATE DATABASE myapp;# Create userCREATE USER myapp_user WITH PASSWORD 'secure_password';# Grant privilegesGRANT ALL PRIVILEGES ON DATABASE myapp TO myapp_user;
3. Configure Stabilize
config/database.tstypescript
import { DBType, type DBConfig } from "stabilize-orm";const dbConfig: DBConfig = {type: DBType.Postgres,connectionString: "postgresql://myapp_user:secure_password@localhost:5432/myapp",retryAttempts: 3,retryDelay: 1000,};export default dbConfig;
🐬MySQL Setup
Popular choice for web applications
1. Install MySQL
# macOSbrew install mysql# Ubuntu/Debiansudo apt-get install mysql-server# Or use managed services like PlanetScale or AWS RDS
2. Create Database
# Connect to MySQLmysql -u root -p# Create databaseCREATE DATABASE myapp;# Create userCREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_password';# Grant privilegesGRANT ALL PRIVILEGES ON myapp.* TO 'myapp_user'@'localhost';FLUSH PRIVILEGES;
3. Configure Stabilize
config/database.tstypescript
import { DBType, type DBConfig } from "stabilize-orm";const dbConfig: DBConfig = {type: DBType.MySQL,connectionString: "mysql://myapp_user:secure_password@localhost:3306/myapp",retryAttempts: 3,retryDelay: 1000,};export default dbConfig;
🪶SQLite Setup
Perfect for development and small applications
1. No Installation Required
SQLite is embedded and requires no separate server installation.
2. Configure Stabilize
config/database.tstypescript
import { DBType, type DBConfig } from "stabilize-orm";export const dbConfig: DBConfig = {type: DBType.SQLite,connectionString: "myaapp.db",retryAttempts: 3,retryDelay: 1000,};
3. File Location
The database file will be created at the specified path. For production, consider:
- Using an absolute path
- Ensuring proper file permissions
- Regular backups
- Write-ahead logging (WAL) mode for better concurrency
Environment Variables
Store database credentials securely using environment variables:
.envtypescript
DATABASE_URL=postgresql://user:password@localhost:5432/myapp
config/database.tstypescript
import { DBType, type DBConfig } from "stabilize-orm";export const dbConfig: DBConfig = {type: DBType.Postgres,connectionString: process.env.DATABASE_URL!,retryAttempts: 3,retryDelay: 1000,};
