Skip to content

Commit d4a50ea

Browse files
Harshal6927cofin
authored andcommitted
fix: advanced-alchemy skills
1 parent efbb3dd commit d4a50ea

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

plugins/litestar/skills/advanced-alchemy/references/fastapi-integration.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,21 @@ from uuid import UUID
118118

119119
from fastapi import APIRouter, Depends
120120
from pydantic import BaseModel
121-
from sqlalchemy.orm import Mapped, mapped_column
121+
from sqlalchemy import ForeignKey
122+
from sqlalchemy.orm import Mapped, mapped_column, relationship
122123

123-
from advanced_alchemy.base import UUIDBase
124+
from advanced_alchemy.base import UUIDAuditBase
124125
from advanced_alchemy.repository import SQLAlchemyAsyncRepository
125126
from advanced_alchemy.service import SQLAlchemyAsyncRepositoryService
126127

127-
class OrderModel(UUIDBase):
128+
class CustomerModel(UUIDAuditBase):
129+
__tablename__ = "customer"
130+
name: Mapped[str] = mapped_column()
131+
132+
class OrderModel(UUIDAuditBase):
128133
__tablename__ = "order"
134+
customer_id: Mapped[UUID] = mapped_column(ForeignKey("customer.id"))
135+
customer: Mapped[CustomerModel] = relationship()
129136
customer_email: Mapped[str] = mapped_column()
130137
total_cents: Mapped[int] = mapped_column()
131138

@@ -288,7 +295,7 @@ from pydantic import BaseModel
288295
from sqlalchemy.orm import Mapped, mapped_column
289296

290297
from advanced_alchemy import filters
291-
from advanced_alchemy.base import UUIDBase
298+
from advanced_alchemy.base import UUIDAuditBase
292299
from advanced_alchemy.repository import SQLAlchemyAsyncRepository
293300
from advanced_alchemy.service import OffsetPagination, SQLAlchemyAsyncRepositoryService
294301
from advanced_alchemy.extensions.fastapi import (
@@ -298,7 +305,7 @@ from advanced_alchemy.extensions.fastapi import (
298305
assign_cli_group,
299306
)
300307

301-
class OrderModel(UUIDBase):
308+
class OrderModel(UUIDAuditBase):
302309
__tablename__ = "order"
303310
customer_email: Mapped[str] = mapped_column()
304311
total_cents: Mapped[int] = mapped_column()

plugins/litestar/skills/advanced-alchemy/references/operations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ from advanced_alchemy.operations import OnConflictUpsert
1515
from sqlalchemy.ext.asyncio import AsyncSession
1616

1717
async def upsert_order(session: AsyncSession, order_table, values: dict) -> None:
18-
dialect_name = session.bind.dialect.name
18+
bind = session.bind if session.bind is not None else session.get_bind()
19+
dialect_name = bind.dialect.name
1920
if not OnConflictUpsert.supports_native_upsert(dialect_name):
2021
raise RuntimeError(f"native upsert unsupported for {dialect_name}")
2122
stmt = OnConflictUpsert.create_upsert(

skills/advanced-alchemy/SKILL.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Advanced Alchemy is NOT a raw ORM — it is a **service/repository layer** built
4040
| `UUIDBase` | UUID v4 | None | Lookup tables, tags, no audit needed |
4141
| `UUIDv7AuditBase` | UUID v7 | `created_at`, `updated_at` | Time-sortable IDs (preferred over v6) |
4242
| `BigIntAuditBase` | BigInt auto-increment | `created_at`, `updated_at` | Legacy systems, integer PKs |
43-
| `NanoidAuditBase` | Nanoid string | `created_at`, `updated_at` | URL-friendly short IDs |
43+
| `NanoIDAuditBase` | NanoID string | `created_at`, `updated_at` | URL-friendly short IDs |
4444
| `DeclarativeBase` | None (define yourself) | None | Full schema control |
4545

4646
### Repository Pattern
@@ -83,7 +83,7 @@ Key lifecycle hooks: `to_model_on_create`, `to_model_on_update`, `to_model_on_up
8383
| Mixin | Fields Added | When to Use |
8484
| --- | --- | --- |
8585
| `AuditMixin` | `created_at`, `updated_at`, `created_by`, `updated_by` | Any model needing a full audit trail (who + when) |
86-
| `SlugMixin` | `slug` (auto-generated) | URL-friendly identifiers derived from another field |
86+
| `SlugKey` | `slug` (auto-generated) | URL-friendly identifiers derived from another field |
8787
| `UniqueMixin` | `get_or_create` class method | Idempotent inserts for lookup/reference tables |
8888
| `SentinelMixin` | `_sentinel` version column | Optimistic locking; raises `ConflictError` on stale writes |
8989

skills/advanced-alchemy/references/fastapi-integration.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,21 @@ from uuid import UUID
118118

119119
from fastapi import APIRouter, Depends
120120
from pydantic import BaseModel
121-
from sqlalchemy.orm import Mapped, mapped_column
121+
from sqlalchemy import ForeignKey
122+
from sqlalchemy.orm import Mapped, mapped_column, relationship
122123

123-
from advanced_alchemy.base import UUIDBase
124+
from advanced_alchemy.base import UUIDAuditBase
124125
from advanced_alchemy.repository import SQLAlchemyAsyncRepository
125126
from advanced_alchemy.service import SQLAlchemyAsyncRepositoryService
126127

127-
class OrderModel(UUIDBase):
128+
class CustomerModel(UUIDAuditBase):
129+
__tablename__ = "customer"
130+
name: Mapped[str] = mapped_column()
131+
132+
class OrderModel(UUIDAuditBase):
128133
__tablename__ = "order"
134+
customer_id: Mapped[UUID] = mapped_column(ForeignKey("customer.id"))
135+
customer: Mapped[CustomerModel] = relationship()
129136
customer_email: Mapped[str] = mapped_column()
130137
total_cents: Mapped[int] = mapped_column()
131138

@@ -288,7 +295,7 @@ from pydantic import BaseModel
288295
from sqlalchemy.orm import Mapped, mapped_column
289296

290297
from advanced_alchemy import filters
291-
from advanced_alchemy.base import UUIDBase
298+
from advanced_alchemy.base import UUIDAuditBase
292299
from advanced_alchemy.repository import SQLAlchemyAsyncRepository
293300
from advanced_alchemy.service import OffsetPagination, SQLAlchemyAsyncRepositoryService
294301
from advanced_alchemy.extensions.fastapi import (
@@ -298,7 +305,7 @@ from advanced_alchemy.extensions.fastapi import (
298305
assign_cli_group,
299306
)
300307

301-
class OrderModel(UUIDBase):
308+
class OrderModel(UUIDAuditBase):
302309
__tablename__ = "order"
303310
customer_email: Mapped[str] = mapped_column()
304311
total_cents: Mapped[int] = mapped_column()

skills/advanced-alchemy/references/operations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ from advanced_alchemy.operations import OnConflictUpsert
1515
from sqlalchemy.ext.asyncio import AsyncSession
1616

1717
async def upsert_order(session: AsyncSession, order_table, values: dict) -> None:
18-
dialect_name = session.bind.dialect.name
18+
bind = session.bind if session.bind is not None else session.get_bind()
19+
dialect_name = bind.dialect.name
1920
if not OnConflictUpsert.supports_native_upsert(dialect_name):
2021
raise RuntimeError(f"native upsert unsupported for {dialect_name}")
2122
stmt = OnConflictUpsert.create_upsert(

0 commit comments

Comments
 (0)