Add queue tables, quote SQL identifiers (v1.3.0)
- 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]>
This commit is contained in:
Vendored
+20
@@ -25,6 +25,26 @@ export function sqlField(name, label = "field name") {
|
||||
}
|
||||
return str;
|
||||
}
|
||||
/**
|
||||
* # Validate and quote an identifier for queries
|
||||
* @description Quoting lets reserved words (`to`, `order`, ...) be used as
|
||||
* names. Backticks, not double quotes: SQLite reads an unknown `"name"` as
|
||||
* a string literal, so a typo would silently match nothing instead of
|
||||
* failing with "no such column".
|
||||
*/
|
||||
export function sqlName(name, label = "identifier") {
|
||||
return `\`${sqlIdent(name, label)}\``;
|
||||
}
|
||||
/**
|
||||
* # Validate and quote a column reference
|
||||
* @description Accepts `field`, `table.field` or `table.*`
|
||||
*/
|
||||
export function sqlColumn(name, label = "field name") {
|
||||
return sqlField(name, label)
|
||||
.split(".")
|
||||
.map((part) => (part === "*" ? part : `\`${part}\``))
|
||||
.join(".");
|
||||
}
|
||||
/**
|
||||
* # Quote an identifier for DDL statements
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user