MCPcopy Create free account
hub / github.com/electric-sql/electric / batchInsert

Function batchInsert

examples/linearlite/db/load_data.js:19–31  ·  view source on GitHub ↗
(sql, table, columns, dataArray, batchSize = 1000)

Source from the content-addressed store, hash-verified

17const sql = postgres(DATABASE_URL)
18
19async function batchInsert(sql, table, columns, dataArray, batchSize = 1000) {
20 for (let i = 0; i < dataArray.length; i += batchSize) {
21 const batch = dataArray.slice(i, i + batchSize)
22
23 await sql`
24 INSERT INTO ${sql(table)} ${sql(batch, columns)}
25 `
26
27 process.stdout.write(
28 `Loaded ${Math.min(i + batchSize, dataArray.length)} of ${dataArray.length} ${table}s\r`
29 )
30 }
31}
32
33const issueCount = issues.length
34let commentCount = 0

Callers 1

load_data.jsFile · 0.85

Calls 2

sliceMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected