MCPcopy Index your code
hub / github.com/simstudioai/sim / batchInsertAll

Function batchInsertAll

apps/sim/lib/copilot/tools/server/table/user-table.ts:306–329  ·  view source on GitHub ↗
(
  tableId: string,
  rows: RowData[],
  table: TableDefinition,
  workspaceId: string,
  context?: ServerToolContext
)

Source from the content-addressed store, hash-verified

304}
305
306async function batchInsertAll(
307 tableId: string,
308 rows: RowData[],
309 table: TableDefinition,
310 workspaceId: string,
311 context?: ServerToolContext
312): Promise<number> {
313 let inserted = 0
314 const userId = context?.userId
315 for (let i = 0; i < rows.length; i += MAX_BATCH_SIZE) {
316 assertServerToolNotAborted(context, 'Request aborted before table mutation could be applied.')
317 const batch = rows.slice(i, i + MAX_BATCH_SIZE)
318 const requestId = generateId().slice(0, 8)
319 const result = await batchInsertRows(
320 { tableId, rows: batch, workspaceId, userId },
321 // Pass the running total so each batch's capacity check sees cumulative rows,
322 // not the same pre-loop snapshot (which would let a multi-batch insert overshoot).
323 { ...table, rowCount: table.rowCount + inserted },
324 requestId
325 )
326 inserted += result.length
327 }
328 return inserted
329}
330
331export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult> = {
332 name: UserTable.id,

Callers 1

executeFunction · 0.85

Calls 3

generateIdFunction · 0.90
batchInsertRowsFunction · 0.90

Tested by

no test coverage detected