shortenit/shortenit/models/objects.py
2024-12-01 22:33:55 +01:00

27 lines
975 B
Python

from shortenit.models.base import Base
from typing import List, Optional
from sqlalchemy import Integer, String, ForeignKey
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import relationship, mapped_column
from pydantic import AnyHttpUrl
class Link(Base):
__tablename__ = "links"
id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False)
identifier: Mapped[str] = mapped_column(index=True)
data: Mapped[AnyHttpUrl] = mapped_column(String)
timestamp: Mapped[str]
pointers: Mapped[List["Pointer"]] = relationship(back_populates="link")
class Pointer(Base):
__tablename__ = "pointers"
id: Mapped[int] = mapped_column(primary_key=True, index=True, init=False)
identifier: Mapped[str] = mapped_column(index=True)
data: Mapped[str]
ttl: Mapped[str]
timestamp: Mapped[str]
link_id: Mapped[int] = mapped_column(ForeignKey("links.id"))
link: Mapped["Link"] = relationship(back_populates="pointers")