query executes a statement and collects all result pages into a single array. It follows Trino's nextUri pagination automatically.
1
2
3
4
const rows = await client.query<{ id: number; status: string }>({
sql: "SELECT id, status FROM hive.sales.orders",
})
Transforming Rows #
Trino returns rows as positional arrays. Pass a transform to map each row, with its column metadata, into a shape of your choice:
1
2
3
4
5
const rows = await client.query({
sql: "SHOW COLUMNS FROM hive.sales.orders",
transform: (row, columns) => ({ name: row[0], type: row[1] }),
})
Impersonation #
Pass impersonateAs to run the statement as another user through the X-Trino-User header:
1
2
await client.query({ sql: "SELECT 1", impersonateAs: "alice" })
Cancellation #
Pass an AbortSignal to cancel a query, or cancel by id:
1
2
3
4
const controller = new AbortController()
const promise = client.query({ sql: longRunningSql, signal: controller.signal })
controller.abort()
The client tracks in-flight queries. Manage them with cancelQuery, cancelAllQueries, and getActiveQueries. An aborted query throws a TrinoCancellationError.