LakeQL
Overview
  • Introduction
Configuration
  • Client Setup
Queries
  • Executing Queries
  • Streaming
Metadata
  • Inspecting Catalogs
  • API Reference
GitHub
LakeQL
  1. Trino Client
  2. API Reference

On this page

  1. API Reference
    1. CTrinoClientError
    2. CTrinoQueryError
    3. CTrinoTimeoutError
    4. CTrinoCancellationError
    5. CTrinoClient
      1. setHeader
      2. setRawHeader
      3. getHeaders
      4. query
      5. stream
      6. cancelQuery
      7. cancelAllQueries
      8. getActiveQueries
      9. schemas
      10. tables
      11. views
      12. columns
      13. dropTable
      14. createTable
    6. IRetryConfig
    7. EState
    8. IBasicAuth
    9. IBearerAuth
    10. TAuth
    11. ETrinoHeader
    12. TTrinoHeaderName
    13. IErrorLocation
    14. IFailureInfo
    15. IQueryError
    16. IWarning
    17. IClientTypeSignature
    18. TClientTypeSignatureParameter
    19. IColumn
    20. IStageStats
    21. IStats
    22. IQueryResult
    23. ITrinoClientProps
    24. IQueryProps
    25. IGetSchemasProps
    26. IGetTablesProps
    27. IGetViewsProps
    28. IGetColumnsProps
    29. IColumnInfo
    30. IDropTableProps
    31. IColumnDefinition
    32. ICreateTableProps

API Reference

Auto-generated reference for all exported types, interfaces, and functions from @lakeql/trino-client.

Base error for Trino client errors.

Constructor

new TrinoClientError(message, statusCode?)

Parameters

ParameterTypeDefault Value
messagestring—
statusCode?number—

Properties

PropertyTypeDefault Value
statusCode?undefined | number—
Modifiers:readonly

HTTP status code if available.

Extends

Error

Error during Trino query execution (Trino returned an error in the response).

Constructor

new TrinoQueryError(message, queryId, errorCode, errorName, errorType)

Parameters

ParameterTypeDefault Value
messagestring—
queryIdstring—
errorCodenumber—
errorNamestring—
errorTypestring—

Properties

PropertyTypeDefault Value
queryIdstring—
Modifiers:readonly

The Trino query ID that failed.

errorCodenumber—
Modifiers:readonly

Trino error code.

errorNamestring—
Modifiers:readonly

Trino error name (e.g. “TABLE_NOT_FOUND”).

errorTypestring—
Modifiers:readonly

Trino error type (e.g. “USER_ERROR”, “INTERNAL_ERROR”).

Extends

Error

Error when a query exceeds its timeout.

Constructor

new TrinoTimeoutError(message, queryId?)

Parameters

ParameterTypeDefault Value
messagestring—
queryId?string—

Properties

PropertyTypeDefault Value
queryId?undefined | string—
Modifiers:readonly

The query ID that timed out, if available.

Extends

Error

Error when a query is cancelled via AbortSignal.

Constructor

new TrinoCancellationError(message, queryId?)

Parameters

ParameterTypeDefault Value
messagestring—
queryId?string—

Properties

PropertyTypeDefault Value
queryId?undefined | string—
Modifiers:readonly

The query ID that was cancelled.

Extends

Error

A client for interacting with a Trino cluster via its REST API.

Uses native fetch — no external HTTP dependencies. Supports automatic pagination, streaming via async generators, query cancellation, and configurable retry with exponential backoff.

Constructor

new TrinoClient({ host, port, auth, catalog, schema, source, retry, timeout, })

Parameters

ParameterTypeDefault Value
{ host, port, auth, catalog, schema, source, retry, timeout, }TrinoClientProps—

Creates a new TrinoClient instance.

Properties

PropertyTypeDefault Value
hoststring—
portnumber—
headersHeaders—

Methods

MethodType
setHeader(key: "X-Trino-User" | "X-Trino-Original-User" | "X-Trino-Source" | "X-Trino-Catalog" | "X-Trino-Schema" | "X-Trino-Time-Zone" | "X-Trino-Language" | "X-Trino-Trace-Token" | "X-Trino-Session" | "X-Trino-Role" | "X-Trino-Prepared-Statement" | "X-Trino-Transaction-Id" | "X-Trino-Client-Info" | "X-Trino-Client-Tags" | "X-Trino-Resource-Estimate" | "X-Trino-Extra-Credential", value: string) => void

Sets a well-known Trino request header.

Parameters

ParameterTypeDefault Value
key"X-Trino-User" | "X-Trino-Original-User" | "X-Trino-Source" | "X-Trino-Catalog" | "X-Trino-Schema" | "X-Trino-Time-Zone" | "X-Trino-Language" | "X-Trino-Trace-Token" | "X-Trino-Session" | "X-Trino-Role" | "X-Trino-Prepared-Statement" | "X-Trino-Transaction-Id" | "X-Trino-Client-Info" | "X-Trino-Client-Tags" | "X-Trino-Resource-Estimate" | "X-Trino-Extra-Credential"—
valuestring—

Returns

void
setRawHeader(key: string, value: string) => void

Sets an arbitrary request header without key validation.

Parameters

ParameterTypeDefault Value
keystring—
valuestring—

Returns

void
getHeaders() => Record<…>

Returns all currently configured request headers as a plain object.

Returns

Record<string, string>
query<T>({ sql, impersonateAs, signal, transform, }: QueryProps<…>) => Promise<…>

Executes a SQL statement and collects all result pages into a single array. Automatically follows nextUri pagination until the result set is complete.

Type Parameters

ParameterConstraintDefault
T——

Parameters

ParameterTypeDefault Value
{ sql, impersonateAs, signal, transform, }QueryProps<T>—

Returns

Promise<Array<T>>
Modifiers:async
stream<T>({ sql, impersonateAs, signal, transform, }: QueryProps<…>) => Promise<…>

Executes a SQL statement and returns an async generator that yields rows one at a time as pages are fetched.

Type Parameters

ParameterConstraintDefault
T——

Parameters

ParameterTypeDefault Value
{ sql, impersonateAs, signal, transform, }QueryProps<T>—

Returns

Promise<AsyncGenerator<T, any, any>>
Modifiers:async
cancelQuery(queryId: string) => Promise<…>

Cancels a running query via its query ID.

Parameters

ParameterTypeDefault Value
queryIdstring—

Returns

Promise<void>
Modifiers:async
cancelAllQueries() => Promise<…>

Cancels all currently active queries tracked by this client.

Returns

Promise<void>
Modifiers:async
getActiveQueries() => Array<…>

Returns the IDs of all currently active (in-flight) queries.

Returns

Array<string>
schemas({ catalog }: GetSchemasProps) => Promise<…>

Lists all schemas in the given catalog.

Parameters

ParameterTypeDefault Value
{ catalog }GetSchemasProps—

Returns

Promise<Array<string>>
Modifiers:async
tables({ catalog, schema }: GetTablesProps) => Promise<…>

Lists all base tables in the given catalog and schema.

Parameters

ParameterTypeDefault Value
{ catalog, schema }GetTablesProps—

Returns

Promise<Array<string>>
Modifiers:async
views({ catalog, schema }: GetViewsProps) => Promise<…>

Lists all views in the given catalog and schema.

Parameters

ParameterTypeDefault Value
{ catalog, schema }GetViewsProps—

Returns

Promise<Array<string>>
Modifiers:async
columns(props: GetColumnsProps & { asObject: true; }) => Promise<…> (+1 overload)

Overload 1

Lists all columns for the given table as typed objects.

Parameters

ParameterTypeDefault Value
propsGetColumnsProps & { asObject: true; }—

Returns

Promise<Array<ColumnInfo>>
Modifiers:async

Overload 2

Lists all columns for the given table as raw tuples.

Parameters

ParameterTypeDefault Value
propsGetColumnsProps & { asObject?: false; }—

Returns

Promise<Array<[name: string, type: string, extra: string, description: string]>>
Modifiers:async
dropTable({ catalog, schema, table }: DropTableProps) => Promise<…>

Drops a table if it exists.

Parameters

ParameterTypeDefault Value
{ catalog, schema, table }DropTableProps—

Returns

Promise<void>
Modifiers:async
createTable({ catalog, schema, table, columns, properties, ifNotExists = true, }?: CreateTableProps) => Promise<…>

Creates an external table with the given column definitions and storage properties.

Parameters

ParameterTypeDefault Value
{ catalog, schema, table, columns, properties, ifNotExists = true, }?CreateTableProps{"ifNotExists":true}

Returns

Promise<void>
Modifiers:async

Configuration for automatic retry behavior.

Properties

PropertyTypeModifiers
maxRetries?number—

Maximum number of retry attempts.

initialDelay?number—

Initial delay between retries in ms.

maxDelay?number—

Maximum delay between retries in ms.

backoffMultiplier?number—

Multiplier for exponential backoff.

retryableStatusCodes?Array<number>—

HTTP status codes that trigger a retry.

Members

MemberValue
"QUEUED""QUEUED"
"PLANNING""PLANNING"
"STARTING""STARTING"
"RUNNING""RUNNING"
"FINISHED""FINISHED"
"CANCELED""CANCELED"
"FAILED""FAILED"

Basic authentication using username and password.

Properties

PropertyTypeModifiers
type"basic"—
usernamestring—

The authentication username.

passwordstring—

The authentication password.

Bearer token authentication (e.g. OAuth2 or JWT).

Properties

PropertyTypeModifiers
type"bearer"—
tokenstring—

The bearer token value.

Type

BasicAuth | BearerAuth

Well-known Trino request headers.

Members

MemberValue
"X-Trino-User"0
"X-Trino-Original-User"1
"X-Trino-Source"2
"X-Trino-Catalog"3
"X-Trino-Schema"4
"X-Trino-Time-Zone"5
"X-Trino-Language"6
"X-Trino-Trace-Token"7
"X-Trino-Session"8
"X-Trino-Role"9
"X-Trino-Prepared-Statement"10
"X-Trino-Transaction-Id"11
"X-Trino-Client-Info"12
"X-Trino-Client-Tags"13
"X-Trino-Resource-Estimate"14
"X-Trino-Extra-Credential"15

A well-known Trino request header name.

Type

"X-Trino-User" | "X-Trino-Original-User" | "X-Trino-Source" | "X-Trino-Catalog" | "X-Trino-Schema" | "X-Trino-Time-Zone" | "X-Trino-Language" | "X-Trino-Trace-Token" | "X-Trino-Session" | "X-Trino-Role" | "X-Trino-Prepared-Statement" | "X-Trino-Transaction-Id" | "X-Trino-Client-Info" | "X-Trino-Client-Tags" | "X-Trino-Resource-Estimate" | "X-Trino-Extra-Credential"

Location in the query where an error occurred.

Properties

PropertyTypeModifiers
lineNumbernumber—
columnNumbernumber—

Detailed failure information including stack trace.

Properties

PropertyTypeModifiers
typestring—
message?string—
cause?FailureInfo—
suppressedArray<FailureInfo>—
stackArray<string>—
errorLocation?ErrorLocation—

Error information when a query fails.

Properties

PropertyTypeModifiers
messagestring—
sqlState?string—
errorCodenumber—
errorNamestring—
errorType"USER_ERROR" | "INTERNAL_ERROR" | "EXTERNAL" | "INSUFFICIENT_RESOURCES"—
errorLocation?ErrorLocation—
failureInfo?FailureInfo—

Warning from Trino during query execution.

Properties

PropertyTypeModifiers
warningCode{ code: number; name: string; }—
messagestring—

Type signature for complex column types.

Properties

PropertyTypeModifiers
rawTypestring—
argumentsArray<ClientTypeSignatureParameter>—

Type

{ kind: "TYPE"; typeSignature: ClientTypeSignature; } | { kind: "LONG"; longLiteral: number; } | { kind: "VARIABLE"; namedTypeSignature: { name?: string; typeSignature: ClientTypeSignature; }; }

Column definition in query results.

Properties

PropertyTypeModifiers
namestring—

Column name.

typestring—

Type string (e.g. “varchar”, “bigint”, “array(varchar)”).

typeSignature?ClientTypeSignature—

Detailed type signature for complex types.

Statistics for a query execution stage.

Properties

PropertyTypeModifiers
stageIdstring—
statestring—
doneboolean—
nodesnumber—
totalSplitsnumber—
queuedSplitsnumber—
runningSplitsnumber—
completedSplitsnumber—
cpuTimeMillisnumber—
wallTimeMillisnumber—
processedRowsnumber—
processedBytesnumber—
physicalInputBytesnumber—
failedTasksnumber—
coordinatorOnlyboolean—
subStagesArray<StageStats>—

Statistics about query execution.

Properties

PropertyTypeModifiers
stateState—
queuedboolean—
scheduledboolean—
progressPercentage?number—
runningPercentage?number—
nodesnumber—
totalSplitsnumber—
queuedSplitsnumber—
runningSplitsnumber—
completedSplitsnumber—
cpuTimeMillisnumber—
wallTimeMillisnumber—
queuedTimeMillisnumber—
elapsedTimeMillisnumber—
processedRowsnumber—
processedBytesnumber—
physicalInputBytesnumber—
peakMemoryBytesnumber—
spilledBytesnumber—
rootStage?StageStats—

Main query results response from Trino.

Type Parameters

ParameterConstraintDefault
T—unknown

Properties

PropertyTypeModifiers
idstring—

The unique query ID.

infoUristring—

URI for the query info page.

partialCancelUri?string—

URI for partial cancellation.

nextUri?string—

URI to fetch next batch of results. If absent, query is complete.

columns?Array<Column>—

Column definitions for the result set.

data?Array<T>—

Result data rows.

statsStats—

Statistics about query execution.

error?QueryError—

Error information if query failed.

warningsArray<Warning>—

List of warnings.

updateType?string—

Type of update operation (e.g. “CREATE TABLE”).

updateCount?number—

Number of rows updated (for DML operations).

Configuration options for creating a TrinoClient instance.

Properties

PropertyTypeModifiers
hoststring—

Trino coordinator hostname including protocol (e.g. "https://trino.example.com").

portnumber—

Port the Trino coordinator listens on.

authAuth—

Authentication credentials — either basic (username/password) or bearer (token).

catalogstring—

Default catalog used for all queries.

schema?string—

Optional default schema used for all queries.

source?string—

Source identifier sent as X-Trino-Source header.

retry?RetryConfig—

Retry configuration for failed requests.

timeout?number—

Default timeout for queries in milliseconds. No timeout when omitted.

Parameters for executing a SQL query or stream.

Type Parameters

ParameterConstraintDefault
T—unknown

Properties

PropertyTypeModifiers
sqlstring—

The SQL statement to execute.

impersonateAs?string—

Optional Trino user to impersonate via X-Trino-User.

signal?AbortSignal—

Abort signal for cancelling the query.

transform?(row: unknown[], columns: Column[]) => T—

Optional transform function to map raw row arrays to typed objects.

Parameters for listing schemas in a catalog.

Properties

PropertyTypeModifiers
catalogstring—

The catalog to inspect.

Parameters for listing tables in a catalog and schema.

Extends

GetSchemasProps

Properties

PropertyTypeModifiers
schemastring—

The schema to inspect.

catalogstring—

The catalog to inspect.

Parameters for listing views in a catalog and schema.

Extends

GetSchemasProps

Properties

PropertyTypeModifiers
schemastring—

The schema to inspect.

catalogstring—

The catalog to inspect.

Parameters for listing columns of a table.

Extends

GetTablesProps

Properties

PropertyTypeModifiers
tablestring—

The table to describe.

asObject?boolean—

When true, returns typed objects instead of raw tuples.

schemastring—

The schema to inspect.

catalogstring—

The catalog to inspect.

Column metadata returned by columns() when asObject is true.

Properties

PropertyTypeModifiers
namestring—

Column name.

typestring—

Trino data type (e.g. “varchar”, “integer”, “timestamp(3)”).

extrastring—

Extra column metadata (e.g. partition key info).

descriptionstring—

Column description/comment.

Parameters for dropping a table.

Properties

PropertyTypeModifiers
catalogstring—

The catalog containing the table.

schemastring—

The schema containing the table.

tablestring—

The table name to drop.

A column definition for CREATE TABLE statements.

Properties

PropertyTypeModifiers
namestring—

The column name.

typestring—

The Trino column type (e.g., “VARCHAR”, “INTEGER”, “TIMESTAMP(3)”).

Parameters for creating a table.

Properties

PropertyTypeModifiers
catalogstring—

The catalog to create the table in.

schemastring—

The schema to create the table in.

tablestring—

The table name to create.

columnsArray<ColumnDefinition>—

Column definitions (name + type pairs).

properties?Record<string, string>—

Optional WITH clause properties (e.g., external_location, format).

ifNotExists?boolean—

Whether to use IF NOT EXISTS (default: true).

Next page

Overview