Skip to main content

@terascope/sql-builder / clauses

clauses

Interfaces​

InterfaceDescription
SQLSortInputA 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:

ascendingdescending
Elasticsearch (missing defaults to _last)lastlast
DuckDB (default_null_order)lastlast
PostgreSQL (a null is the largest value)lastfirst
DataFrame - what this returnsfirstlast

So orderByTerms writes NULLS FIRST or NULLS LAST on every term. To get Elasticsearch's behavior, pass nulls: 'last' on the sort.

Parameters​

ParameterType
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​

ParameterType
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​

ParameterType
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​

ParameterType
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​

ParameterType
valueunknown

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​

ParameterType
sortSQLSortInput

Returns​

SQLSort