List records with cursor-based pagination, ordering by created_at. Cursor is an ID, but pagination is based on the cursor object's created_at value. Args: db_session: SQLAlchemy session cursor: ID of the last item seen (for pagination) st
(
cls,
*,
db_session: AsyncSession,
cursor: Optional[str] = None,
start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
limit: Optional[int] = 50,
query_text: Optional[str] = None,
query_embedding: Optional[List[float]] = None,
ascending: bool = True,
tags: Optional[List[str]] = None,
match_all_tags: bool = False,
actor: Optional["Client"] = None,
access: Optional[List[Literal["read", "write", "admin"]]] = ["read"],
access_type: AccessType = AccessType.ORGANIZATION,
join_model: Optional[Base] = None,
join_conditions: Optional[Union[Tuple, List]] = None,
**kwargs,
)
| 193 | @handle_db_timeout |
| 194 | @retry_db_operation(max_retries=3, base_delay=0.1, max_delay=2.0) |
| 195 | async def list( |
| 196 | cls, |
| 197 | *, |
| 198 | db_session: AsyncSession, |
| 199 | cursor: Optional[str] = None, |
| 200 | start_date: Optional[datetime] = None, |
| 201 | end_date: Optional[datetime] = None, |
| 202 | limit: Optional[int] = 50, |
| 203 | query_text: Optional[str] = None, |
| 204 | query_embedding: Optional[List[float]] = None, |
| 205 | ascending: bool = True, |
| 206 | tags: Optional[List[str]] = None, |
| 207 | match_all_tags: bool = False, |
| 208 | actor: Optional["Client"] = None, |
| 209 | access: Optional[List[Literal["read", "write", "admin"]]] = ["read"], |
| 210 | access_type: AccessType = AccessType.ORGANIZATION, |
| 211 | join_model: Optional[Base] = None, |
| 212 | join_conditions: Optional[Union[Tuple, List]] = None, |
| 213 | **kwargs, |
| 214 | ) -> List["SqlalchemyBase"]: |
| 215 | """ |
| 216 | List records with cursor-based pagination, ordering by created_at. |
| 217 | Cursor is an ID, but pagination is based on the cursor object's created_at value. |
| 218 | |
| 219 | Args: |
| 220 | db_session: SQLAlchemy session |
| 221 | cursor: ID of the last item seen (for pagination) |
| 222 | start_date: Filter items after this date |
| 223 | end_date: Filter items before this date |
| 224 | limit: Maximum number of items to return |
| 225 | query_text: Text to search for |
| 226 | query_embedding: Vector to search for similar embeddings |
| 227 | ascending: Sort direction |
| 228 | tags: List of tags to filter by |
| 229 | match_all_tags: If True, return items matching all tags. If False, match any tag. |
| 230 | **kwargs: Additional filters to apply |
| 231 | """ |
| 232 | if start_date and end_date and start_date > end_date: |
| 233 | raise ValueError("start_date must be earlier than or equal to end_date") |
| 234 | |
| 235 | logger.debug("Listing %s with kwarg filters %s", cls.__name__, kwargs) |
| 236 | session = db_session |
| 237 | # If cursor provided, get the reference object |
| 238 | cursor_obj = None |
| 239 | if cursor: |
| 240 | cursor_obj = await session.get(cls, cursor) |
| 241 | if not cursor_obj: |
| 242 | raise NoResultFound(f"No {cls.__name__} found with id {cursor}") |
| 243 | |
| 244 | query = select(cls) |
| 245 | |
| 246 | if join_model and join_conditions: |
| 247 | query = query.join(join_model, and_(*join_conditions)) |
| 248 | |
| 249 | # Apply access predicate if actor is provided |
| 250 | if actor: |
| 251 | query = cls.apply_access_predicate(query, actor, access, access_type) |
| 252 |
no test coverage detected