- isQueue table option adds queue columns and a (status, available_at) index; BunSQLite.queue exposes add, claim, complete, fail and release_stale with atomic claims - Set busy_timeout on connections so workers in separate processes wait instead of failing with SQLITE_BUSY - Quote table and column names with backticks in generated SQL, so reserved words (to, order, group) work and unknown columns error instead of matching as string literals - Tests for queue ops, multi-process claims and reserved-word names Co-Authored-By: Claude Opus 5.5 <[email protected]>
36 lines
615 B
TypeScript
36 lines
615 B
TypeScript
import { sqlName, sqlStringLiteral } from "./sql-safe";
|
|
|
|
type Param = {
|
|
/**
|
|
* An already validated and quoted column reference
|
|
*/
|
|
field: string;
|
|
alias: string;
|
|
separator?: string;
|
|
distinct?: boolean;
|
|
};
|
|
|
|
export default function sqlGenGrabConcatStr({
|
|
alias,
|
|
field,
|
|
separator = ",",
|
|
distinct,
|
|
}: Param) {
|
|
let gc = `GROUP_CONCAT(`;
|
|
|
|
if (distinct) {
|
|
gc += `DISTINCT `;
|
|
}
|
|
|
|
gc += field;
|
|
|
|
if (!distinct) {
|
|
gc += `, ${sqlStringLiteral(String(separator))}`;
|
|
}
|
|
|
|
gc += `)`;
|
|
gc += ` AS ${sqlName(alias, "alias")}`;
|
|
|
|
return gc;
|
|
}
|