Skip to content

trinodb/trino-js-client

Repository files navigation

trino-js-client

A Trino client for Node.js.

Warning

The project is currently undergoing a migration to the trinodb organization. Join us on Trino Slack in #core-dev, help us, and stay tuned.

@latest it-tests license

Features

  • Connections over HTTP or HTTPS
  • Supports HTTP Basic Authentication
  • Per-query user information for access control

Requirements

  • Node 12 or newer.
  • Trino 0.16x or newer.

Install

npm install trino-client or yarn add trino-client

Usage

For additional info on all available methods and types have a look at the API documentation.

Create a Trino client

const trino: Trino = Trino.create({
  server: 'http://localhost:8080',
  catalog: 'tpcds',
  schema: 'sf100000',
  auth: new BasicAuth('test'),
});

Submit a query

const iter: Iterator<QueryResult> = await trino.query(
  'select * from customer limit 100'
);

Iterate through the query results

for await (const queryResult of iter) {
  console.log(queryResult.data);
}

Alternative: map and aggregate the data

const data: QueryData[] = await iter
  .map(r => r.data ?? [])
  .fold<QueryData[]>([], (row, acc) => [...acc, ...row]);

Examples

More usage examples can be found in the integration tests.

Build

Use the following commands to build the project locally with your modifications, and in preparation to contribute a pull request.

Requirements:

  • yarn

Install dependencies:

yarn install --frozen-lockfile

Lint the source code:

yarn test:lint

Build

yarn build

Contributing

Follow the Trino contribution guidelines and contact us on Slack and GitHub.

Copyright Trino JS Client contributors 2022-present