MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / insertImportBatch

Function insertImportBatch

packages/db/src/services/import.service.ts:108–136  ·  view source on GitHub ↗
(
  events: IClickhouseEvent[],
  importId: string
)

Source from the content-addressed store, hash-verified

106 * Insert a batch of events into the imports staging table
107 */
108export 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.

Callers 3

importJobFunction · 0.90

Calls 2

formatClickhouseDateFunction · 0.90
mapMethod · 0.45

Tested by

no test coverage detected