@terascope/sql-builder / clauses
clauses
Interfaces
| Interface | Description |
|---|---|
| SQLSortInput | A sort term whose direction is optional, for code that calls a frame's orderBy. |
Type Aliases
SQLJoinType
SQLJoinType =
"inner"|"left"|"right"|"full"|"cross"
Defined in: clauses.ts:123
The joins a statement can make, as joinClause takes them.
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
joinClause()
joinClause(
type,relation,on?):string
Defined in: clauses.ts:154
A JOIN clause, such as LEFT JOIN <relation> ON <condition>.
The relation and the condition are SQL and are used as-is, like an ORDER BY expression:
the relation is usually an aliased table or subquery ("child" AS "c"), and the condition
refers to the aliases. A cross join takes no condition; every other join requires one.
Parameters
| Parameter | Type |
|---|---|
type | SQLJoinType |
relation | string |
on? | string |
Returns
string
joinType()
joinType(
value):"INNER"|"LEFT"|"RIGHT"|"FULL"|"CROSS"
Defined in: clauses.ts:133
Validate a join type and return it as its keyword.
The type is written into the statement as a keyword, so it is checked at runtime, like sortDirection.
Parameters
| Parameter | Type |
|---|---|
value | unknown |
Returns
"INNER" | "LEFT" | "RIGHT" | "FULL" | "CROSS"
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