mirror of
https://github.com/grillazz/fastapi-sqlalchemy-asyncpg.git
synced 2025-11-30 13:20:40 +03:00
add json filed example
This commit is contained in:
@@ -27,7 +27,8 @@ class Base(DeclarativeBase):
|
||||
"""
|
||||
try:
|
||||
db_session.add(self)
|
||||
return await db_session.commit()
|
||||
await db_session.commit()
|
||||
return await db_session.refresh(self)
|
||||
except SQLAlchemyError as ex:
|
||||
await logger.aerror(f"Error inserting instance of {self}: {repr(ex)}")
|
||||
raise HTTPException(
|
||||
|
||||
@@ -9,6 +9,18 @@ from app.models.base import Base
|
||||
from app.models.nonsense import Nonsense
|
||||
from app.utils.decorators import compile_sql_or_scalar
|
||||
|
||||
from sqlalchemy.dialects.postgresql import JSON
|
||||
|
||||
|
||||
class RandomStuff(Base):
|
||||
__tablename__ = "random_stuff"
|
||||
__table_args__ = ({"schema": "happy_hog"},)
|
||||
|
||||
id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True), default=uuid.uuid4, primary_key=True
|
||||
)
|
||||
chaos: Mapped[dict] = mapped_column(JSON)
|
||||
|
||||
|
||||
class Stuff(Base):
|
||||
__tablename__ = "stuff"
|
||||
|
||||
Reference in New Issue
Block a user