Requirements

  • Node 12 or newer.

Install

npm install @peaka/client or yarn add @peaka/client

Usage

Create a Peaka connection

import { Peaka, connectToPeaka } from "@peaka/client";

const connection: Peaka = connectToPeaka("<YOUR_API_KEY>")

Submit a query

import type { QueryResult } from "@peaka/client";

try{
  const iter: Iterator<QueryResult> = await connection.query(
    'select * from <CATALOG_NAME>.<SCHEMA_NAME>.<TABLE_NAME> limit 100'
  );
}catch(err){
  console.error(err.response.data);
})

Iterate through the query results

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

Alternative: map and aggregate the data

import type { QueryData } from "@peaka/client";

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

Handle the Errors

Query errors are returned in the error.response.data object, and this object contains the following properties:

Error PropertyDescription
errorCodeCode of error
messageDescription of the error
traceIdThe identifier that you can give Peaka Team to learn more about the error