Database Setup Guide

Learn how to configure PostgreSQL, MySQL, or SQLite with Stabilize ORM

🐘PostgreSQL Setup
Recommended for production applications

1. Install PostgreSQL

# macOS
brew install postgresql@18
# Ubuntu/Debian
sudo apt-get install postgresql-18
# Or use a managed service like Neon, Supabase, or AWS RDS

2. Create Database

# Connect to PostgreSQL
psql postgres
# Create database
CREATE DATABASE myapp;
# Create user
CREATE USER myapp_user WITH PASSWORD 'secure_password';
# Grant privileges
GRANT 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

# macOS
brew install mysql
# Ubuntu/Debian
sudo apt-get install mysql-server
# Or use managed services like PlanetScale or AWS RDS

2. Create Database

# Connect to MySQL
mysql -u root -p
# Create database
CREATE DATABASE myapp;
# Create user
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_password';
# Grant privileges
GRANT 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,
};