You shouldn't need a PhD in SQLAlchemy internals just to define a composite unique constraint or an autoincrementing ID. wsqlite turns Pydantic field descriptions into clean, declarative SQL constraints.
Here is how you use Declarative SQL Constraints in Pydantic Field in production with wsqlite:
from typing import Optional
from pydantic import BaseModel, Field
from wsqlite import WSQLite
class Employee(BaseModel):
id: Optional[int] = Field(None, description="primary autoincrement")
# Composite unique: department + position must be unique together
department: str = Field(..., description="unique:job_role")
position: str = Field(..., description="unique:job_role")
# Foreign key referencing company.id
company_id: int = Field(..., description="references:company.id")
db = WSQLite(Employee, "corp.db")
Why developers love wsqlite:
- Define database tables using standard Pydantic v2 models.
- Auto-syncs columns on startup without writing manual migrations.
- Thread-safe connection pooling with WAL mode enabled by default (5,000+ inserts/sec).
- Full sync and async/await support.
Explore the repository on GitHub!
Author: William Steve Rodríguez Villamizar (Wisrovi)
Top comments (0)