@terascope/sql-builder / clauses
clauses
Interfaces
| Interface | Description |
|---|---|
| SQLSortInput | A sort term whose direction is optional, for code that calls a frame's orderBy. |
Functions
defaultNullOrder()
defaultNullOrder(
direction):SQLNullOrder
Defined in: clauses.ts:46
Where nulls go when the sort does not say.
This follows DataFrame, which treats null as the smallest value: nulls come first when
ascending and last when descending. No engine's default matches:
| ascending | descending | |
|---|---|---|
Elasticsearch (missing defaults to _last) | last | last |
DuckDB (default_null_order) | last | last |
| PostgreSQL (a null is the largest value) | last | first |
DataFrame - what this returns | first | last |
So orderByTerms writes NULLS FIRST or NULLS LAST on every term. To get
Elasticsearch's behavior, pass nulls: 'last' on the sort.
Parameters
| Parameter | Type |
|---|---|
direction | "ASC" | "DESC" |
Returns
SQLNullOrder
groupByClause()
groupByClause(
groupBy?):string
Defined in: clauses.ts:99
A complete GROUP BY clause, or ''.
Each entry is raw SQL, like an ORDER BY expression, so date_trunc('day', ts) is a
valid grouping key.
Parameters
| Parameter | Type |
|---|---|
groupBy? | readonly string[] |
Returns
string
orderByClause()
orderByClause(
sort?):string
Defined in: clauses.ts:88
A complete ORDER BY clause, or '' when the query asked for no ordering.
Parameters
| Parameter | Type |
|---|---|
sort? | readonly SQLSort[] |
Returns
string
orderByTerms()
orderByTerms(
sort?):string
Defined in: clauses.ts:82
The comma-separated ORDER BY terms, without the keyword, or '' for no ordering.
Parameters
| Parameter | Type |
|---|---|
sort? | readonly SQLSort[] |
Returns
string
sortDirection()
sortDirection(
value):"ASC"|"DESC"
Defined in: clauses.ts:17
Validate a sort direction and return ASC or DESC.
The value comes from the request and is written into the statement as a keyword, so it is checked at runtime to prevent SQL injection.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
"ASC" | "DESC"
toSQLSort()
toSQLSort(
sort):SQLSort
Defined in: clauses.ts:118
A frame's sort term as a complete SQLSort, defaulting the direction to ascending.
Parameters
| Parameter | Type |
|---|---|
sort | SQLSortInput |
Returns
SQLSort