Skip to content

Example trigger.dev task implementations for Tinybird APIs

License

Notifications You must be signed in to change notification settings

sdairs/tinybird-trigger

Repository files navigation

@sdairs/tinybird-trigger-tasks

A collection of trigger.dev task implementations for Tinybird APIs.

Installation

npm install @sdairs/tinybird-trigger-tasks
# or
yarn add @sdairs/tinybird-trigger-tasks
# or
pnpm add @sdairs/tinybird-trigger-tasks

Tasks

Query

The Query task executes a SQL query using the Query API.

Copy

The Copy task executes an on-demand Copy job using the Copy API.

Usage

You can provide your Tinybird API token either through the environment variable TINYBIRD_TOKEN or directly in the task payload.

Copy Task

To run a Copy with no params:

import { tinybirdCopyTask } from '@sdairs/tinybird-trigger-tasks';

const copyResult = await tinybirdCopyTask.triggerAndWait({ 
  pipeId: "YOUR_COPY_PIPE_ID",
  token: "YOUR_TOKEN" // Optional if TINYBIRD_TOKEN env var is set
});

To run a Copy with params:

const copyWithParamResult = await tinybirdCopyTask.triggerAndWait({ 
  pipeId: "YOUR_COPY_WITH_PARAM_ID", 
  params: { test_int: "7" },
  token: "YOUR_TOKEN" // Optional if TINYBIRD_TOKEN env var is set
});

Query Task

To run a Query with no params:

import { tinybirdQueryTask } from '@sdairs/tinybird-trigger-tasks';

const queryResult = await tinybirdQueryTask.triggerAndWait({ 
  sql: "SELECT * FROM table",
  token: "YOUR_TOKEN" // Optional if TINYBIRD_TOKEN env var is set
});

To run a Query with params:

const paramResult = await tinybirdQueryTask.triggerAndWait({ 
  sql: "% SELECT * FROM my_ds WHERE number == {{Int8(test_int)}}", 
  params: { test_int: "7" },
  token: "YOUR_TOKEN" // Optional if TINYBIRD_TOKEN env var is set
});

About

Example trigger.dev task implementations for Tinybird APIs

Topics

Resources

License

Stars

Watchers

Forks