* Builds an emptiness check against a JSONB cell. `isEmpty` matches null cells * (absent key or JSON null, both surfaced as SQL NULL by `->>`) and empty * strings; the negation requires the cell to be present and non-empty.
(tableName: string, field: string, isEmpty: boolean)
| 557 | * strings; the negation requires the cell to be present and non-empty. |
| 558 | */ |
| 559 | function buildEmptyClause(tableName: string, field: string, isEmpty: boolean): SQL { |
| 560 | const escapedField = field.replace(/'/g, "''") |
| 561 | const cell = sql.raw(`${tableName}.data->>'${escapedField}'`) |
| 562 | return isEmpty |
| 563 | ? sql`(${cell} IS NULL OR ${cell} = '')` |
| 564 | : sql`(${cell} IS NOT NULL AND ${cell} <> '')` |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Builds a single ORDER BY clause for a field. |
no test coverage detected