@@ -312,6 +312,30 @@ export const drizzleAdapter = (options: DrizzleAdapterOptions): DBAdapter => {
312312 return row as never ;
313313 } ) ,
314314
315+ // Real multi-row INSERT in fixed-size chunks. One statement per
316+ // chunk, not one per row — per-row loops blow the Hyperdrive
317+ // request budget on specs with thousands of operations. Chunking
318+ // (vs a single giant statement) also keeps payload size bounded:
319+ // JSON columns like tool schemas / operation bindings can be a
320+ // few KB each, so a 2700-row insert becomes a >10MB statement
321+ // otherwise, which chokes both Hyperdrive ingress and WASM
322+ // Postgres (PGlite) in the test harness.
323+ createMany : ( { model, data } ) =>
324+ Effect . gen ( function * ( ) {
325+ if ( data . length === 0 ) return [ ] as never ;
326+ const table = getTable ( model ) ;
327+ const CHUNK = 500 ;
328+ const all : Record < string , unknown > [ ] = [ ] ;
329+ for ( let i = 0 ; i < data . length ; i += CHUNK ) {
330+ const slice = data . slice ( i , i + CHUNK ) as Record < string , unknown > [ ] ;
331+ const rows = ( yield * runPromise ( "insert many returning" , ( ) =>
332+ db . insert ( table ) . values ( slice ) . returning ( ) ,
333+ ) ) as Record < string , unknown > [ ] ;
334+ for ( const row of rows ) all . push ( row ) ;
335+ }
336+ return all as never ;
337+ } ) ,
338+
315339 findOne : ( { model, where, join } ) =>
316340 Effect . gen ( function * ( ) {
317341 const table = getTable ( model ) ;
0 commit comments