Database
LongLink projects use standard SQLModel(opens in new tab) tables. The SDK adds database.session() for a Solution-scoped async SQLAlchemy(opens in new tab) database session. Migrations are based on Alembic(opens in new tab).
| Environment |
|---|
Testing memory SQLite database for isolated test runs. |
Development dev.db SQLite database for local development. |
Production PostgreSQL database using a schema scoped to the Solution. |
Basic usage
pythonfrom longlink import databasefrom sqlmodel import Field, SQLModelclass Project(SQLModel, table=True):id: int | None = Field(default=None, primary_key=True)name: strasync def create_project() -> None:async with database.session() as session:session.add(Project(name="Launch"))await session.commit()
Timezone
Use LongLink's UTCDateTime type for datetime fields defined by your project. It requires a timezone-aware value and stores it in UTC.
pythonfrom datetime import UTC, datetimefrom longlink.database.types import UTCDateTimefrom sqlmodel import Field, SQLModelclass Event(SQLModel, table=True):id: int | None = Field(default=None, primary_key=True)starts_at: datetime = Field(sa_type=UTCDateTime)event = Event(starts_at=datetime(2026, 8, 3, 9, 0, tzinfo=UTC))
Audit table
Use database.AuditTable only when a database table needs Platform-user attribution. It adds creation, update, and deletion timestamps; the matching Platform user identifiers; and read-only user relationships.
pythonfrom longlink import databasefrom sqlmodel import Fieldclass Approval(database.AuditTable, table=True):id: int | None = Field(default=None, primary_key=True)status: strapproval = Approval(status="pending")print(approval.status) # pending# approval.created_by and approval.updated_by are database.AuditUser values after persistence.
Migrations
After you add or change database models, run migrations to keep the schema aligned:
bashuv run longlink migrate