feat: support pagination in sqlstore

# What does this PR do?


## Test Plan
This commit is contained in:
Eric Huang 2025-06-16 11:33:31 -07:00
parent 40e2c97915
commit f993bdaa1c
10 changed files with 1130 additions and 117 deletions

View file

@ -114,18 +114,18 @@ class LocalfsFilesImpl(Files):
if not self.sql_store:
raise RuntimeError("Files provider not initialized")
# TODO: Implement 'after' pagination properly
if after:
raise NotImplementedError("After pagination not yet implemented")
if not order:
order = Order.desc
where = None
where_conditions = {}
if purpose:
where = {"purpose": purpose.value}
where_conditions["purpose"] = purpose.value
rows = await self.sql_store.fetch_all(
"openai_files",
where=where,
order_by=[("created_at", order.value if order else Order.desc.value)],
paginated_result = await self.sql_store.fetch_all(
table="openai_files",
where=where_conditions if where_conditions else None,
order_by=[("created_at", order.value)],
cursor=("id", after) if after else None,
limit=limit,
)
@ -138,12 +138,12 @@ class LocalfsFilesImpl(Files):
created_at=row["created_at"],
expires_at=row["expires_at"],
)
for row in rows
for row in paginated_result.data
]
return ListOpenAIFileResponse(
data=files,
has_more=False, # TODO: Implement proper pagination
has_more=paginated_result.has_more,
first_id=files[0].id if files else "",
last_id=files[-1].id if files else "",
)