( events: IClickhouseEvent[], importId: string )
| 106 | * Insert a batch of events into the imports staging table |
| 107 | */ |
| 108 | export async function insertImportBatch( |
| 109 | events: IClickhouseEvent[], |
| 110 | importId: string |
| 111 | ): Promise<ImportStageResult> { |
| 112 | if (events.length === 0) { |
| 113 | return { importId, totalEvents: 0, insertedEvents: 0 }; |
| 114 | } |
| 115 | |
| 116 | const now = formatClickhouseDate(new Date()); |
| 117 | const rows = events.map((event) => ({ |
| 118 | ...event, |
| 119 | import_id: importId, |
| 120 | import_status: 'pending', |
| 121 | imported_at: event.imported_at || now, |
| 122 | imported_at_meta: now, |
| 123 | })); |
| 124 | |
| 125 | await ch.insert({ |
| 126 | table: TABLE_NAMES.events_imports, |
| 127 | values: rows, |
| 128 | format: 'JSONEachRow', |
| 129 | }); |
| 130 | |
| 131 | return { |
| 132 | importId, |
| 133 | totalEvents: events.length, |
| 134 | insertedEvents: events.length, |
| 135 | }; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Insert a batch of profiles into the production profiles table. |
no test coverage detected