[REF] Refactor

This commit is contained in:
2026-02-13 13:35:18 +01:00
parent b00c35f19b
commit dc819b1674
29 changed files with 101 additions and 80 deletions

View File

@@ -1,4 +0,0 @@
from .base import Base
from .env import Env
from .library import Library
from .path import Path

View File

@@ -1,4 +0,0 @@
from sqlalchemy.orm import DeclarativeBase
class Base(DeclarativeBase):
pass

View File

@@ -1,3 +1,6 @@
from .base import Base
from .book import Book
from .tag import Tag
from .env import Env
#from .tag import Tag
from .path import Path
from .library import Library
from .book import Book

View File

@@ -1,6 +1,6 @@
from typing import List
from typing import Optional
from sqlalchemy import String
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import relationship
@@ -10,14 +10,16 @@ from .base import Base
class Book(Base):
__tablename__ = "book"
id: Mapped[int] = mapped_column(primary_key=True)
hash: Mapped[str] = mapped_column(String(255))
file_name: Mapped[str] = mapped_column(String(255))
file_path: Mapped[str] = mapped_column(String(65656))
name: Mapped[str] = mapped_column(String(255))
publisher: Mapped[str] = mapped_column(String(255))
notes: Mapped[str] = mapped_column(String(65656))
classification: Mapped[int] = mapped_column(primary_key=True)
tags: Mapped[List["Tags"]] = relationship(
back_populates="books", cascade="all, delete-orphan"
)
library_id: Mapped[int] = mapped_column(ForeignKey("library.id"))
library: Mapped[int] = relationship("Library", back_populates="books")
def __repr__(self) -> str:
return f"Book(id={self.id!r}, name={self.name!r}, publisher={self.publisher!r}," \

View File

@@ -12,7 +12,6 @@ class Library(Base):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(255))
notes: Mapped[str] = mapped_column(String(65656))
connection_string: Mapped[str] = mapped_column(String(65656))
envs: Mapped[List["Env"]] = relationship(
back_populates="library", cascade="all, delete-orphan"
@@ -22,6 +21,9 @@ class Library(Base):
back_populates="library", cascade="all, delete-orphan"
)
books: Mapped[List["Book"]] = relationship(
back_populates="library", cascade="all, delete-orphan"
)
def __repr__(self) -> str:
return f"Library(id={self.id!r}, name={self.name!r}, notes={self.notes!r}," \
f" connection_string={self.connection_string!r})"
return f"Library(id={self.id!r}, name={self.name!r}, notes={self.notes!r}"