Why Do You Need a Database?
❌ In-Memory Storage
- Data deleted on server restart
- Data inconsistency across multiple servers
- Risk of running out of memory
✅ Using a Database
- Permanent data storage
- Same data across multiple servers
- Efficient searching and sorting
Why PostgreSQL?
Here is why we recommend PostgreSQL among the many databases available:
- Free & Open Source - No licensing costs
- Proven Stability - Over 30 years of history
- Cloud Support - Managed services available on all clouds
- JSON Support - Flexible data storage like NoSQL
Quick Start
1. Install Dependencies
Terminal
pip install sqlalchemy psycopg2-binary alembic2. Define Database Models
app/models/project.py
from sqlalchemy import Column, String, DateTime, Boolean
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.ext.declarative import declarative_base
import uuid
from datetime import datetime
Base = declarative_base()
class Project(Base):
__tablename__ = "projects"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String(200), nullable=False)
description = Column(String(1000))
is_active = Column(Boolean, default=True)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)Cloud Database Options
Get started quickly with BaaS
If you want to use a database and authentication directly without a backend, check out the Supabase guide. You can access the database directly from the frontend without writing SQL.