* 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 )
| 743 | * (a find vs a list page) could shuffle ties and misalign ordinals. |
| 744 | */ |
| 745 | function 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}. */ |
| 763 | export interface FindRowMatch { |
no test coverage detected