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

Function buildRowOrderBySql

apps/sim/lib/table/rows/service.ts:745–760  ·  view source on GitHub ↗

* Canonical ORDER BY for a table's rows, shared by `queryRows` (the paginated * list) and `findRowMatches` so a match's ordinal lines up with its index in * the list. Order: explicit data sort (if any) → fractional `order_key` or * legacy `position` → `id`. The `id` tiebreak is always appended so

(
  sort: Sort | undefined,
  tableName: string,
  columns: ColumnDefinition[],
  fractionalOrderingEnabled: boolean
)

Source from the content-addressed store, hash-verified

743 * (a find vs a list page) could shuffle ties and misalign ordinals.
744 */
745function buildRowOrderBySql(
746 sort: Sort | undefined,
747 tableName: string,
748 columns: ColumnDefinition[],
749 fractionalOrderingEnabled: boolean
750): SQL {
751 const primary = fractionalOrderingEnabled ? `${tableName}.order_key` : `${tableName}.position`
752 const id = `${tableName}.id`
753 if (sort && Object.keys(sort).length > 0) {
754 const sortClause = buildSortClause(sort, tableName, columns)
755 if (sortClause) {
756 return sql.join([sortClause, sql.raw(primary), sql.raw(id)], sql.raw(', '))
757 }
758 }
759 return sql.raw(`${primary}, ${id}`)
760}
761
762/** One matching cell from {@link findRowMatches}. */
763export interface FindRowMatch {

Callers 2

findRowMatchesFunction · 0.85
buildPageQueryFunction · 0.85

Calls 2

buildSortClauseFunction · 0.90
joinMethod · 0.80

Tested by

no test coverage detected