generated from coulomb/repo-seed
Add hub-core package, docs, and State Hub integration scaffold
Extract the first reusable slice (models, schemas, routers, MCP, migrations) from state-hub with INTENT/SCOPE, agent instructions, workplan, and aligned inter_hub capability registry index.
This commit is contained in:
22
hub_core/utils/pagination.py
Normal file
22
hub_core/utils/pagination.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import TypeVar
|
||||
|
||||
from sqlalchemy.sql import Select
|
||||
|
||||
SelectT = TypeVar("SelectT", bound=Select)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class PageParams:
|
||||
limit: int = 100
|
||||
offset: int = 0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
if self.limit < 1 or self.limit > 1000:
|
||||
raise ValueError("limit must be between 1 and 1000")
|
||||
if self.offset < 0:
|
||||
raise ValueError("offset must be >= 0")
|
||||
|
||||
|
||||
def apply_pagination(query: SelectT, page: PageParams) -> SelectT:
|
||||
return query.offset(page.offset).limit(page.limit)
|
||||
Reference in New Issue
Block a user