File tree Expand file tree Collapse file tree 2 files changed +423
-55
lines changed
Expand file tree Collapse file tree 2 files changed +423
-55
lines changed Original file line number Diff line number Diff line change 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 */
58export 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}` ;
You can’t perform that action at this time.
0 commit comments