@digitalwalletcorp/sql-builder 2.0.0 → 2.1.0

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/%40digitalwalletcorp%2Fsql-builder)](https://www.npmjs.com/package/@digitalwalletcorp/sql-builder) [![License](https://img.shields.io/npm/l/%40digitalwalletcorp%2Fsql-builder)](https://opensource.org/licenses/MIT) [![Build Status](https://img.shields.io/github/actions/workflow/status/digitalwalletcorp/sql-builder/ci.yml?branch=main)](https://github.com/digitalwalletcorp/sql-builder/actions) [![Test Coverage](https://img.shields.io/codecov/c/github/digitalwalletcorp/sql-builder.svg)](https://codecov.io/gh/digitalwalletcorp/sql-builder)
4
4
 
5
- Inspired by Java's S2Dao, this TypeScript/JavaScript library dynamically generates SQL. It embeds entity objects into SQL templates, simplifying complex query construction and enhancing readability. Ideal for flexible, type-safe SQL generation without a full ORM. It efficiently handles dynamic `WHERE` clauses, parameter binding, and looping, reducing boilerplate code.
5
+ Inspired by Java's **S2Dao its successor Doma**, this TypeScript/JavaScript library dynamically generates SQL. It embeds entity objects into SQL templates, simplifying complex query construction and enhancing readability. Ideal for flexible, type-safe SQL generation without a full ORM. It efficiently handles dynamic `WHERE` clauses, parameter binding, and looping, reducing boilerplate code.
6
6
 
7
7
  The core mechanism involves parsing special SQL comments (`/*IF ...*/`, `/*BEGIN...*/`, etc.) in a template and generating a final query based on a provided data object.
8
8
 
@@ -47,23 +47,23 @@ console.log(sql);
47
47
 
48
48
  > 💡 Tip: If you upgrade a template from v1.x to v2.x, make sure to add parentheses around any IN bind variables to avoid SQL syntax errors.
49
49
 
50
- ### ✨ Features
50
+ #### ✨ Features
51
51
 
52
52
  * Dynamic Query Generation: Build complex SQL queries dynamically at runtime.
53
- * Conditional Logic (`/*IF...*/`): Automatically include or exclude SQL fragments based on JavaScript conditions evaluated against your data.
53
+ * Conditional Logic (`/*IF...*/`, `/*ELSEIF...*/`, `/*ELSE...*/`): Robust conditional branching. Support for complex `if-elseif-else` structures, including nesting.
54
54
  * Optional Blocks (`/*BEGIN...*/`): Wrap entire clauses (like `WHERE`) that are only included if at least one inner `/*IF...*/` condition is met.
55
55
  * Looping (`/*FOR...*/`): Generate repetitive SQL snippets by iterating over arrays in your data (e.g., for multiple `LIKE` or `OR` conditions).
56
56
  * Simple Parameter Binding: Easily bind values from your data object into the SQL query.
57
57
  * Zero Dependencies: A single, lightweight class with no external library requirements.
58
58
 
59
- ### ✅ Compatibility
59
+ #### ✅ Compatibility
60
60
 
61
61
  This library is written in pure, environment-agnostic JavaScript/TypeScript and has zero external dependencies, allowing it to run in various environments.
62
62
 
63
63
  - ✅ **Node.js**: Designed and optimized for server-side use in any modern Node.js environment. This is the **primary and recommended** use case.
64
64
  - ⚠️ **Browser-like Environments (Advanced)**: While technically capable of running in browsers (e.g., for use with in-browser databases like SQLite via WebAssembly), generating SQL on the client-side to be sent to a server **is a significant security risk and is strongly discouraged** in typical web applications.
65
65
 
66
- ### 📦 Instllation
66
+ #### 📦 Installation
67
67
 
68
68
  ```bash
69
69
  npm install @digitalwalletcorp/sql-builder
@@ -89,7 +89,7 @@ SELECT
89
89
  FROM activity
90
90
  /*BEGIN*/WHERE
91
91
  1 = 1
92
- /*IF projectNames != null && projectNames.length*/AND project_name IN (*projectNames*/'project1')/*END*/
92
+ /*IF projectNames != null && projectNames.length*/AND project_name IN (/*projectNames*/'project1')/*END*/
93
93
  /*IF statuses != null && statuses.length*/AND status IN (/*statuses*/1)/*END*/
94
94
  /*END*/
95
95
  ORDER BY started_at DESC
@@ -151,7 +151,75 @@ ORDER BY started_at DESC
151
151
  LIMIT 100
152
152
  ```
153
153
 
154
- ##### Example 2: FOR Loop
154
+ ##### Example 2: Dynamic WHERE Clause with `ELSEIF/ELSE`
155
+
156
+ **Template:**
157
+
158
+ ```sql
159
+ SELECT
160
+ *
161
+ FROM users
162
+ WHERE
163
+ 1 = 1
164
+ /*IF role === 'admin'*/
165
+ AND access_level = 99
166
+ /*ELSEIF role === 'editor'*/
167
+ AND access_level = 50
168
+ /*ELSE*/
169
+ AND access_level = 1
170
+ /*END*/
171
+ ```
172
+
173
+ **Code:**
174
+
175
+ ```typescript
176
+ import { SQLBuilder } from '@digitalwalletcorp/sql-builder';
177
+
178
+ const builder = new SQLBuilder();
179
+
180
+ const template = `...`; // The SQL template from above
181
+
182
+ const bindEntity1 = {
183
+ role: 'editor'
184
+ };
185
+
186
+ // SCENARIO A: Matched with ELSEIF condition
187
+ const sql = builder.generateSQL(template, bindEntity1);
188
+ console.log(sql1);
189
+
190
+ // SCENARIO B: Matched with ELSE condition
191
+ const bindEntity2 = {
192
+ role: 'read'
193
+ };
194
+ const sql2 = builder.generateSQL(template, bindEntity2);
195
+ console.log(sql2);
196
+ ```
197
+
198
+ **Resulting SQL:**
199
+
200
+ * SQL 1 (Scenario A)
201
+
202
+ ```sql
203
+ SELECT
204
+ *
205
+ FROM users
206
+ WHERE
207
+ 1 = 1
208
+ AND access_level = 50
209
+ ```
210
+
211
+ * SQL 2 (Scenario B)
212
+
213
+ ```sql
214
+ SELECT
215
+ *
216
+ FROM users
217
+ WHERE
218
+ 1 = 1
219
+ AND access_level = 1
220
+ ```
221
+
222
+ ##### Example 3: FOR Loop
155
223
 
156
224
  Use a `/*FOR...*/` block to iterate over an array and generate SQL for each item. This is useful for building multiple `LIKE` conditions.
157
225
 
@@ -231,7 +299,8 @@ If you need to use database-specific features, use `generateParameterizedSQL` wi
231
299
 
232
300
  ##### `generateParameterizedSQL(template: string, entity: Record<string, any>, bindType?: 'postgres' | 'mysql' | 'oracle' | 'mssql'): [string, Array<any> | Record<string, any>]`
233
301
 
234
- Generates a SQL string with placeholders for prepared statements and returns an array of bind parameters. This method is crucial for preventing SQL injection.
302
+ Generates a SQL string with placeholders for prepared statements and returns bind parameters.
303
+ This method prevents SQL injection for value bindings by using parameterized queries.
235
304
 
236
305
  * `template`: The SQL template string containing S2Dao-style comments.
237
306
  * `entity`: A data object whose properties are used for evaluating conditions (`/*IF...*/`) and binding values.
@@ -241,7 +310,7 @@ Generates a SQL string with placeholders for prepared statements and returns an
241
310
  * `sql`: The generated SQL query with appropriate placeholders.
242
311
  * `bindParams`: An array of values (for PostgreSQL/MySQL) or an object of named values (for Oracle/SQL Server) to bind to the placeholders.
243
312
 
244
- ##### Example 3: Parameterized SQL with PostgreSQL
313
+ ##### Example 4: Parameterized SQL with PostgreSQL
245
314
 
246
315
  **Template:**
247
316
 
@@ -277,7 +346,7 @@ console.log('Parameters:', params);
277
346
 
278
347
  **Resulting SQL & Parameters:**
279
348
 
280
- ```
349
+ ```sql
281
350
  SQL:
282
351
  SELECT
283
352
  id,
@@ -292,31 +361,7 @@ Parameters:
292
361
  [ 123, 'project_a', 'project_b' ]
293
362
  ```
294
363
 
295
- ###### ⚠️ PostgreSQL-specific notes
296
-
297
- When using PostgreSQL-specific features such as `ANY` with array parameters,
298
- the SQL template must be written in a form that is valid PostgreSQL SQL by itself.
299
-
300
- For example, to use `ANY` with a text array, write the array literal directly in the template.
301
- The builder will replace the **entire array literal** with a single bind placeholder:
302
-
303
- ```sql
304
- AND user_id = ANY (/*userIds*/ARRAY['U100','U101']::text[])
305
- ```
306
-
307
- This will be rendered as:
308
-
309
- ```sql
310
- AND user_id = ANY ($1::text[])
311
- ```
312
-
313
- with the following bind parameters:
314
-
315
- ```typescript
316
- [ ['U100', 'U101'] ]
317
- ```
318
-
319
- ##### Example 4: INSERT with NULL normalization
364
+ ##### Example 5: INSERT with NULL normalization
320
365
 
321
366
  **Template:**
322
367
 
@@ -369,7 +414,7 @@ console.log('Parameters2:', params2);
369
414
 
370
415
  **Result:**
371
416
 
372
- ```text
417
+ ```sql
373
418
  SQL1:
374
419
  INSERT INTO users (
375
420
  user_id,
@@ -402,10 +447,8 @@ Parameters2:
402
447
 
403
448
  **Notes:**
404
449
 
405
- - For both `generateSQL` and `generateParameterizedSQL`,
406
- `undefined` and `null` values are normalized to SQL `NULL`.
407
- - This behavior is especially important for INSERT / UPDATE statements,
408
- where the number of columns and values must always match.
450
+ - For both `generateSQL` and `generateParameterizedSQL`, `undefined` and `null` values are normalized to SQL `NULL`.
451
+ - This behavior is especially important for INSERT / UPDATE statements, where the number of columns and values must always match.
409
452
  - NOT NULL constraint violations are intentionally left to the database.
410
453
  - If you need to handle `IS NULL` conditions explicitly, you can use `/*IF */` blocks as shown below:
411
454
 
@@ -426,9 +469,11 @@ WHERE
426
469
  | Tag | Syntax | Description |
427
470
  | --- | --- | --- |
428
471
  | IF | `/*IF condition*/ ... /*END*/` | Includes the enclosed SQL fragment only if the `condition` evaluates to a truthy value. The condition is a JavaScript expression evaluated against the `entity` object. |
429
- | BEGIN | `/*BEGIN*/ ... /*END*/` | A wrapper block, typically for a `WHERE` clause. The entire block is included only if at least one `/*IF...*/` statement inside it is evaluated as true. This intelligently removes the `WHERE` keyword if no filters apply. |
472
+ | ELSEIF | `/*ELSEIF condition*/ ...` | Evaluates only if the preceding `IF` or `ELSEIF` was false. Must be placed inside an `IF` block. |
473
+ | ELSE | `/*ELSE*/ ...` | Included if all preceding `IF` and `ELSEIF` conditions in the block were false. |
474
+ | BEGIN | `/*BEGIN*/ ... /*END*/` | A wrapper block, typically for a `WHERE` clause. The entire block is included only if at least one inner `IF/ELSEIF/ELSE` or `FOR` block is active. This intelligently removes the `WHERE` keyword if no filters apply. |
430
475
  | FOR | `/*FOR item:collection*/ ... /*END*/` | Iterates over the `collection` array from the `entity`. For each loop, the enclosed SQL is generated, and the current value is available as the `item` variable for binding. |
431
- | Bind Variable | `/*variable*/` | Binds a value from the `entity`. It automatically formats values: strings are quoted (`'value'`), numbers are left as is (`123`), and arrays are turned into comma-separated lists in parentheses (`('a','b',123)`). |
476
+ | Bind Variable | `/*variable*/` | Binds a value from the `entity`. Strings are quoted `'value'`, numbers are rendered as-is `123`. When the value is an array, elements are expanded into a comma-separated list. The template may contain zero or one dummy expression after a bind tag. If present, only a single SQL expression is allowed. Multiple comma-separated dummy values are not supported. |
432
477
  | END | `/*END*/` | Marks the end of an `IF`, `BEGIN`, or `FOR` block. |
433
478
 
434
479
  ---
@@ -474,16 +519,105 @@ The `condition` inside an `/*IF ...*/` tag is evaluated as a JavaScript expressi
474
519
 
475
520
  ---
476
521
 
477
- ### 📜 License
522
+ #### Vendor Dependency TIPS
478
523
 
479
- This project is licensed under the MIT License. See the [LICENSE](https://opensource.org/licenses/MIT) file for details.
524
+ **PostgreSQL**
480
525
 
481
- ### 🎓 Advanced Usage & Examples
526
+ When using PostgreSQL-specific features such as `ANY` with array parameters,
527
+ the SQL template must be written in a form that is valid PostgreSQL SQL by itself.
528
+
529
+ For example, to use `ANY` with a text array, write the array literal directly in the template.
530
+ The builder will replace the **entire array literal** with a single bind placeholder:
482
531
 
483
- This README covers the basic usage of the library. For more advanced use cases and a comprehensive look at how to verify its behavior, the test suite serves as practical and up-to-date documentation.
532
+ ```sql
533
+ AND user_id = ANY (/*userIds*/ARRAY['U100','U101']::text[])
534
+ ```
484
535
 
485
- We recommend Browse the test files to understand how to handle and verify the sequential, race-condition-free execution in various scenarios.
536
+ This will be rendered as:
537
+
538
+ ```sql
539
+ AND user_id = ANY ($1::text[])
540
+ ```
541
+
542
+ with the following bind parameters:
543
+
544
+ ```typescript
545
+ [ ['U100', 'U101'] ]
546
+ ```
547
+
548
+ **MSSQL**
549
+
550
+ When working with a large number of values for an IN condition in SQL Server, directly expanding them into:
551
+
552
+ ```sql
553
+ WHERE UserID IN (1, 2, 3, ..., N)
554
+ ```
486
555
 
487
- You can find the test case in the `/test/specs` directory of our GitHub repository.
556
+ may lead to:
488
557
 
489
- - **[Explore our Test Suite for Advanced Examples](https://github.com/digitalwalletcorp/sql-builder/tree/main/test/specs)**
558
+ * **No Parameter Limits:** Counts as only 1 parameter regardless of array size.
559
+ * **Better Performance:** Avoids the overhead of parsing thousands of individual parameters.
560
+ * **Type Safety:** `OPENJSON` allows explicit type mapping (e.g., `INT`, `UNIQUEIDENTIFIER`).
561
+
562
+ SQL Server has a maximum limit of 2,100 parameters per RPC request. When using large IN (...) clauses via drivers like `Tedious`, each item in the list is typically treated as a separate parameter.
563
+
564
+ **Template:**
565
+
566
+ ```sql
567
+ DECLARE @jsonUserIds NVARCHAR(MAX) = N'[/*userIds*/100]';
568
+
569
+ WITH T AS (
570
+ SELECT value AS UserID
571
+ FROM OPENJSON(@jsonUserIds)
572
+ )
573
+ SELECT
574
+ U.UserID,
575
+ U.Status,
576
+ U.CreatedAt,
577
+ U.UpdatedAt
578
+ FROM Users U
579
+ JOIN T
580
+ ON U.UserID = T.UserID
581
+ ```
582
+
583
+ **Code:**
584
+
585
+ ```typescript
586
+ const template = '...'; // above SQL
587
+ const builder = new SQLBuilder();
588
+ const [sql, params] = builder.generateParameterizedSQL(template, { userIds: [100, 101, 102, 103] }, 'mssql');
589
+ console.log(sql, params);
590
+ ```
591
+
592
+ **Result:**
593
+
594
+ ```sql
595
+ SQL:
596
+ DECLARE @jsonUserIds NVARCHAR(MAX) = @userIds;
597
+
598
+ WITH T AS (
599
+ SELECT value AS UserID
600
+ FROM OPENJSON(@jsonUserIds)
601
+ )
602
+ SELECT
603
+ U.UserID,
604
+ U.Status,
605
+ U.CreatedAt,
606
+ U.UpdatedAt
607
+ FROM Users U
608
+ JOIN T
609
+ ON U.UserID = T.UserID
610
+
611
+ Parameters:
612
+ {
613
+ userIds: '[100,101,102,103]'
614
+ }
615
+ ```
616
+
617
+ By passing the array as a single JSON parameter and expanding it with OPENJSON, you can avoid large IN (...) lists and handle arbitrarily large collections in a clean and scalable way.
618
+
619
+ ---
620
+
621
+ #### 📜 License
622
+
623
+ This project is licensed under the MIT License. See the [LICENSE](https://opensource.org/licenses/MIT) file for details.
@@ -31,7 +31,7 @@ export declare class AbstractSyntaxTree {
31
31
  /**
32
32
  * 与えられた条件文字列を構文解析し、entityに対する条件として成立するか評価する
33
33
  *
34
- * @param {string} condition "params != null && params.length > 10" のような条件
34
+ * @param {string} condition 'params != null && params.length > 10' のような条件
35
35
  * @param {Record<string, any>} entity
36
36
  * @returns {boolean}
37
37
  */
@@ -57,7 +57,7 @@ class AbstractSyntaxTree {
57
57
  /**
58
58
  * 与えられた条件文字列を構文解析し、entityに対する条件として成立するか評価する
59
59
  *
60
- * @param {string} condition "params != null && params.length > 10" のような条件
60
+ * @param {string} condition 'params != null && params.length > 10' のような条件
61
61
  * @param {Record<string, any>} entity
62
62
  * @returns {boolean}
63
63
  */
@@ -69,9 +69,8 @@ class AbstractSyntaxTree {
69
69
  return result;
70
70
  }
71
71
  catch (error) {
72
- error.condition = condition;
73
- error.entity = entity;
74
- throw error;
72
+ const enhancedMessage = `[SQLBuilder] Failed to evaluate IF condition: '/*IF ${condition}*/'. ${error.message}`;
73
+ throw new Error(enhancedMessage);
75
74
  }
76
75
  }
77
76
  /**
@@ -252,7 +251,8 @@ class AbstractSyntaxTree {
252
251
  output.push(op);
253
252
  }
254
253
  if (!foundLeftParen) {
255
- throw new Error('[SQLBuilder.AbstractSyntaxTree] Mismatched parentheses');
254
+ throw new Error(`[SQLBuilder.AST] Mismatched parentheses: Found closing ')' without a matching '('. Check your IF condition syntax.`);
255
+ ;
256
256
  }
257
257
  }
258
258
  break;
@@ -262,7 +262,7 @@ class AbstractSyntaxTree {
262
262
  while (operatorStack.length) {
263
263
  const op = operatorStack.pop();
264
264
  if (op.value === '(' || op.value === ')') {
265
- throw new Error('[SQLBuilder.AbstractSyntaxTree] Mismatched parentheses');
265
+ throw new Error(`[SQLBuilder.AST] Mismatched parentheses: An extra '${op.value}' was found or a matching '(' is missing.`);
266
266
  }
267
267
  output.push(op);
268
268
  }
@@ -1 +1 @@
1
- {"version":3,"file":"abstract-syntax-tree.js","sourceRoot":"","sources":["../src/abstract-syntax-tree.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAYnC,8BAA8B;AAC9B,MAAM,UAAU,GAKZ;IACF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C;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,uDAAuD,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACtG,CAAC;QACD,0CAA0C;QAC1C,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;CACF;AA1RD,gDA0RC"}
package/lib/common.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ type PropertyResult = {
2
+ exists: boolean;
3
+ value: any;
4
+ };
1
5
  /**
2
6
  * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値を取得する
3
7
  *
@@ -6,3 +10,20 @@
6
10
  * @returns {any}
7
11
  */
8
12
  export declare function getProperty(entity: Record<string, any>, property: string): any;
13
+ /**
14
+ * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値が存在するかチェックする
15
+ *
16
+ * @param {Record<string, any>} entity
17
+ * @param {string} property
18
+ * @returns {boolean}
19
+ */
20
+ export declare function hasProperty(entity: Record<string, any>, property: string): boolean;
21
+ /**
22
+ * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値を取得する
23
+ *
24
+ * @param {Record<string, any>} entity
25
+ * @param {string} property
26
+ * @returns {PropertyResult}
27
+ */
28
+ export declare function getPropertyResult(entity: Record<string, any>, property: string): PropertyResult;
29
+ export {};
package/lib/common.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getProperty = getProperty;
4
+ exports.hasProperty = hasProperty;
5
+ exports.getPropertyResult = getPropertyResult;
4
6
  /**
5
7
  * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値を取得する
6
8
  *
@@ -9,16 +11,42 @@ exports.getProperty = getProperty;
9
11
  * @returns {any}
10
12
  */
11
13
  function getProperty(entity, property) {
14
+ return getPropertyResult(entity, property).value;
15
+ }
16
+ /**
17
+ * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値が存在するかチェックする
18
+ *
19
+ * @param {Record<string, any>} entity
20
+ * @param {string} property
21
+ * @returns {boolean}
22
+ */
23
+ function hasProperty(entity, property) {
24
+ return getPropertyResult(entity, property).exists;
25
+ }
26
+ /**
27
+ * entityで指定したオブジェクトからドットで連結されたプロパティキーに該当する値を取得する
28
+ *
29
+ * @param {Record<string, any>} entity
30
+ * @param {string} property
31
+ * @returns {PropertyResult}
32
+ */
33
+ function getPropertyResult(entity, property) {
12
34
  // `?.` または `.` でパスを分割
13
35
  const propertyPath = property.split(/(\?\.)|\./).filter(Boolean);
14
36
  // 再帰呼び出し用のヘルパー関数
15
37
  const get = (obj, keys) => {
16
38
  if (keys.length === 0) {
17
- return obj;
39
+ return {
40
+ exists: true,
41
+ value: obj
42
+ };
18
43
  }
19
44
  // オプショナルチェイニングのチェック
20
45
  if (obj == null) {
21
- return undefined;
46
+ return {
47
+ exists: false,
48
+ value: undefined
49
+ };
22
50
  }
23
51
  const currentKey = keys[0];
24
52
  const remainingKeys = keys.slice(1);
@@ -27,8 +55,11 @@ function getProperty(entity, property) {
27
55
  return get(obj, remainingKeys);
28
56
  }
29
57
  // プロパティが存在しない場合は undefined を返す
30
- if (!obj.hasOwnProperty(currentKey)) {
31
- return undefined;
58
+ if (!Object.prototype.hasOwnProperty.call(obj, currentKey)) {
59
+ return {
60
+ exists: false,
61
+ value: undefined
62
+ };
32
63
  }
33
64
  return get(obj[currentKey], remainingKeys);
34
65
  };
package/lib/common.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;AAOA,kCA4BC;AAnCD;;;;;;GAMG;AACH,SAAgB,WAAW,CAAC,MAA2B,EAAE,QAAgB;IACvE,sBAAsB;IACtB,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjE,iBAAiB;IACj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MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEjE,iBAAiB;IACjB,MAAM,GAAG,GAAG,CAAC,GAAwB,EAAE,IAAc,EAAO,EAAE;QAC5D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,KAAK,EAAE,GAAG;aACO,CAAC;QACtB,CAAC;QACD,oBAAoB;QACpB,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,SAAS;aACC,CAAC;QACtB,CAAC;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAEpC,kBAAkB;QAClB,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,GAAG,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;QACjC,CAAC;QACD,+BAA+B;QAC/B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;YAC3D,OAAO;gBACL,MAAM,EAAE,KAAK;gBACb,KAAK,EAAE,SAAS;aACC,CAAC;QACtB,CAAC;QACD,OAAO,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC;IACF,OAAO,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AACnC,CAAC"}
@@ -90,7 +90,7 @@ export declare class SQLBuilder {
90
90
  * @param {SharedIndex} pos 現在処理している文字列の先頭インデックス
91
91
  * @param {string} template
92
92
  * @param {Record<string, any>} entity
93
- * @param {TagContext[]} tagContexts
93
+ * @param {(TagContext | ParentTagContext)[]} tagContexts
94
94
  * @param {*} [options]
95
95
  * ├ bindType BindType
96
96
  * ├ bindIndex number
@@ -98,6 +98,26 @@ export declare class SQLBuilder {
98
98
  * @returns {string}
99
99
  */
100
100
  private parse;
101
+ /**
102
+ * 指定したタグから親を遡り、指定したタグタイプのタグコンテキストを返す
103
+ * 見つからない場合はundefinedを返す
104
+ *
105
+ * @param {TagContext | ParentTagContext | null} tagContext
106
+ * @param {T} tagType
107
+ * @returns {(TagContext & { type: T }) | undefined}
108
+ */
109
+ private findParentTagContext;
110
+ /**
111
+ * 指定したタグの兄弟をたどり、指定したタグタイプのタグコンテキストを返す
112
+ * 見つからない場合はundefinedを返す
113
+ * ユースケースとしては、ELSEIF/ELSEから同じIFに属するENDを探す
114
+ *
115
+ * @param {TagContext} tagContext
116
+ * @param {TagType | TagType[]} tagType
117
+ * @param {'previous' | 'next'} direction
118
+ * @returns {TagContext | undefined}
119
+ */
120
+ private seekSiblingTagContext;
101
121
  /**
102
122
  * ダミーパラメータの終了インデックスを返す
103
123
  *