-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.ts
More file actions
34 lines (26 loc) · 773 Bytes
/
handler.ts
File metadata and controls
34 lines (26 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { FunctionHandler } from './types';
type Params = {
query?: string;
actor_id?: string;
};
type Result = {
success: boolean;
message: string;
data?: unknown;
};
const handler: FunctionHandler<Params, Result> = async (params, context) => {
const { log, withUserContext } = context;
const { query = 'SELECT version()', actor_id } = params;
log.info('[sql-example] Executing query', { query, actor_id });
const result = await withUserContext(actor_id, async (client) => {
const res = await client.query(query);
return res.rows;
});
log.info('[sql-example] Query complete', { rowCount: result.length });
return {
success: true,
message: 'Query executed successfully',
data: result,
};
};
export default handler;