/
matusha
/
hist_center
Обзор
Документация
Войти
/
matusha
/
hist_center
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/database/models/models.py
47 строк
2 KB
Galimianov Matvey
create repositories and ORM
15 дек 2024, 03:51
15 дек 2024, 03:51
8255305
Код
Авторство
О чём код?
import datetime from sqlalchemy import ( ForeignKey, String, text, ) from sqlalchemy.orm import Mapped, mapped_column, relationship from ..engine import Base class Users(Base): __tablename__ = "users" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) first_name: Mapped[str] = mapped_column(String(50)) second_name: Mapped[str | None] = mapped_column(String(50)) username: Mapped[str] = mapped_column(String(50), unique=True) password: Mapped[str] class Articles(Base): __tablename__ = "articles" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) title: Mapped[str] = mapped_column() created_at: Mapped[datetime.datetime] = mapped_column(server_default=text("TIMEZONE('utc', now())")) updated_at: Mapped[datetime.datetime | None] is_published: Mapped[bool] = mapped_column(default=False) author_id: Mapped[int | None] = mapped_column(ForeignKey("users.id")) class Contents(Base): __tablename__ = "contents" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) article_id: Mapped[int | None] = mapped_column(ForeignKey("articles.id")) file_path: Mapped[str | None] hiearchy: Mapped[int] text: Mapped[str | None] type_id: Mapped[int | None] = mapped_column(ForeignKey("type_id.id")) class Type_id(Base): __tablename__ = "type_id" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) name: Mapped[str] = mapped_column(String(256), unique=True) description: Mapped[str | None] = mapped_column(String(256)) blockName: Mapped[str]