event to functon handler completed
This commit is contained in:
@@ -2,6 +2,7 @@ from contextlib import contextmanager
|
||||
from typing import Any, Dict, Optional, Generator
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import inspect
|
||||
|
||||
from Services.PostgresDb.database import Base
|
||||
|
||||
|
||||
@@ -17,7 +18,8 @@ class BaseModel(Base):
|
||||
|
||||
__abstract__ = True # Marks this as a base class, won't create a table
|
||||
|
||||
def get_session(self) -> Session:
|
||||
@classmethod
|
||||
def new_session(cls) -> Session:
|
||||
"""Get database session."""
|
||||
from Services.PostgresDb.database import get_db
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ class FilterAttributes:
|
||||
|
||||
@classmethod
|
||||
def filter_all(
|
||||
cls: Type[T], db: Session, *args: BinaryExpression, system: bool = False
|
||||
cls: Type[T], *args: Any, db: Session, system: bool = False
|
||||
) -> PostgresResponse:
|
||||
"""
|
||||
Filter multiple records by expressions.
|
||||
@@ -473,8 +473,8 @@ class FilterAttributes:
|
||||
@classmethod
|
||||
def filter_one(
|
||||
cls: Type[T],
|
||||
*args: Any,
|
||||
db: Session,
|
||||
*args: BinaryExpression,
|
||||
system: bool = False,
|
||||
expired: bool = False,
|
||||
) -> PostgresResponse:
|
||||
|
||||
@@ -110,13 +110,13 @@ class CrudMixin(
|
||||
|
||||
# Common timestamp fields for all models
|
||||
expiry_starts: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP(timezone=True),
|
||||
type_=TIMESTAMP(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False,
|
||||
comment="Record validity start timestamp",
|
||||
)
|
||||
expiry_ends: Mapped[TIMESTAMP] = mapped_column(
|
||||
TIMESTAMP(timezone=True),
|
||||
type_=TIMESTAMP(timezone=True),
|
||||
default="2099-12-31",
|
||||
server_default="2099-12-31",
|
||||
comment="Record validity end timestamp",
|
||||
@@ -434,7 +434,7 @@ class BaseCollection(CrudMixin):
|
||||
__abstract__ = True
|
||||
__repr__ = ReprMixin.__repr__
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
|
||||
|
||||
class CrudCollection(CrudMixin):
|
||||
@@ -454,7 +454,7 @@ class CrudCollection(CrudMixin):
|
||||
__repr__ = ReprMixin.__repr__
|
||||
|
||||
# Primary and reference fields
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
uu_id: Mapped[str] = mapped_column(
|
||||
UUID,
|
||||
server_default=text("gen_random_uuid()"),
|
||||
|
||||
@@ -42,6 +42,11 @@ class PostgresResponse(Generic[T]):
|
||||
self._data: Optional[Union[List[T], T]] = None
|
||||
self._count: Optional[int] = None
|
||||
|
||||
@property
|
||||
def query(self) -> Query:
|
||||
"""Get query object."""
|
||||
return self._query
|
||||
|
||||
@property
|
||||
def data(self) -> Union[List[T], T, None]:
|
||||
"""
|
||||
|
||||
@@ -25,13 +25,13 @@ Base = declarative_base()
|
||||
@lru_cache()
|
||||
def get_session_factory() -> scoped_session:
|
||||
"""Create a thread-safe session factory."""
|
||||
SessionLocal = sessionmaker(
|
||||
session_local = sessionmaker(
|
||||
bind=engine,
|
||||
autocommit=False,
|
||||
autoflush=False,
|
||||
expire_on_commit=False, # Prevent expired object issues
|
||||
)
|
||||
return scoped_session(SessionLocal)
|
||||
return scoped_session(session_local)
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
Reference in New Issue
Block a user