sql-batching

Batch Drizzle ORM SQL queries to stay within D1's 100 parameter limit.

2|2|Updated May 30, 2025
One-click install
npx skills add https://github.com/wodsmith/thewodapp --skill sql-batching
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: sql-batching
Source: https://github.com/wodsmith/thewodapp/tree/main/.claude/skills/sql-batching
Command: npx skills add https://github.com/wodsmith/thewodapp --skill sql-batching

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prevents D1 "too many SQL variables" errors when using Drizzle ORM by batching queries with autochunk utilities and chunking for parallel execution.

Core Features & Use Cases

  • 100 parameter limit awareness: D1's actual limit is 100 bound parameters per query
  • Batch utilities: autochunk, autochunkFirst, and chunk with SQL_BATCH_SIZE
  • Bulk inserts & inArray: handle dynamic arrays and parameter counts

Quick Start

Use autochunk to process large lists of IDs, or autochunkFirst for a first-match query across batches.

Frequently Asked Questions about sql-batching

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix 'too many SQL variables' errors in Drizzle ORM with D1?

Batching SQL queries prevents 'too many SQL variables' errors by chunking operations into smaller batches that respect D1's 100 bound parameter limit. Use autochunk to automatically split large inArray() queries and bulk inserts into safe-sized batches executed in parallel.

What's the 100 parameter limit in D1, and how does it affect my queries?

D1 accepts a maximum of 100 bound parameters per query. When using Drizzle's inArray() or bulk insert operations with dynamic arrays, parameter counts can exceed this limit, causing query failures. Batching divides the operation to stay within bounds.

How do I batch bulk inserts and inArray queries in Drizzle?

Use autochunk or autochunkFirst utilities with SQL_BATCH_SIZE to automatically divide large operations into batches. autochunk executes all batches in parallel with Promise.all, while autochunkFirst returns the first result across batches.

Can I use batching with dynamic arrays of unbounded size?

Yes. Batching dynamically computes safe batch sizes based on total columns and existing parameters in your query, then chunks the array accordingly, ensuring total bound parameters never exceed D1's 100-parameter limit.

When should I use autochunk vs autochunkFirst for batched queries?

Use autochunk when you need all results from all batches executed in parallel. Use autochunkFirst when searching across batches and only the first matching result is needed, reducing unnecessary batch executions.