Skip to main content

@terascope/sql-builder / quoting

quoting

Functions​

parens()​

parens(expression): string

Defined in: quoting.ts:49

Wrap an expression in parentheses so operator precedence cannot change its meaning.

An expression that is already one parenthesized group is left alone, to keep the generated SQL readable.

Parameters​

ParameterType
expressionstring

Returns​

string


quoteBoolean()​

quoteBoolean(value): string

Defined in: quoting.ts:142

A boolean literal.

Parameters​

ParameterType
valueunknown

Returns​

string


quoteIdentifier()​

quoteIdentifier(name): string

Defined in: quoting.ts:24

Quote an identifier, always.

Quoting every identifier means reserved words such as group, order and end work as field names without a reserved-word list.

Case handling differs: DuckDB matches quoted identifiers case-insensitively, while PostgreSQL treats them as case-sensitive. A dialect that needs a normalized name should normalize it before calling this.

@terascope/data-types has its own copy so that it does not depend on a query builder.

Parameters​

ParameterType
namestring

Returns​

string


quoteLiteral()​

quoteLiteral(value): string

Defined in: quoting.ts:39

Quote a value as a SQL string literal.

Doubling single quotes is the only escaping needed. DuckDB and PostgreSQL (with standard_conforming_strings on, the default since 9.1) treat a backslash in a single-quoted string as an ordinary character. An engine that does not can override SQLDialect.stringLiteral.

Do not use core-utils' jsStringEscape here: it escapes for JavaScript, so it would change C:\path and would not escape the single quote.

Parameters​

ParameterType
valuestring

Returns​

string


quoteNumber()​

quoteNumber(value): string

Defined in: quoting.ts:109

A number literal. Throws for NaN and Infinity, which have no correct SQL equivalent.

Parameters​

ParameterType
valueunknown

Returns​

string


toEpochMillisText()​

toEpochMillisText(value): string

Defined in: quoting.ts:170

A date as epoch milliseconds, for comparing with the ms member of a DuckDB date column (STRUCT(ms BIGINT, tz_offset SMALLINT)). Any offset in the value is applied: '2020-01-01T00:00:00+02:00' is 1577829600000.

Parameters​

ParameterType
valueunknown

Returns​

string


toLiteralString()​

toLiteralString(value): string

Defined in: quoting.ts:175

A value as the text a SQL literal needs, or a thrown error for something that is not.

Parameters​

ParameterType
valueunknown

Returns​

string


toUTCTimestampText()​

toUTCTimestampText(value): string

Defined in: quoting.ts:159

A date as UTC text, ready to cast to a TIMESTAMP without a time zone.

DuckDB's TIMESTAMP cast drops a time zone offset instead of applying it: CAST('2020-01-01T00:00:00+02:00' AS TIMESTAMP) is 2020-01-01 00:00:00. Converting to UTC first gives the same instant in every engine and server time zone.

Parameters​

ParameterType
valueunknown

Returns​

string


wholeNumber()​

wholeNumber(value, name): number

Defined in: quoting.ts:128

Validate a row count as a non-negative integer.

A LIMIT cannot be a bound parameter, so the number is written into the statement and is checked to prevent SQL injection.

Parameters​

ParameterType
valueunknown
namestring

Returns​

number