MCPcopy Index your code
hub / github.com/simstudioai/sim / selectRowDataPage

Function selectRowDataPage

apps/sim/lib/table/rows/ordering.ts:542–574  ·  view source on GitHub ↗
(params: {
  tableId: string
  workspaceId: string
  cutoff: Date
  filterClause?: SQL
  afterId?: string
  limit: number
  excludeIfPatched?: string
})

Source from the content-addressed store, hash-verified

540 * would double-count progress. It also skips no-op updates of rows that already hold those values.
541 */
542export async function selectRowDataPage(params: {
543 tableId: string
544 workspaceId: string
545 cutoff: Date
546 filterClause?: SQL
547 afterId?: string
548 limit: number
549 excludeIfPatched?: string
550}): Promise<Array<{ id: string; data: RowData }>> {
551 const { tableId, workspaceId, cutoff, filterClause, afterId, limit, excludeIfPatched } = params
552 const selectPage = (executor: DbExecutor) =>
553 executor
554 .select({ id: userTableRows.id, data: userTableRows.data })
555 .from(userTableRows)
556 .where(
557 and(
558 eq(userTableRows.tableId, tableId),
559 eq(userTableRows.workspaceId, workspaceId),
560 lte(userTableRows.createdAt, cutoff),
561 afterId ? gt(userTableRows.id, afterId) : undefined,
562 excludeIfPatched
563 ? sql`NOT (${userTableRows.data} @> ${excludeIfPatched}::jsonb)`
564 : undefined,
565 filterClause
566 )
567 )
568 .orderBy(asc(userTableRows.id))
569 .limit(limit)
570 const rows = filterClause
571 ? await withSeqscanOff(async (trx) => selectPage(trx))
572 : await selectPage(db)
573 return rows.map((r) => ({ id: r.id, data: r.data as RowData }))
574}
575
576/**
577 * Deletes one page of rows for the async delete-job worker, committing each `DELETE_BATCH_SIZE`

Callers 1

runTableUpdateFunction · 0.90

Calls 2

withSeqscanOffFunction · 0.90
selectPageFunction · 0.85

Tested by

no test coverage detected