Skip to main content

Cloudflare D1 Limitations

Cloudflare D1 is a serverless SQLite database with specific limitations.

No Transaction Support

D1 does not support transactions:

// ❌ NOT SUPPORTED
await db.transaction(async (tx) => {
await tx.insert(table1).values({...});
await tx.insert(table2).values({...});
});

// ✅ Use sequential operations
const result1 = await db.insert(table1).values({...});
const result2 = await db.insert(table2).values({...});

Statement Length Limits

Break large operations into smaller batches:

const BATCH_SIZE = 100;
for (let i = 0; i < records.length; i += BATCH_SIZE) {
const batch = records.slice(i, i + BATCH_SIZE);
await db.insert(table).values(batch);
}

All Operations are Async

Always use await with database operations.