@@ -4,8 +4,8 @@ import { logger, query, task } from "@trigger.dev/sdk";
44type RunRow = {
55 id : string ;
66 status : string ;
7- created_at : string ;
8- duration : number ;
7+ triggered_at : string ;
8+ total_duration : number ;
99} ;
1010
1111// Simple query example - just the query string, all defaults
@@ -25,7 +25,7 @@ export const simpleQueryTask = task({
2525
2626 // Type-safe query with explicit row type
2727 const typedResult = await query . execute < RunRow > (
28- "SELECT id , status, created_at, duration FROM runs LIMIT 10"
28+ "SELECT run_id , status, triggered_at, total_duration FROM runs LIMIT 10"
2929 ) ;
3030
3131 logger . info ( "Query results (typed)" , {
@@ -39,7 +39,7 @@ export const simpleQueryTask = task({
3939 logger . info ( `Run ${ index + 1 } ` , {
4040 id : row . id , // TypeScript knows this is a string
4141 status : row . status , // TypeScript knows this is a string
42- duration : row . duration , // TypeScript knows this is a number
42+ total_duration : row . total_duration , // TypeScript knows this is a number
4343 } ) ;
4444 } ) ;
4545
@@ -65,7 +65,7 @@ export const fullJsonQueryTask = task({
6565 `SELECT
6666 status,
6767 COUNT(*) as count,
68- AVG(duration ) as avg_duration
68+ AVG(total_duration ) as avg_duration
6969 FROM runs
7070 WHERE status IN ('COMPLETED', 'FAILED')
7171 GROUP BY status` ,
@@ -104,7 +104,7 @@ export const csvQueryTask = task({
104104
105105 // Query with CSV format - automatically typed as discriminated union!
106106 const result = await query . execute (
107- "SELECT id , status, created_at, duration FROM runs LIMIT 100 " ,
107+ "SELECT run_id , status, triggered_at, total_duration FROM runs LIMIT 10 " ,
108108 {
109109 scope : "project" , // Query all environments in the project
110110 period : "7d" , // Last 7 days
@@ -116,22 +116,12 @@ export const csvQueryTask = task({
116116 logger . info ( "CSV query completed" , {
117117 format : result . format ,
118118 dataLength : result . results . length ,
119- preview : result . results . substring ( 0 , 200 ) , // Show first 200 chars
120- } ) ;
121-
122- // Count the number of rows (lines - 1 for header)
123- const lines = result . results . split ( "\n" ) ;
124- const rowCount = lines . length - 1 ;
125-
126- logger . info ( "CSV stats" , {
127- totalRows : rowCount ,
128- headerLine : lines [ 0 ] ,
119+ results : result . results ,
129120 } ) ;
130121
131122 return {
132123 format : result . format ,
133124 csv : result . results ,
134- rowCount,
135125 } ;
136126 } ,
137127} ) ;
0 commit comments