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:
2026-10-18 16:29:14 +01:00
co-authored by Claude Opus 5.5
parent 07807cb19d
commit 938a1da71d
45 changed files with 1524 additions and 115 deletions
+34
View File
@@ -89,6 +89,35 @@ export interface BUN_SQLITE_TableSchemaType {
* Type of vector. Defaults to `vec0`
*/
vectorType?: string;
/**
* Make this a queue table. Adds the `QueueFields` columns and an index
* on `(status, available_at)`. Use `BunSQLite.queue` to work the queue.
*/
isQueue?: boolean | BUN_SQLITE_QueueOptions;
}
/**
* Options for a queue table (`isQueue`).
*/
export interface BUN_SQLITE_QueueOptions {
/**
* Claims allowed before a failing job is marked `failed`. Defaults to `3`
*/
maxAttempts?: number;
/**
* Milliseconds a claimed job can stay `processing` before it is
* released back to the queue. Defaults to `300000` (5 minutes)
*/
lockTimeout?: number;
/**
* Base retry delay in milliseconds, doubled on every attempt. Defaults
* to `1000`
*/
backoff?: number;
/**
* Delete jobs on completion instead of marking them `completed`.
* Defaults to `false`
*/
deleteOnComplete?: boolean;
}
/**
* Reference object used to link a table to one of its child tables.
@@ -1420,6 +1449,11 @@ export type SchemaChange = {
* Default fields automatically suggested for new tables.
*/
export declare const DefaultFields: BUN_SQLITE_FieldSchemaType[];
export declare const QueueStatuses: readonly ["pending", "processing", "completed", "failed"];
/**
* Fields added to queue tables (`isQueue`)
*/
export declare const QueueFields: BUN_SQLITE_FieldSchemaType[];
export type BunSQLiteQueryFieldValues<F extends string = string, T extends string = string> = {
field: F;
table?: T;
+47
View File
@@ -185,3 +185,50 @@ export const DefaultFields = [
fieldDescription: "The time when the record was updated. (Unix Timestamp)",
},
];
export const QueueStatuses = [
"pending",
"processing",
"completed",
"failed",
];
/**
* Fields added to queue tables (`isQueue`)
*/
export const QueueFields = [
{
fieldName: "status",
dataType: "TEXT",
notNullValue: true,
defaultValue: "pending",
fieldDescription: `The state of the job. (${QueueStatuses.join(" | ")})`,
},
{
fieldName: "attempts",
dataType: "INTEGER",
notNullValue: true,
defaultValue: 0,
fieldDescription: "The number of times the job has been claimed.",
},
{
fieldName: "available_at",
dataType: "INTEGER",
notNullValue: true,
defaultValue: 0,
fieldDescription: "The time from which the job can be claimed. (Unix Timestamp)",
},
{
fieldName: "locked_at",
dataType: "INTEGER",
fieldDescription: "The time when the job was claimed. (Unix Timestamp)",
},
{
fieldName: "locked_by",
dataType: "TEXT",
fieldDescription: "The worker that claimed the job.",
},
{
fieldName: "last_error",
dataType: "TEXT",
fieldDescription: "The error from the last failed attempt.",
},
];