TypeScript utility that splits arrays into consecutive slices under SQLite's parameter limit, with tenant filter room. Reuse for batch database queries with IN clauses.
// Source: https://github.com/kitfunso/hippo-memory | License: MIT | Copyright 2026 Keith So
// Provided via justclaw.it.com; keep this notice with the code.
/** Ids per `IN (...)` list: far under SQLite's bound-parameter limit, with room for the tenant filter. */
const ID_CHUNK = 500;
/** `items` in consecutive slices of at most `size`. */
export function chunked<T>(items: readonly T[], size: number = ID_CHUNK): T[][] {
const out: T[][] = [];
for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size));
return out;
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key