Skip to content

Commit 00a7fa7

Browse files
committed
Changeset
1 parent 885d17e commit 00a7fa7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

.changeset/afraid-gorillas-jump.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
---
4+
5+
Added `query.execute()` which lets you query your Trigger.dev data using TRQL (Trigger Query Language) and returns results as typed JSON rows or CSV. It supports configurable scope (environment, project, or organization), time filtering via `period` or `from`/`to` ranges, and a `format` option for JSON or CSV output.
6+
7+
```typescript
8+
import { query } from "@trigger.dev/sdk";
9+
import type { QueryTable } from "@trigger.dev/sdk";
10+
11+
// Basic untyped query
12+
const result = await query.execute("SELECT run_id, status FROM runs LIMIT 10");
13+
14+
// Type-safe query using QueryTable to pick specific columns
15+
const typedResult = await query.execute<QueryTable<"runs", "run_id" | "status" | "triggered_at">>(
16+
"SELECT run_id, status, triggered_at FROM runs LIMIT 10"
17+
);
18+
typedResult.results.forEach(row => {
19+
console.log(row.run_id, row.status); // Fully typed
20+
});
21+
22+
// Aggregation query with inline types
23+
const stats = await query.execute<{ status: string; count: number }>(
24+
"SELECT status, COUNT(*) as count FROM runs GROUP BY status",
25+
{ scope: "project", period: "30d" }
26+
);
27+
28+
// CSV export
29+
const csv = await query.execute(
30+
"SELECT run_id, status FROM runs",
31+
{ format: "csv", period: "7d" }
32+
);
33+
console.log(csv.results); // Raw CSV string
34+
```

0 commit comments

Comments
 (0)