Managing Data Sources with Tinybird.js

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

datasources()

The datasources() method returns the list of Data Sources 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()

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 Data Sources with this token`)
}

schema()

The schema() method 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()

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

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