npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

okanjo-app-td

v2.0.0

Published

Service for interfacing with TreasureData

Downloads

5

Readme

Okanjo TreasureData Service

Node.js CI Coverage Status

Service for interfacing with TreasureData for the Okanjo App ecosystem.

Installing

Add to your project like so:

npm install okanjo-app-td

Note: requires the okanjo-app module.

TreasureDataService

Service for working with TreasureData queries.

const TreasureDataService = require('okanjo-app-td');

Properties

  • service.app – (read-only) The OkanjoApp instance provided when constructed
  • service.config – (read-only) The service configuration provided when constructed
  • service.tdClient – (read-only) The underlying TreasureData Node.js Client

Methods

new TreasureDataService(app, config)

Creates a new service instance.

  • app – The OkanjoApp instance to bind to
  • config – (Required) The service configuration object.
    • config.apiKey – (Required) The TD API key to pass to the underlying TD client.
    • config.jobStatusPollInterval – (Optional) Job status polling interval (in ms).

service.query(db, query, options={})

Executes a new query.

  • db - The name of the database to query against
  • query – The SQL query body
  • options - (optional) Query options. Defaults to {}
    • options.hive – (optional) Whether to run the query using Hive (true) or Presto (false). Defaults to false.
    • options.* - Passed to the underlying prestoQuery or hiveQuery TD client call.

Returns Promise<array>, where each row is mapped to an object using the output column names as keys.

service.namedQuery(name, options={})

Executes a new query.

  • name - The name stored query to run
  • options - (optional) Query options. Defaults to {}
    • options.scheduledTime – (optional) The scheduled time the job will execute using. Defaults to Date.now.

Returns Promise<array>, where each row is mapped to an object using the output column names as keys.

service.startPrestoQueryJob(db, query, options={})

Starts a new presto query job.

  • db - The name of the database to query against
  • query – The SQL query body
  • options - (optional) Query options. Defaults to {}

Returns Promise<response>, where response is the TD JSON response.

service.startHiveQueryJob(db, query, options={})

Starts a new hive query job.

  • db - The name of the database to query against
  • query – The SQL query body
  • options - (optional) Query options. Defaults to {}

Returns Promise<response>, where response is the TD JSON response.

service.getJobStatus(jobId)

Gets the status of a job.

  • jobId – Query job id

Returns Promise<response>, where response is the TD JSON response.

service.waitForJobCompletion(jobId)

Resolves once the job has completed.

  • jobId – Query job id

Returns Promise<response>, where response is the TD JSON response.

  • Resolves when the job status is success.
  • Rejects if the job status is error or killed.

service.getJobSchema(jobId)

Gets the output schema of a job.

  • jobId – Query job id

Returns Promise<schema>, where schema is the parsed column schema.

service.getJobResults(jobId, options = 'json')

Gets the output row data of a job.

  • jobId – Query job id

Returns Promise<rows>

service.mapSchemaToJobData(schema, rows)

Returns a mapped array of row objects whose keys are the query column names.

  • schema - Job output schema
  • rows - Job output rows

Returns an Array of mapped row objects.

Events

This class does not emit events.

Extending and Contributing

Our goal is quality-driven development. Please ensure that 100% of the code is covered with testing.

Before contributing pull requests, please ensure that changes are covered with unit tests, and that all are passing.

Testing

To run unit tests and code coverage:

npm run report

This will perform:

  • Unit tests
  • Code coverage report
  • Code linting

Sometimes, that's overkill to quickly test a quick change. To run just the unit tests:

npm test

or if you have mocha installed globally, you may run mocha test instead.