Variable: sql | AppKit
const sql: {
binary: SQLBinaryMarker;
boolean: SQLBooleanMarker;
date: SQLDateMarker;
number: SQLNumberMarker;
string: SQLStringMarker;
timestamp: SQLTimestampMarker;
};
SQL helper namespace
Type Declaration
binary()
binary(value: string | Uint8Array | ArrayBuffer): SQLBinaryMarker;
Creates a BINARY parameter as hex-encoded STRING Accepts Uint8Array, ArrayBuffer, or hex string Note: Databricks SQL Warehouse doesn't support BINARY as parameter type, so this helper returns a STRING with hex encoding. Use UNHEX(:param) in your SQL.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | Uint8Array | ArrayBuffer | Uint8Array, ArrayBuffer, or hex string |
Returns
SQLBinaryMarker
Marker object with STRING type and hex-encoded value
Examples
// From Uint8Array:
const params = { data: sql.binary(new Uint8Array([0x53, 0x70, 0x61, 0x72, 0x6b])) };
// Returns: { __sql_type: "STRING", value: "537061726B" }
// SQL: SELECT UNHEX(:data) as binary_value
// From hex string:
const params = { data: sql.binary("537061726B") };
// Returns: { __sql_type: "STRING", value: "537061726B" }
boolean()
boolean(value: string | number | boolean): SQLBooleanMarker;
Create a BOOLEAN type parameter Accepts booleans, strings, or numbers
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | number | boolean | Boolean, string, or number |
Returns
SQLBooleanMarker
Marker object for BOOLEAN type parameter
Examples
const params = { isActive: sql.boolean(true) };
params = { isActive: "true" }
const params = { isActive: sql.boolean("true") };
params = { isActive: "true" }
const params = { isActive: sql.boolean(1) };
params = { isActive: "true" }
const params = { isActive: sql.boolean("false") };
params = { isActive: "false" }
const params = { isActive: sql.boolean(0) };
params = { isActive: "false" }
date()
date(value: string | Date): SQLDateMarker;
Creates a DATE type parameter Accepts Date objects or ISO date strings (YYYY-MM-DD format)
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | Date | Date object or ISO date string |
Returns
SQLDateMarker
Marker object for DATE type parameter
Examples
const params = { startDate: sql.date(new Date("2024-01-01")) };
params = { startDate: "2024-01-01" }
const params = { startDate: sql.date("2024-01-01") };
params = { startDate: "2024-01-01" }
number()
number(value: string | number): SQLNumberMarker;
Creates a NUMERIC type parameter Accepts numbers or numeric strings
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | number | Number or numeric string |
Returns
SQLNumberMarker
Marker object for NUMERIC type parameter
Examples
const params = { userId: sql.number(123) };
params = { userId: "123" }
const params = { userId: sql.number("123") };
params = { userId: "123" }
string()
string(value: string | number | boolean): SQLStringMarker;
Creates a STRING type parameter Accepts strings, numbers, or booleans
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | number | boolean | String, number, or boolean |
Returns
SQLStringMarker
Marker object for STRING type parameter
Examples
const params = { name: sql.string("John") };
params = { name: "John" }
const params = { name: sql.string(123) };
params = { name: "123" }
const params = { name: sql.string(true) };
params = { name: "true" }
timestamp()
timestamp(value: string | number | Date): SQLTimestampMarker;
Creates a TIMESTAMP type parameter Accepts Date objects, ISO timestamp strings, or Unix timestamp numbers
Parameters
| Parameter | Type | Description |
|---|---|---|
value | string | number | Date | Date object, ISO timestamp string, or Unix timestamp number |
Returns
SQLTimestampMarker
Marker object for TIMESTAMP type parameter
Examples
const params = { createdTime: sql.timestamp(new Date("2024-01-01T12:00:00Z")) };
params = { createdTime: "2024-01-01T12:00:00Z" }
const params = { createdTime: sql.timestamp("2024-01-01T12:00:00Z") };
params = { createdTime: "2024-01-01T12:00:00Z" }
const params = { createdTime: sql.timestamp(1704110400000) };
params = { createdTime: "2024-01-01T12:00:00Z" }