rawsql-ts 0.1.0-beta.8 → 0.1.1-beta.1

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.
Files changed (121) hide show
  1. package/README.md +231 -173
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.js +2 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/models/BinarySelectQuery.js +9 -8
  6. package/dist/models/BinarySelectQuery.js.map +1 -1
  7. package/dist/models/SimpleSelectQuery.js +10 -8
  8. package/dist/models/SimpleSelectQuery.js.map +1 -1
  9. package/dist/parsers/CommandExpressionParser.d.ts +1 -1
  10. package/dist/parsers/CommandExpressionParser.js +6 -6
  11. package/dist/parsers/CommandExpressionParser.js.map +1 -1
  12. package/dist/parsers/CommonTableParser.d.ts +2 -2
  13. package/dist/parsers/CommonTableParser.js +7 -5
  14. package/dist/parsers/CommonTableParser.js.map +1 -1
  15. package/dist/parsers/ForClauseParser.d.ts +2 -2
  16. package/dist/parsers/ForClauseParser.js +5 -3
  17. package/dist/parsers/ForClauseParser.js.map +1 -1
  18. package/dist/parsers/FromClauseParser.d.ts +2 -2
  19. package/dist/parsers/FromClauseParser.js +6 -4
  20. package/dist/parsers/FromClauseParser.js.map +1 -1
  21. package/dist/parsers/FunctionExpressionParser.d.ts +1 -1
  22. package/dist/parsers/FunctionExpressionParser.js +8 -8
  23. package/dist/parsers/FunctionExpressionParser.js.map +1 -1
  24. package/dist/parsers/GroupByParser.d.ts +2 -2
  25. package/dist/parsers/GroupByParser.js +6 -4
  26. package/dist/parsers/GroupByParser.js.map +1 -1
  27. package/dist/parsers/HavingParser.d.ts +2 -2
  28. package/dist/parsers/HavingParser.js +6 -4
  29. package/dist/parsers/HavingParser.js.map +1 -1
  30. package/dist/parsers/IdentifierParser.d.ts +1 -1
  31. package/dist/parsers/IdentifierParser.js +1 -1
  32. package/dist/parsers/IdentifierParser.js.map +1 -1
  33. package/dist/parsers/JoinClauseParser.js +2 -2
  34. package/dist/parsers/JoinClauseParser.js.map +1 -1
  35. package/dist/parsers/LimitClauseParser.d.ts +2 -2
  36. package/dist/parsers/LimitClauseParser.js +7 -5
  37. package/dist/parsers/LimitClauseParser.js.map +1 -1
  38. package/dist/parsers/LiteralParser.d.ts +1 -1
  39. package/dist/parsers/LiteralParser.js +1 -1
  40. package/dist/parsers/LiteralParser.js.map +1 -1
  41. package/dist/parsers/OrderByClauseParser.d.ts +2 -2
  42. package/dist/parsers/OrderByClauseParser.js +6 -4
  43. package/dist/parsers/OrderByClauseParser.js.map +1 -1
  44. package/dist/parsers/OverExpressionParser.d.ts +2 -2
  45. package/dist/parsers/OverExpressionParser.js +4 -4
  46. package/dist/parsers/OverExpressionParser.js.map +1 -1
  47. package/dist/parsers/ParameterExpressionParser.d.ts +1 -1
  48. package/dist/parsers/ParameterExpressionParser.js +1 -1
  49. package/dist/parsers/ParameterExpressionParser.js.map +1 -1
  50. package/dist/parsers/ParenExpressionParser.d.ts +1 -1
  51. package/dist/parsers/ParenExpressionParser.js +2 -2
  52. package/dist/parsers/ParenExpressionParser.js.map +1 -1
  53. package/dist/parsers/PartitionByParser.d.ts +2 -2
  54. package/dist/parsers/PartitionByParser.js +7 -5
  55. package/dist/parsers/PartitionByParser.js.map +1 -1
  56. package/dist/parsers/SelectClauseParser.d.ts +2 -2
  57. package/dist/parsers/SelectClauseParser.js +6 -4
  58. package/dist/parsers/SelectClauseParser.js.map +1 -1
  59. package/dist/parsers/SelectQueryParser.d.ts +2 -2
  60. package/dist/parsers/SelectQueryParser.js +16 -14
  61. package/dist/parsers/SelectQueryParser.js.map +1 -1
  62. package/dist/parsers/SourceAliasExpressionParser.d.ts +1 -1
  63. package/dist/parsers/SourceAliasExpressionParser.js +2 -1
  64. package/dist/parsers/SourceAliasExpressionParser.js.map +1 -1
  65. package/dist/parsers/SourceExpressionParser.d.ts +1 -1
  66. package/dist/parsers/SourceExpressionParser.js +5 -4
  67. package/dist/parsers/SourceExpressionParser.js.map +1 -1
  68. package/dist/parsers/SourceParser.d.ts +2 -2
  69. package/dist/parsers/SourceParser.js +9 -6
  70. package/dist/parsers/SourceParser.js.map +1 -1
  71. package/dist/parsers/StringSpecifierExpressionParser.d.ts +1 -1
  72. package/dist/parsers/StringSpecifierExpressionParser.js +1 -1
  73. package/dist/parsers/StringSpecifierExpressionParser.js.map +1 -1
  74. package/dist/parsers/UnaryExpressionParser.d.ts +1 -1
  75. package/dist/parsers/UnaryExpressionParser.js +2 -2
  76. package/dist/parsers/UnaryExpressionParser.js.map +1 -1
  77. package/dist/parsers/ValueParser.d.ts +2 -2
  78. package/dist/parsers/ValueParser.js +15 -13
  79. package/dist/parsers/ValueParser.js.map +1 -1
  80. package/dist/parsers/ValuesQueryParser.d.ts +2 -2
  81. package/dist/parsers/ValuesQueryParser.js +5 -5
  82. package/dist/parsers/ValuesQueryParser.js.map +1 -1
  83. package/dist/parsers/WhereClauseParser.d.ts +2 -2
  84. package/dist/parsers/WhereClauseParser.js +6 -4
  85. package/dist/parsers/WhereClauseParser.js.map +1 -1
  86. package/dist/parsers/WindowClauseParser.d.ts +2 -2
  87. package/dist/parsers/WindowClauseParser.js +6 -4
  88. package/dist/parsers/WindowClauseParser.js.map +1 -1
  89. package/dist/parsers/WindowExpressionParser.d.ts +2 -2
  90. package/dist/parsers/WindowExpressionParser.js +29 -17
  91. package/dist/parsers/WindowExpressionParser.js.map +1 -1
  92. package/dist/parsers/WithClauseParser.d.ts +2 -2
  93. package/dist/parsers/WithClauseParser.js +7 -5
  94. package/dist/parsers/WithClauseParser.js.map +1 -1
  95. package/dist/transformers/CTEBuilder.js +1 -1
  96. package/dist/transformers/CTEBuilder.js.map +1 -1
  97. package/dist/transformers/CTECollector.d.ts +2 -1
  98. package/dist/transformers/CTECollector.js +5 -1
  99. package/dist/transformers/CTECollector.js.map +1 -1
  100. package/dist/transformers/CTEDisabler.js +1 -1
  101. package/dist/transformers/CTEDisabler.js.map +1 -1
  102. package/dist/transformers/CTENormalizer.d.ts +5 -5
  103. package/dist/transformers/CTENormalizer.js +11 -7
  104. package/dist/transformers/CTENormalizer.js.map +1 -1
  105. package/dist/transformers/Formatter.d.ts +16 -1
  106. package/dist/transformers/Formatter.js +17 -2
  107. package/dist/transformers/Formatter.js.map +1 -1
  108. package/dist/transformers/QueryConverter.d.ts +41 -0
  109. package/dist/transformers/{QueryNormalizer.js → QueryConverter.js} +39 -34
  110. package/dist/transformers/QueryConverter.js.map +1 -0
  111. package/dist/transformers/SelectValueCollector.d.ts +2 -4
  112. package/dist/transformers/SelectValueCollector.js.map +1 -1
  113. package/dist/transformers/SelectableColumnCollector.d.ts +2 -0
  114. package/dist/transformers/SelectableColumnCollector.js +17 -3
  115. package/dist/transformers/SelectableColumnCollector.js.map +1 -1
  116. package/dist/transformers/TableColumnResolver.d.ts +10 -0
  117. package/dist/transformers/TableColumnResolver.js +3 -0
  118. package/dist/transformers/TableColumnResolver.js.map +1 -0
  119. package/package.json +15 -2
  120. package/dist/transformers/QueryNormalizer.d.ts +0 -37
  121. package/dist/transformers/QueryNormalizer.js.map +0 -1
package/README.md CHANGED
@@ -1,179 +1,262 @@
1
1
  # rawsql-ts
2
2
 
3
- rawsql-ts is a TypeScript SQL parser that performs Abstract Syntax Tree (AST) analysis for advanced SQL processing and transformation.
3
+ ![No external dependencies](https://img.shields.io/badge/dependencies-none-brightgreen)
4
+ ![Browser Support](https://img.shields.io/badge/browser-%F0%9F%9A%80-brightgreen)
5
+ ![npm version](https://img.shields.io/npm/v/rawsql-ts)
6
+ ![npm downloads](https://img.shields.io/npm/dm/rawsql-ts)
7
+ ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
4
8
 
5
- > **Note:** This library is currently in beta. The API may change without notice until the v1.0 release.
9
+ rawsql-ts is a high-performance SQL parser and AST transformer library written in TypeScript. It is designed for extensibility and advanced SQL analysis, with initial focus on PostgreSQL syntax but not limited to it. The library enables easy SQL parsing, transformation, and analysis for a wide range of SQL dialects.
6
10
 
7
- ## Installation
11
+ > **Note:** This library is currently in beta. The API may change until the v1.0 release.
8
12
 
9
- Install the package from npm as follows:
13
+ ---
10
14
 
11
- ```bash
12
- npm install rawsql-ts
13
- ```
15
+ 💡 **Key Advantages**
14
16
 
15
- ## Usage
17
+ With rawsql-ts, raw SQL can be represented as objects, enabling flexible manipulation of SQL statements directly within your program. Objectified SQL can be partially transformed, decomposed into manageable components, and recombined as needed. This approach dramatically improves the maintainability and reusability of complex SQL, making even large-scale queries easy to manage and refactor.
16
18
 
17
- Basic usage example:
19
+ ---
18
20
 
19
- ```typescript
20
- import { SelectQueryParser } from 'rawsql-ts';
21
- import { Formatter } from 'rawsql-ts';
21
+ ## Features
22
22
 
23
- const sql = `SELECT id, name FROM users WHERE active = TRUE`;
24
- const query = SelectQueryParser.parseFromText(sql);
25
- const formatter = new Formatter();
26
- const formattedSql = formatter.visit(query);
27
- console.log(formattedSql);
28
- // => select "id", "name" from "users" where "active" = true
29
- ```
23
+ - Zero dependencies: fully self-contained and lightweight
24
+ - High-speed SQL parsing and AST analysis
25
+ - Rich utilities for SQL structure transformation and analysis
30
26
 
31
- ---
27
+ ## ✨ Browser & CDN Ready!
32
28
 
33
- ## 🧩 Parsing Features
29
+ You can use rawsql-ts directly in modern browsers via CDN (unpkg/jsdelivr)!
30
+ No Node.js dependencies, no build tools required.
31
+ Just import it like this:
34
32
 
35
- rawsql-ts provides the following main parser class for converting SQL text into an Abstract Syntax Tree (AST):
33
+ ```html
34
+ <!-- Always get the latest version -->
35
+ <script type="module">
36
+ import { parse } from "https://unpkg.com/rawsql-ts/dist/esm/index.js";
37
+ </script>
38
+ ```
36
39
 
37
- - **SelectQueryParser**
38
- Parses complete SELECT and VALUES queries, including support for CTEs (WITH), UNION/INTERSECT/EXCEPT, subqueries, and all major SQL clauses. Handles PostgreSQL-specific syntax and advanced query structures.
39
-
40
- **Key methods:**
41
- - `parseFromText(sql: string): SelectQuery`
42
- Parses a SQL string and returns the root AST node for the query. Throws an error if the SQL is invalid or contains extra tokens.
43
- - `parse(lexemes: Lexeme[], index: number): { value: SelectQuery; newIndex: number }`
44
- Parses a tokenized SQL query from the given index and returns the AST node and the new index. Used internally for advanced parsing scenarios.
45
-
46
- **Notes:**
47
- - Only PostgreSQL syntax is supported at this time.
48
- - Only SELECT and VALUES queries are supported (INSERT/UPDATE/DELETE are not yet implemented).
49
- - All SQL comments are removed during parsing.
50
-
51
- This class is designed to handle all practical SQL parsing needs for SELECT/VALUES queries in PostgreSQL, including:
52
- - CTEs (WITH), including recursive and materialized options
53
- - UNION, INTERSECT, EXCEPT, and subqueries
54
- - Window functions and analytic clauses
55
- - Complex expressions, functions, and operators
56
- - Robust error handling with detailed messages
57
- - Accurate tokenization, including comments and special literals
40
+ ```html
41
+ <!-- Pin a specific version for stability -->
42
+ <script type="module">
43
+ import { parse } from "https://unpkg.com/rawsql-ts@0.1.0-beta.12/dist/esm/index.js";
44
+ </script>
45
+ ```
58
46
 
59
47
  ---
60
48
 
61
- ## Core SQL Query Classes
49
+ ## Installation
62
50
 
63
- The following classes are the primary building blocks for representing and manipulating SQL queries in rawsql-ts:
51
+ ```bash
52
+ npm install rawsql-ts
53
+ ```
64
54
 
65
- ### SimpleSelectQuery
55
+ ## Quick Start
66
56
 
67
- Represents a single, standard SQL SELECT statement (not a UNION or VALUES). This class encapsulates all major clauses such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and more.
57
+ ```typescript
58
+ import { SelectQueryParser, Formatter } from 'rawsql-ts';
68
59
 
69
- **Key methods:**
70
- - `toUnion`, `toUnionAll`, `toIntersect`, `toExcept`, etc.
71
- - Combine this query with another using UNION, INTERSECT, EXCEPT, etc., returning a BinarySelectQuery.
72
- - `appendWhere`, `appendWhereRaw`
73
- - Add a new condition to the WHERE clause (as AST or raw SQL string).
74
- - `appendHaving`, `appendHavingRaw`
75
- - Add a new condition to the HAVING clause.
76
- - `innerJoin`, `leftJoin`, `rightJoin`, `innerJoinRaw`, etc.
77
- - Add JOIN clauses to the query, either as AST or from raw SQL.
78
- - `toSource`
79
- - Wrap this query as a subquery (for use in FROM/JOIN, etc.).
80
- - `appendWith`, `appendWithRaw`
81
- - Add CTEs (WITH clause) to the query.
60
+ const sql = `SELECT user_id, name FROM users WHERE active = TRUE`;
61
+ const query = SelectQueryParser.parse(sql);
62
+ const formatter = new Formatter();
63
+ const formattedSql = formatter.format(query);
82
64
 
83
- ### BinarySelectQuery
65
+ console.log(formattedSql);
66
+ // => select "user_id", "name" from "users" where "active" = true
67
+ ```
84
68
 
85
- Represents a binary SQL query, such as `SELECT ... UNION SELECT ...`, `INTERSECT`, or `EXCEPT`. This class holds a left and right query and the operator between them.
69
+ ---
86
70
 
87
- **Key methods:**
88
- - `union`, `unionAll`, `intersect`, `intersectAll`, `except`, `exceptAll`
89
- - Chain additional queries to the current binary query.
90
- - `appendSelectQuery`
91
- - Add a new query with a custom operator.
92
- - `toSource`
93
- - Wrap this binary query as a subquery (for use in FROM/JOIN, etc.).
94
- - `unionRaw`, `intersectRaw`, etc.
95
- - Add a new query by parsing a raw SQL string and combining it.
71
+ ## Main Parser Features
96
72
 
97
- ### ValuesQuery
73
+ - **SelectQueryParser**
74
+ The main class for converting SELECT and VALUES statements into AST. Fully supports CTEs (WITH), UNION/INTERSECT/EXCEPT, subqueries, and PostgreSQL-specific syntax.
75
+ - `parse(sql: string): SelectQuery`
76
+ Converts a SQL string to an AST. Throws an exception on error.
77
+ - Supports only PostgreSQL syntax
78
+ - Only SELECT and VALUES are supported (INSERT/UPDATE/DELETE are not yet implemented)
79
+ - SQL comments are automatically removed
80
+ - Handles CTEs (WITH), UNION/INTERSECT/EXCEPT, subqueries, window functions, complex expressions, and functions
81
+ - Provides detailed error messages
82
+ - Highly accurate tokenization
98
83
 
99
- Represents a SQL `VALUES` clause, such as `VALUES (1, 'a'), (2, 'b')`, which is used for inline data tables.
84
+ ---
100
85
 
101
- **Key methods:**
102
- - (Primarily the constructor and tuple access)
103
- - This class can be used as a subquery source or wrapped with QueryNormalizer to convert it into a standard SELECT query.
86
+ ## Core SQL Query Classes
104
87
 
105
- ---
88
+ - **SimpleSelectQuery**
89
+ Represents a standard SELECT statement. Supports all major clauses such as WHERE, GROUP BY, JOIN, and CTE.
90
+ - `toUnion`, `toUnionAll`, ... for UNION operations
91
+ - `appendWhere`, `appendWhereRaw` to add WHERE conditions
92
+ - `innerJoin`, `leftJoin`, ... to add JOINs
93
+ - `toSource` to wrap as a subquery
94
+ - `appendWith`, `appendWithRaw` to add CTEs
106
95
 
107
- These classes are designed to be flexible and allow for robust construction, combination, and transformation of SQL queries. For further details, please refer to the source code.
96
+ - **BinarySelectQuery**
97
+ Represents binary SQL queries such as UNION, INTERSECT, and EXCEPT.
98
+ - `union`, `intersect`, ... to combine queries
99
+ - `toSource` to wrap as a subquery
100
+ - `unionRaw`, ... to combine with raw SQL
101
+
102
+ - **ValuesQuery**
103
+ For inline tables like `VALUES (1, 'a'), (2, 'b')`.
104
+ - Can be used as a subquery or converted to SELECT with QueryNormalizer
108
105
 
109
106
  ---
110
107
 
111
- ## 🛠️ Transformer Features (AST Transformers)
108
+ ## AST Transformer Features
112
109
 
113
- rawsql-ts provides a suite of AST (Abstract Syntax Tree) transformers for advanced SQL analysis and manipulation. These utilities are intended for engineers who require programmatic extraction, analysis, or transformation of SQL query structures.
110
+ A suite of utilities for transforming and analyzing SQL ASTs.
114
111
 
115
112
  ### Main Transformers
116
113
 
117
114
  - **Formatter**
118
- Converts SQL ASTs into standardized SQL text, handling identifier escaping and formatting for all SQL components.
119
- **Note:** Output formatting is currently limited to single-line (compact) style.
120
-
115
+ Converts ASTs to formatted SQL strings. Handles identifier escaping. Output is currently single-line (compact) style.
121
116
  - **SelectValueCollector**
122
- Extracts all columns, including aliases and expressions, from SELECT clauses. Supports wildcard expansion (e.g., `*`, `table.*`) when table structure information is provided.
123
-
117
+ Extracts all columns, aliases, and expressions from SELECT clauses. Supports wildcard expansion (e.g., `*`, `table.*`) with TableColumnResolver.
124
118
  - **SelectableColumnCollector**
125
- Collects all column references in a query that can be included in a SELECT clause. Gathers all columns available from root FROM/JOIN sources.
126
-
119
+ Collects all columns available from root FROM/JOIN sources.
120
+ - **TableSourceCollector**
121
+ Collects all table and subquery sources from FROM and JOIN clauses.
127
122
  - **CTECollector**
128
- Collects all Common Table Expressions (CTEs) from WITH clauses, subqueries, and UNION queries. Supports both nested and recursive CTEs.
129
-
123
+ Collects all CTEs from WITH clauses, subqueries, and UNION queries.
130
124
  - **UpstreamSelectQueryFinder**
131
- Identifies upstream SELECT queries that provide specific columns by traversing CTEs, subqueries, and UNION branches.
132
-
125
+ Finds upstream SELECT queries that provide specific columns by traversing CTEs, subqueries, and UNION branches.
133
126
  - **CTENormalizer**
134
- Consolidates all Common Table Expressions (CTEs) from any part of a query (including nested subqueries, JOINs, and UNIONs) into a single root-level WITH clause. If duplicate CTE names with different definitions are detected, an error is thrown to prevent ambiguity.
135
-
127
+ Consolidates all CTEs into a single root-level WITH clause. Throws an error if duplicate CTE names with different definitions are found.
136
128
  - **QueryNormalizer**
137
- Converts any SELECT query (including UNION, EXCEPT, or VALUES queries) into a standard SimpleSelectQuery format. For UNION or EXCEPT, the query is wrapped as a subquery with an alias (e.g., SELECT * FROM (...)). For VALUES, sequential column names (column1, column2, ...) are generated and the VALUES are wrapped in a subquery. This ensures a predictable query structure for downstream processing.
129
+ Converts any SELECT/UNION/VALUES query into a standard SimpleSelectQuery. Handles subquery wrapping and automatic column name generation.
130
+ - **TableColumnResolver**
131
+ A function type for resolving column names from a table name, mainly used for wildcard expansion (e.g., `table.*`). Used by analyzers like SelectValueCollector.
132
+ ```typescript
133
+ export type TableColumnResolver = (tableName: string) => string[];
134
+ ```
138
135
 
139
- ---
136
+ ---
140
137
 
141
- ### Example Usage
138
+ ## Usage Example
142
139
 
143
140
  ```typescript
144
- import { SelectQueryParser } from 'rawsql-ts';
145
- import { SelectableColumnCollector } from 'rawsql-ts/transformers/SelectableColumnCollector';
141
+ import { TableColumnResolver, SelectQueryParser, SelectableColumnCollector, SelectValueCollector, TableSourceCollector, Formatter } from 'rawsql-ts';
142
+
143
+ // TableColumnResolver example
144
+ const resolver: TableColumnResolver = (tableName) => {
145
+ if (tableName === 'users') return ['user_id', 'user_name', 'email'];
146
+ if (tableName === 'posts') return ['post_id', 'user_id', 'title', 'content'];
147
+ return [];
148
+ };
146
149
 
147
- const sql = `SELECT u.id, u.name FROM users u JOIN posts p ON u.id = p.user_id`;
148
- const query = SelectQueryParser.parseFromText(sql);
150
+ const sql = `SELECT u.*, p.title as post_title FROM users u INNER JOIN posts p ON u.user_id = p.user_id`;
151
+ const query = SelectQueryParser.parse(sql);
152
+ const formatter = new Formatter();
149
153
 
150
- const collector = new SelectableColumnCollector();
151
- const columns = collector.collect(query);
152
- console.log(columns.map(col => col.name)); // ["id", "name", "user_id", ...]
154
+ // Collects information from the SELECT clause.
155
+ // To expand wildcards, you must specify a TableColumnResolver.
156
+ const selectValueCollector = new SelectValueCollector(resolver);
157
+ const selectValues = selectValueCollector.collect(query);
158
+ // Log the name and formatted value of each select value
159
+ console.log('Select values:');
160
+ selectValues.forEach(val => {
161
+ console.log(` name: ${val.name}, value: ${formatter.format(val.value)}`);
162
+ });
163
+ /*
164
+ Select values:
165
+ name: post_title, value: "p"."title"
166
+ name: user_id, value: "u"."user_id"
167
+ name: user_name, value: "u"."user_name"
168
+ name: email, value: "u"."email"
169
+ */
170
+
171
+ // Collects selectable columns from the FROM/JOIN clauses.
172
+ // You can get accurate information by specifying a TableColumnResolver.
173
+ // If omitted, the information will be inferred from the query content.
174
+ const selectableColumnCollector = new SelectableColumnCollector(resolver);
175
+ const selectableColumns = selectableColumnCollector.collect(query);
176
+ // Log detailed info for each selectable column
177
+ console.log('Selectable columns:');
178
+ selectableColumns.forEach(val => {
179
+ console.log(` name: ${val.name}, value: ${formatter.format(val.value)}`);
180
+ });
181
+ /*
182
+ Selectable columns:
183
+ name: post_title, value: "p"."title"
184
+ name: user_id, value: "u"."user_id"
185
+ name: user_name, value: "u"."user_name"
186
+ name: email, value: "u"."email"
187
+ name: post_id, value: "p"."post_id"
188
+ name: title, value: "p"."title"
189
+ name: content, value: "p"."content"
190
+ */
191
+
192
+ // Retrieves physical table sources.
193
+ const tableSourceCollector = new TableSourceCollector();
194
+ const sources = tableSourceCollector.collect(query);
195
+ // Log detailed info for each source
196
+ console.log('Sources:');
197
+ sources.forEach(src => {
198
+ console.log(` name: ${src.getSourceName()}`);
199
+ });
200
+ /*
201
+ TableSources:
202
+ name: users
203
+ name: posts
204
+ */
153
205
  ```
154
206
 
155
207
  ---
156
208
 
157
- By utilizing these transformer utilities, you can perform advanced SQL analysis and manipulation with reliability and consistency.
209
+ ## Advanced Example: Table Join
210
+
211
+ This example demonstrates how to join two tables using rawsql-ts. You do not need to understand the internal structure or manage aliases manually. By specifying the join key(s), the ON clause is generated automatically.
212
+
213
+ ```typescript
214
+ import { SelectQueryParser, Formatter, SimpleSelectQuery } from 'rawsql-ts';
215
+
216
+ // Parse the base query
217
+ const query = SelectQueryParser.parse('SELECT u.user_id, u.name FROM users u') as SimpleSelectQuery;
218
+
219
+ // Add LEFT JOIN using the leftJoinRaw method (join on user_id)
220
+ query.leftJoinRaw('orders', 'o', ['user_id']);
221
+
222
+ // Add WHERE clause
223
+ query.appendWhereRaw('o.order_id IS NULL');
224
+
225
+ const formatter = new Formatter();
226
+ const formattedSql = formatter.format(query);
227
+
228
+ console.log(formattedSql);
229
+ // => select "u"."user_id", "u"."name" from "users" as "u" left join "orders" as "o" on "u"."user_id" = "o"."user_id" where "o"."order_id" is null
230
+ ```
231
+
232
+ **Key Points:**
233
+ - No need to understand internal implementation or alias management
234
+ - Specify only the join key(s) (e.g., `['user_id']`); the ON clause is generated automatically
235
+ - Subqueries and aliases are handled automatically
236
+ - You can join queries without detailed knowledge of SQL structure or AST internals
237
+
238
+ ---
158
239
 
159
240
  ## Benchmarks
160
241
 
161
- This project includes benchmarking functionality. To run benchmarks, execute:
242
+ This project includes a comprehensive benchmark suite to evaluate the performance of `rawsql-ts` in comparison with other popular libraries such as `node-sql-parser` and `sql-formatter`.
243
+
244
+ ### How to Run
162
245
 
163
246
  ```bash
164
247
  npm run benchmark
165
248
  ```
166
249
 
167
- ## Benchmark Details
250
+ ### Benchmark Details
168
251
 
169
- The benchmark suite evaluates the SQL parsing and formatting performance of `rawsql-ts` in comparison to popular libraries such as `sql-formatter` and `node-sql-parser`. Queries of varying complexity are tested:
252
+ The benchmark suite measures SQL parsing and formatting speed across queries of varying complexity:
170
253
 
171
- - **Tokens20**: Simple `SELECT` query with a basic `WHERE` condition (~20 tokens)
172
- - **Tokens70**: Medium complexity query with `JOIN`s and multiple conditions (~70 tokens)
173
- - **Tokens140**: Complex query with `CTE`s and aggregations (~140 tokens)
174
- - **Tokens230**: Highly complex query with multiple `CTE`s, subqueries, and window functions (~230 tokens)
254
+ - **Tokens20**: Simple SELECT with a basic WHERE clause (~20 tokens)
255
+ - **Tokens70**: Medium complexity query with JOINs and multiple conditions (~70 tokens)
256
+ - **Tokens140**: Complex query with CTEs and aggregations (~140 tokens)
257
+ - **Tokens230**: Highly complex query with multiple CTEs, subqueries, and window functions (~230 tokens)
175
258
 
176
- ## Benchmark Environment
259
+ ### Benchmark Environment
177
260
 
178
261
  ```
179
262
  benchmark.js v2.1.4
@@ -182,71 +265,46 @@ AMD Ryzen 7 7800X3D (8C/16T)
182
265
  Node.js v22.14.0
183
266
  ```
184
267
 
185
- ## Results
186
-
187
- ### Tokens20
188
- | Method | Mean | Error | StdDev |
189
- |---------------------------------- |-----------:|----------:|----------:|
190
- | rawsql-ts | 0.021 ms | 0.0044 ms | 0.0023 ms |
191
- | node-sql-parser | 0.169 ms | 0.0695 ms | 0.0355 ms |
192
- | sql-formatter | 0.208 ms | 0.0556 ms | 0.0284 ms |
193
-
194
- ### Tokens70
195
- | Method | Mean | Error | StdDev |
196
- |---------------------------------- |-----------:|----------:|----------:|
197
- | rawsql-ts | 0.057 ms | 0.0143 ms | 0.0073 ms |
198
- | node-sql-parser | 0.216 ms | 0.0780 ms | 0.0398 ms |
199
- | sql-formatter | 0.512 ms | 0.1251 ms | 0.0638 ms |
200
-
201
- ### Tokens140
202
- | Method | Mean | Error | StdDev |
203
- |---------------------------------- |-----------:|----------:|----------:|
204
- | rawsql-ts | 0.112 ms | 0.0236 ms | 0.0120 ms |
205
- | node-sql-parser | 0.404 ms | 0.0926 ms | 0.0472 ms |
206
- | sql-formatter | 1.004 ms | 0.3027 ms | 0.1545 ms |
207
-
208
- ### Tokens230
209
- | Method | Mean | Error | StdDev |
210
- |---------------------------------- |-----------:|----------:|----------:|
211
- | rawsql-ts | 0.182 ms | 0.0371 ms | 0.0189 ms |
212
- | node-sql-parser | 0.865 ms | 0.3325 ms | 0.1696 ms |
213
- | sql-formatter | 1.696 ms | 0.2754 ms | 0.1405 ms |
214
-
215
- ## Performance Summary
268
+ ### Results
269
+
270
+ #### Tokens20
271
+ | Method | Mean | Error | StdDev |
272
+ |------------------|----------:|----------:|----------:|
273
+ | rawsql-ts | 0.021 ms | 0.0044 ms | 0.0023 ms |
274
+ | node-sql-parser | 0.169 ms | 0.0695 ms | 0.0355 ms |
275
+ | sql-formatter | 0.208 ms | 0.0556 ms | 0.0284 ms |
276
+
277
+ #### Tokens70
278
+ | Method | Mean | Error | StdDev |
279
+ |------------------|----------:|----------:|----------:|
280
+ | rawsql-ts | 0.057 ms | 0.0143 ms | 0.0073 ms |
281
+ | node-sql-parser | 0.216 ms | 0.0780 ms | 0.0398 ms |
282
+ | sql-formatter | 0.512 ms | 0.1251 ms | 0.0638 ms |
283
+
284
+ #### Tokens140
285
+ | Method | Mean | Error | StdDev |
286
+ |------------------|----------:|----------:|----------:|
287
+ | rawsql-ts | 0.112 ms | 0.0236 ms | 0.0120 ms |
288
+ | node-sql-parser | 0.404 ms | 0.0926 ms | 0.0472 ms |
289
+ | sql-formatter | 1.004 ms | 0.3027 ms | 0.1545 ms |
290
+
291
+ #### Tokens230
292
+ | Method | Mean | Error | StdDev |
293
+ |------------------|----------:|----------:|----------:|
294
+ | rawsql-ts | 0.182 ms | 0.0371 ms | 0.0189 ms |
295
+ | node-sql-parser | 0.865 ms | 0.3325 ms | 0.1696 ms |
296
+ | sql-formatter | 1.696 ms | 0.2754 ms | 0.1405 ms |
297
+
298
+ ### Performance Summary
216
299
 
217
300
  - `rawsql-ts` consistently outperforms both `node-sql-parser` and `sql-formatter` in all tested scenarios.
218
301
  - Approximately 4x faster than `node-sql-parser`.
219
- - Approximately 9-10x faster than `sql-formatter`.
220
- - Maintains comprehensive SQL parsing capabilities while delivering significant performance improvements.
221
-
222
- > **Note:** These benchmarks are based on a specific hardware and software environment. Actual performance may vary depending on system configuration and workload.
302
+ - Approximately 910x faster than `sql-formatter`.
303
+ - Maintains high performance even with complex SQL while providing comprehensive features.
223
304
 
224
- ## Practical Example: Table Join
305
+ > **Note:** These benchmarks are based on a specific hardware and software environment. Actual performance may vary depending on system configuration and query complexity.
225
306
 
226
- Let's see how easy it is to join two tables using rawsql-ts! You don't need to know the internal structure of SelectQuery or worry about alias names—just specify the join key(s) and the library will generate the ON clause for you automatically.
227
-
228
- ```typescript
229
- import { SelectQueryParser } from 'rawsql-ts';
230
- import { Formatter } from 'rawsql-ts';
231
-
232
- // Parse two separate queries
233
- const userQuery = SelectQueryParser.parseFromText('SELECT user_id, user_name FROM users');
234
- const postQuery = SelectQueryParser.parseFromText('SELECT post_id, user_id, title FROM posts');
235
-
236
- // Join the two queries using innerJoin
237
- // Just pass the join key(s) as an array, and the ON clause will be generated automatically!
238
- const joinedQuery = userQuery.innerJoin(postQuery, ['user_id']);
307
+ ---
239
308
 
240
- // Format the joined query back to SQL
241
- const formatter = new Formatter();
242
- const sql = formatter.visit(joinedQuery);
243
- console.log(sql);
244
- // Output:
245
- // select "user_id", "user_name", "post_id", "title" from "users" inner join (select "post_id", "user_id", "title" from "posts") on "users"."user_id" = "posts"."user_id"
246
- ```
309
+ Feel free to try rawsql-ts! Questions, requests, and bug reports are always welcome.
247
310
 
248
- **Point:**
249
- - You do not need to understand the internal code of SelectQuery to perform joins.
250
- - You only need to specify the join key(s) (e.g., `['user_id']`). The ON clause is generated for you.
251
- - Alias names and subquery details are handled automatically by the library, so you never have to worry about them!
252
- - This makes it super easy to join queries, even if you don't know the full structure of the SQL or the internal AST.
package/dist/index.d.ts CHANGED
@@ -6,8 +6,9 @@ export * from './models/ValuesQuery';
6
6
  export * from './transformers/CTECollector';
7
7
  export * from './transformers/CTENormalizer';
8
8
  export * from './transformers/Formatter';
9
- export * from './transformers/QueryNormalizer';
9
+ export * from './transformers/QueryConverter';
10
10
  export * from './transformers/SelectValueCollector';
11
11
  export * from './transformers/SelectableColumnCollector';
12
+ export * from './transformers/TableColumnResolver';
12
13
  export * from './transformers/TableSourceCollector';
13
14
  export * from './transformers/UpstreamSelectQueryFinder';
package/dist/index.js CHANGED
@@ -23,9 +23,10 @@ __exportStar(require("./models/ValuesQuery"), exports);
23
23
  __exportStar(require("./transformers/CTECollector"), exports);
24
24
  __exportStar(require("./transformers/CTENormalizer"), exports);
25
25
  __exportStar(require("./transformers/Formatter"), exports);
26
- __exportStar(require("./transformers/QueryNormalizer"), exports);
26
+ __exportStar(require("./transformers/QueryConverter"), exports);
27
27
  __exportStar(require("./transformers/SelectValueCollector"), exports);
28
28
  __exportStar(require("./transformers/SelectableColumnCollector"), exports);
29
+ __exportStar(require("./transformers/TableColumnResolver"), exports);
29
30
  __exportStar(require("./transformers/TableSourceCollector"), exports);
30
31
  __exportStar(require("./transformers/UpstreamSelectQueryFinder"), exports);
31
32
  // Add more exports here if you want to expose additional public API
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,iEAA+C;AAC/C,sEAAoD;AACpD,2EAAyD;AACzD,sEAAoD;AACpD,2EAAyD;AACzD,oEAAoE"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oCAAoC;AACpC,8DAA4C;AAE5C,6DAA2C;AAC3C,uDAAqC;AACrC,0DAAwC;AACxC,uDAAqC;AAErC,8DAA4C;AAC5C,+DAA6C;AAC7C,2DAAyC;AACzC,gEAA8C;AAC9C,sEAAoD;AACpD,2EAAyD;AACzD,qEAAmD;AACnD,sEAAoD;AACpD,2EAAyD;AACzD,oEAAoE"}
@@ -95,8 +95,9 @@ class BinarySelectQuery extends SqlComponent_1.SqlComponent {
95
95
  this.left = new BinarySelectQuery(this.left, this.operator.value, this.right);
96
96
  this.operator = new ValueComponent_1.RawString(operator);
97
97
  this.right = query;
98
- const normalizer = new CTENormalizer_1.CTENormalizer();
99
- normalizer.normalize(this);
98
+ // const normalizer = new CTENormalizer();
99
+ // normalizer.normalize(this);
100
+ CTENormalizer_1.CTENormalizer.normalize(this);
100
101
  return this;
101
102
  }
102
103
  /**
@@ -106,27 +107,27 @@ class BinarySelectQuery extends SqlComponent_1.SqlComponent {
106
107
  * @returns A new BinarySelectQuery representing "(this) UNION (parsed query)"
107
108
  */
108
109
  unionRaw(sql) {
109
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
110
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
110
111
  return this.union(parsedQuery);
111
112
  }
112
113
  unionAllRaw(sql) {
113
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
114
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
114
115
  return this.unionAll(parsedQuery);
115
116
  }
116
117
  intersectRaw(sql) {
117
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
118
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
118
119
  return this.intersect(parsedQuery);
119
120
  }
120
121
  intersectAllRaw(sql) {
121
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
122
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
122
123
  return this.intersectAll(parsedQuery);
123
124
  }
124
125
  exceptRaw(sql) {
125
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
126
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
126
127
  return this.except(parsedQuery);
127
128
  }
128
129
  exceptAllRaw(sql) {
129
- const parsedQuery = SelectQueryParser_1.SelectQueryParser.parseFromText(sql);
130
+ const parsedQuery = SelectQueryParser_1.SelectQueryParser.parse(sql);
130
131
  return this.exceptAll(parsedQuery);
131
132
  }
132
133
  // Returns a SourceExpression wrapping this query as a subquery source.
@@ -1 +1 @@
1
- {"version":3,"file":"BinarySelectQuery.js","sourceRoot":"","sources":["../../src/models/BinarySelectQuery.ts"],"names":[],"mappings":";;;AAAA,qCAAmF;AAInF,iDAA8C;AAC9C,qDAA6C;AAC7C,iEAA8D;AAC9D,oEAAiE;AAEjE;;GAEG;AACH,MAAa,iBAAkB,SAAQ,2BAAY;IAM/C,YAAY,IAAiB,EAAE,QAAgB,EAAE,KAAkB;QAC/D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,0BAAS,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;;;;;;OAOG;IACI,KAAK,CAAC,KAAkB;QAC3B,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACI,QAAQ,CAAC,KAAkB;QAC9B,OAAO,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;O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EAAE,IAAI,CAAC,CACzC,CAAC;IACN,CAAC;;AAhJL,8CAiJC;AAhJU,sBAAI,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
@@ -106,7 +106,7 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
106
106
  * @param rawCondition Raw SQL string representing the condition (e.g. "status = 'active'")
107
107
  */
108
108
  appendWhereRaw(rawCondition) {
109
- const parsedCondition = ValueParser_1.ValueParser.parseFromText(rawCondition);
109
+ const parsedCondition = ValueParser_1.ValueParser.parse(rawCondition);
110
110
  this.appendWhere(parsedCondition);
111
111
  }
112
112
  /**
@@ -130,7 +130,7 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
130
130
  * @param rawCondition Raw SQL string representing the condition (e.g. "count(*) > 5")
131
131
  */
132
132
  appendHavingRaw(rawCondition) {
133
- const parsedCondition = ValueParser_1.ValueParser.parseFromText(rawCondition);
133
+ const parsedCondition = ValueParser_1.ValueParser.parse(rawCondition);
134
134
  this.appendHaving(parsedCondition);
135
135
  }
136
136
  /**
@@ -208,7 +208,7 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
208
208
  * @param columns Array of column names to join on
209
209
  */
210
210
  joinSourceRaw(joinType, joinSourceRawText, alias, columns) {
211
- const tableSource = SourceParser_1.SourceParser.parseFromText(joinSourceRawText);
211
+ const tableSource = SourceParser_1.SourceParser.parse(joinSourceRawText);
212
212
  const sourceExpr = new Clause_1.SourceExpression(tableSource, new Clause_1.SourceAliasExpression(alias, null));
213
213
  this.joinSource(joinType, sourceExpr, columns);
214
214
  }
@@ -249,8 +249,9 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
249
249
  this.fromClause.joins = [joinClause];
250
250
  }
251
251
  }
252
- const normalizer = new CTENormalizer_1.CTENormalizer();
253
- normalizer.normalize(this);
252
+ // const normalizer = new CTENormalizer();
253
+ // normalizer.normalize(this);
254
+ CTENormalizer_1.CTENormalizer.normalize(this);
254
255
  }
255
256
  // Returns a SourceExpression wrapping this query as a subquery source.
256
257
  // Alias is required for correct SQL generation and join logic.
@@ -269,8 +270,9 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
269
270
  else {
270
271
  this.WithClause.tables.push(...tables);
271
272
  }
272
- const normalizer = new CTENormalizer_1.CTENormalizer();
273
- normalizer.normalize(this);
273
+ // const normalizer = new CTENormalizer();
274
+ // normalizer.normalize(this);
275
+ CTENormalizer_1.CTENormalizer.normalize(this);
274
276
  }
275
277
  /**
276
278
  * Appends a CommonTable (CTE) to the WITH clause from raw SQL text and alias.
@@ -280,7 +282,7 @@ class SimpleSelectQuery extends SqlComponent_1.SqlComponent {
280
282
  * @param alias Optional alias for the CTE (e.g. 'cte_name')
281
283
  */
282
284
  appendWithRaw(rawText, alias) {
283
- const query = SelectQueryParser_1.SelectQueryParser.parseFromText(rawText);
285
+ const query = SelectQueryParser_1.SelectQueryParser.parse(rawText);
284
286
  const commonTable = new Clause_1.CommonTable(query, alias, null);
285
287
  this.appendWith(commonTable);
286
288
  }