Managing datasources with Tinybird.js

The following methods allow you to fetch and update information about the available datasources in your account.

datasources() - list datasources

The datasources() method returns the list of datasources that are accessible with the Auth Token currently in use, independently of the level of access the token grants: DATASOURCES:READ, DATASOURCES:APPEND OR DATASOURCES:DROP

datasources()
//norun
const tinyb = tinybird('<token>')
console.log(await tinyb.datasources())

info() - get datasource information

The info() method returns information about a specific datasource.

info()
const tinyb = tinybird('<token>')
const { datasources, error } = await tinyb.datasources()
if (datasources.length !== 0) {
    const name = datasources[0]['name']
    console.log(await tinyb.datasource(name).info())
} else {
    console.log(error || `can't fetch any datasources with this token`)
}

schema() - recover datasource schema

schema() returns the schema for a specific datasource. It contains a columns array with all the name and types of each column, as well as whether each of them is a nullable field or not.

schema()
//norun
let tinyb = tinybird('<token>')
console.log(await tinyb.datasource(<datasource>).schema())

delete() - delete a datasource

The method delete() drops the datasource. This action can’t be undone.

delete()
//norun
let tinyb = tinybird('<token>')
await tinyb.datasource('<datasource>').delete()