Examples

Reading table data

1
import * as redivis from 'redivis'
2
3
const rows = await redivis
4
.organization('demo')
5
.dataset('nyt covid us cases deaths')
6
.table('covid_us states')
7
// max_results and variables parameters are optional
8
// If not specified will return all records and variables
9
.listRows({ max_results: 100, variables: ['state', 'cases'] })
Copied!

Execute a query

1
// Execute a query against fully qualified tables on Redivis.
2
// Dataset at https://redivis.com/Demo/datasets/1921
3
4
import * as redivis from 'redivis'
5
6
const rows = await redivis
7
.query(`
8
SELECT *
9
FROM demo.nyt_covid_us_cases_deaths.covid_us_counties
10
WHERE state = 'California'
11
`)
12
.listRows()
Copied!

Execute a scoped query

1
// Perform a query scoped to the "nyt covid us cases deaths" dataset.
2
// Table at https://redivis.com/Demo/datasets/1921/tables
3
4
// We don't need to include fully-qualified table names
5
// if we scope our query to the appropriate dataset or project
6
7
import * as redivis from 'redivis'
8
9
const rows = await redivis
10
.organization('demo')
11
.dataset('nyt covid us cases_deaths')
12
.query(`
13
SELECT *
14
FROM covid_us_states
15
WHERE state = 'California'
16
`)
17
.listRows()
18
Copied!

Authorization

Authorization will happen automatically when querying data, but you can force an authorization flow via this method.
1
import * as redivis from 'redivis'
2
3
redivis.authorize()
4
.then(() => {
5
// Authorization was successful!
6
})
7
.catch((e) => {
8
// Authorization failed :/
9
})
Copied!
Last modified 18d ago