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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlite-executor",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "private": false,
5
5
  "description": "SQLite executor for Node.js",
6
6
  "sideEffects": false,