* Write a single event with a generated UUID v7 event_id. * Call this inside an existing transaction by passing the client directly, * or let it run against the pool for standalone writes.
(input: WriteEventInput, client?: { query: (text: string, params?: unknown[]) => Promise<unknown> })
| 49 | * or let it run against the pool for standalone writes. |
| 50 | */ |
| 51 | async writeEvent(input: WriteEventInput, client?: { query: (text: string, params?: unknown[]) => Promise<unknown> }): Promise<string> { |
| 52 | const eventId = uuidv7(); |
| 53 | const sql = `INSERT INTO catalog_events (event_id, event_type, entity_type, entity_id, payload, actor) |
| 54 | VALUES ($1, $2, $3, $4, $5, $6)`; |
| 55 | const params = [eventId, input.event_type, input.entity_type, input.entity_id, JSON.stringify(input.payload ?? {}), input.actor]; |
| 56 | |
| 57 | if (client) { |
| 58 | await client.query(sql, params); |
| 59 | } else { |
| 60 | await query(sql, params); |
| 61 | } |
| 62 | return eventId; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Write multiple events in a single transaction. |
no test coverage detected