Skip to content

Commit 4377fd9

Browse files
authored
fix workflow code (#140)
* fix workflow code * fix nested code * fixes
1 parent 8fb0672 commit 4377fd9

File tree

2 files changed

+423
-55
lines changed

2 files changed

+423
-55
lines changed
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
/**
22
* Code template for Database Query action step
33
* This is a string template used for code generation - keep as string export
4+
*
5+
* Requires: pnpm add postgres
6+
* Environment: DATABASE_URL
47
*/
58
export default `export async function databaseQueryStep(input: {
69
query: string;
710
}) {
811
"use step";
912
10-
// Database Query - You need to set up your database connection
11-
// Install: pnpm add postgres (or your preferred database library)
12-
// Set DATABASE_URL in your environment variables
13+
const databaseUrl = process.env.DATABASE_URL;
14+
if (!databaseUrl) {
15+
return { success: false, error: "DATABASE_URL environment variable is not set" };
16+
}
1317
14-
// Example using postgres library:
15-
// import postgres from 'postgres';
16-
// const sql = postgres(process.env.DATABASE_URL!);
17-
// const result = await sql.unsafe(input.query);
18-
// await sql.end();
18+
const postgres = await import("postgres");
19+
const sql = postgres.default(databaseUrl, { max: 1 });
1920
20-
throw new Error('Database Query not implemented - see comments in generated code');
21+
try {
22+
const result = await sql.unsafe(input.query);
23+
await sql.end();
24+
return { success: true, rows: result, count: result.length };
25+
} catch (error) {
26+
await sql.end();
27+
const message = error instanceof Error ? error.message : String(error);
28+
return { success: false, error: \`Database query failed: \${message}\` };
29+
}
2130
}`;

0 commit comments

Comments
 (0)