Examples

Reading table data

import * as redivis from 'redivis'

const rows = await redivis
  .organization('demo')
  .dataset('nyt covid us cases deaths')
  .table('covid_us states')
  // max_results and variables parameters are optional
  // If not specified will return all records and variables
  .listRows({ max_results: 100, variables: ['state', 'cases'] }) 

Execute a query

// Execute a query against fully qualified tables on Redivis. 
// Dataset at https://redivis.com/Demo/datasets/1921

import * as redivis from 'redivis'

const rows = await redivis
  .query(`
    SELECT * 
    FROM demo.nyt_covid_us_cases_deaths.covid_us_counties 
    WHERE state = 'California'
  `)
  .listRows()

Execute a scoped query

// Perform a query scoped to the "nyt covid us cases deaths" dataset. 
// Table at https://redivis.com/Demo/datasets/1921/tables

// We don't need to include fully-qualified table names 
//    if we scope our query to the appropriate dataset or project

import * as redivis from 'redivis'

const rows = await redivis
  .organization('demo')
  .dataset('nyt covid us cases_deaths')
  .query(`
    SELECT * 
    FROM covid_us_states
    WHERE state = 'California'
  `)
  .listRows()

Authorization

Authorization will happen automatically when querying data, but you can force an authorization flow via this method.

import * as redivis from 'redivis'

redivis.authorize()
  .then(() => {
    // Authorization was successful!
  })
  .catch((e) => {
    // Authorization failed :/
  })

Last updated