forked from vikram-dagger/dagger-python-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
37 lines (24 loc) · 781 Bytes
/
models.py
File metadata and controls
37 lines (24 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from sqlalchemy import String
from pydantic import BaseModel, ConfigDict
# SQLAlchemy models
class Base(DeclarativeBase):
"""Base class for all database models"""
pass
class Book(Base):
"""Book model"""
__tablename__ = "books"
id: Mapped[int] = mapped_column(primary_key=True, index=True)
title: Mapped[str] = mapped_column(String(255), index=True)
author: Mapped[str] = mapped_column(String(255))
# Pydantic models
class BookIn(BaseModel):
"""Pydantic model for book input"""
title: str
author: str
class BookOut(BaseModel):
"""Pydantic model for book output"""
id: int
title: str
author: str
model_config = ConfigDict(from_attributes=True)