sqlite-executor 4.0.4 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,14 @@
1
+ import type { SQLTemplate } from "./normalize";
2
+
3
+ /**
4
+ * 使用预解析的模板替换参数,避免重新扫描 SQL。
5
+ *
6
+ * @param template - 由 `normalizeSQLTemplate` 返回的预解析模板
7
+ * @param params - 要插值的参数数组
8
+ * @returns 插值后的完整 SQL 字符串
9
+ */
10
+ export function interpolateFromTemplate(template: SQLTemplate, params: any[]): string;
11
+
1
12
  /**
2
13
  * 替换 SQL 语句中的 `?` 占位符为转义后的参数值。
3
14
  *
@@ -5,3 +5,27 @@
5
5
  * @returns 规范化后的 SQL 语句
6
6
  */
7
7
  export function normalizeSQL(sql: string): string;
8
+
9
+ export interface SQLTemplate {
10
+ /** 规范化后的完整 SQL 字符串 */
11
+ normalized: string;
12
+ /**
13
+ * 以 `?` 为分隔符的片段数组。
14
+ * - segments[0] 为第一个 `?` 之前的部分
15
+ * - segments[n] 为第 n 个 `?` 之后、第 n+1 个 `?` 之前的部分
16
+ * - 最后一个元素为最后一个 `?` 之后的部分
17
+ * - 无 `?` 时 segments 为 [normalized]
18
+ */
19
+ segments: string[];
20
+ /** `?` 占位符的数量 */
21
+ paramCount: number;
22
+ }
23
+
24
+ /**
25
+ * 单次扫描同时完成 SQL 规范化和 `?` 占位符追踪。
26
+ * 避免 `normalizeSQL` + `_parseTemplate` 两次扫描的重复开销。
27
+ *
28
+ * @param sql - 原始 SQL 语句
29
+ * @returns 包含规范化结果和占位符信息的模板对象
30
+ */
31
+ export function normalizeSQLTemplate(sql: string): SQLTemplate;
@@ -3,9 +3,10 @@ export const DEFAULT_STATEMENT_TIMEOUT: 30000;
3
3
 
4
4
  /**
5
5
  * 创建包含 SQL 上下文的超时错误。
6
+ * 注意:sql 应已由调用方完成规范化,本函数不再内部调用 normalizeSQL。
6
7
  *
7
8
  * @param timeout - 超时时间(毫秒)
8
- * @param sql - 超时发生时正在执行的 SQL 语句
9
+ * @param sql - 超时发生时正在执行的 SQL 语句(已规范化)
9
10
  * @returns 包含超时时间和 SQL 信息的 Error 实例
10
11
  */
11
12
  export function createTimeoutError(timeout: number, sql: string): Error;
@@ -1,6 +1,13 @@
1
1
  /** 基于 Map 插入顺序的 LRU 缓存。 */
2
2
  export declare class LRUCache<T> {
3
- constructor(options?: { maxSize?: number; maxKeyLength?: number });
3
+ /**
4
+ * 创建 LRUCache 实例。
5
+ * @param options 可选项。
6
+ * @param options.maxSize 最大缓存条目数,默认为 100。
7
+ * @param options.maxKeyLength 超长 key 的最大长度,默认为 100。超过该长度的 key 不会被缓存。
8
+ * @param options.maxValueLength 超长 value 的最大长度,默认为 Infinity。超过该长度的 value 不会被缓存。
9
+ */
10
+ constructor(options?: { maxSize?: number; maxKeyLength?: number, maxValueLength?: number });
4
11
 
5
12
  /** 获取缓存值,命中时提升到末尾。未命中或 key 不合法时返回 undefined。 */
6
13
  get(key: string): T | undefined;
@@ -16,6 +16,8 @@ export interface PipelineEngineOptions {
16
16
  maxInflight?: number;
17
17
  /** 任务超时时的回调 */
18
18
  onTaskTimeout?: (task: any) => void;
19
+ /** 任务超时检查的时间间隔,默认 100ms */
20
+ sweepInterval?: number;
19
21
  }
20
22
 
21
23
  /**
@@ -2,7 +2,7 @@
2
2
  * 只读 Worker 连接池。
3
3
  *
4
4
  * 管理多个 TaskWorker 实例,所有 worker 共享同一数据库文件。
5
- * 通过轮询(round-robin)分配读任务,实现读操作的水平扩展。
5
+ * 通过 Least Busy(最小负载)分配读任务,实现读操作的水平扩展。
6
6
  *
7
7
  * 注意:ReaderPool 中的 worker 不初始化 WAL 模式(`initMode: "none"`),
8
8
  * 直接继承数据库文件头中的 journal 模式,避免与 writer 竞争 WAL 初始化锁。
@@ -30,7 +30,7 @@ export class ReaderPool {
30
30
  get pendingStatements(): number;
31
31
 
32
32
  /**
33
- * 分发一个读任务到下一个空闲 Worker(轮询)。
33
+ * 分发一个读任务到负载最小的 Worker(Least Busy)。
34
34
  * @param task - 任务配置对象
35
35
  */
36
36
  enqueue(task: object): void;