tree-sitter-analyzer 1.9.17.1__py3-none-any.whl

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 (149) hide show
  1. tree_sitter_analyzer/__init__.py +132 -0
  2. tree_sitter_analyzer/__main__.py +11 -0
  3. tree_sitter_analyzer/api.py +853 -0
  4. tree_sitter_analyzer/cli/__init__.py +39 -0
  5. tree_sitter_analyzer/cli/__main__.py +12 -0
  6. tree_sitter_analyzer/cli/argument_validator.py +89 -0
  7. tree_sitter_analyzer/cli/commands/__init__.py +26 -0
  8. tree_sitter_analyzer/cli/commands/advanced_command.py +226 -0
  9. tree_sitter_analyzer/cli/commands/base_command.py +181 -0
  10. tree_sitter_analyzer/cli/commands/default_command.py +18 -0
  11. tree_sitter_analyzer/cli/commands/find_and_grep_cli.py +188 -0
  12. tree_sitter_analyzer/cli/commands/list_files_cli.py +133 -0
  13. tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -0
  14. tree_sitter_analyzer/cli/commands/query_command.py +109 -0
  15. tree_sitter_analyzer/cli/commands/search_content_cli.py +161 -0
  16. tree_sitter_analyzer/cli/commands/structure_command.py +156 -0
  17. tree_sitter_analyzer/cli/commands/summary_command.py +116 -0
  18. tree_sitter_analyzer/cli/commands/table_command.py +414 -0
  19. tree_sitter_analyzer/cli/info_commands.py +124 -0
  20. tree_sitter_analyzer/cli_main.py +472 -0
  21. tree_sitter_analyzer/constants.py +85 -0
  22. tree_sitter_analyzer/core/__init__.py +15 -0
  23. tree_sitter_analyzer/core/analysis_engine.py +580 -0
  24. tree_sitter_analyzer/core/cache_service.py +333 -0
  25. tree_sitter_analyzer/core/engine.py +585 -0
  26. tree_sitter_analyzer/core/parser.py +293 -0
  27. tree_sitter_analyzer/core/query.py +605 -0
  28. tree_sitter_analyzer/core/query_filter.py +200 -0
  29. tree_sitter_analyzer/core/query_service.py +340 -0
  30. tree_sitter_analyzer/encoding_utils.py +530 -0
  31. tree_sitter_analyzer/exceptions.py +747 -0
  32. tree_sitter_analyzer/file_handler.py +246 -0
  33. tree_sitter_analyzer/formatters/__init__.py +1 -0
  34. tree_sitter_analyzer/formatters/base_formatter.py +201 -0
  35. tree_sitter_analyzer/formatters/csharp_formatter.py +367 -0
  36. tree_sitter_analyzer/formatters/formatter_config.py +197 -0
  37. tree_sitter_analyzer/formatters/formatter_factory.py +84 -0
  38. tree_sitter_analyzer/formatters/formatter_registry.py +377 -0
  39. tree_sitter_analyzer/formatters/formatter_selector.py +96 -0
  40. tree_sitter_analyzer/formatters/go_formatter.py +368 -0
  41. tree_sitter_analyzer/formatters/html_formatter.py +498 -0
  42. tree_sitter_analyzer/formatters/java_formatter.py +423 -0
  43. tree_sitter_analyzer/formatters/javascript_formatter.py +611 -0
  44. tree_sitter_analyzer/formatters/kotlin_formatter.py +268 -0
  45. tree_sitter_analyzer/formatters/language_formatter_factory.py +123 -0
  46. tree_sitter_analyzer/formatters/legacy_formatter_adapters.py +228 -0
  47. tree_sitter_analyzer/formatters/markdown_formatter.py +725 -0
  48. tree_sitter_analyzer/formatters/php_formatter.py +301 -0
  49. tree_sitter_analyzer/formatters/python_formatter.py +830 -0
  50. tree_sitter_analyzer/formatters/ruby_formatter.py +278 -0
  51. tree_sitter_analyzer/formatters/rust_formatter.py +233 -0
  52. tree_sitter_analyzer/formatters/sql_formatter_wrapper.py +689 -0
  53. tree_sitter_analyzer/formatters/sql_formatters.py +536 -0
  54. tree_sitter_analyzer/formatters/typescript_formatter.py +543 -0
  55. tree_sitter_analyzer/formatters/yaml_formatter.py +462 -0
  56. tree_sitter_analyzer/interfaces/__init__.py +9 -0
  57. tree_sitter_analyzer/interfaces/cli.py +535 -0
  58. tree_sitter_analyzer/interfaces/cli_adapter.py +359 -0
  59. tree_sitter_analyzer/interfaces/mcp_adapter.py +224 -0
  60. tree_sitter_analyzer/interfaces/mcp_server.py +428 -0
  61. tree_sitter_analyzer/language_detector.py +553 -0
  62. tree_sitter_analyzer/language_loader.py +271 -0
  63. tree_sitter_analyzer/languages/__init__.py +10 -0
  64. tree_sitter_analyzer/languages/csharp_plugin.py +1076 -0
  65. tree_sitter_analyzer/languages/css_plugin.py +449 -0
  66. tree_sitter_analyzer/languages/go_plugin.py +836 -0
  67. tree_sitter_analyzer/languages/html_plugin.py +496 -0
  68. tree_sitter_analyzer/languages/java_plugin.py +1299 -0
  69. tree_sitter_analyzer/languages/javascript_plugin.py +1622 -0
  70. tree_sitter_analyzer/languages/kotlin_plugin.py +656 -0
  71. tree_sitter_analyzer/languages/markdown_plugin.py +1928 -0
  72. tree_sitter_analyzer/languages/php_plugin.py +862 -0
  73. tree_sitter_analyzer/languages/python_plugin.py +1636 -0
  74. tree_sitter_analyzer/languages/ruby_plugin.py +757 -0
  75. tree_sitter_analyzer/languages/rust_plugin.py +673 -0
  76. tree_sitter_analyzer/languages/sql_plugin.py +2444 -0
  77. tree_sitter_analyzer/languages/typescript_plugin.py +1892 -0
  78. tree_sitter_analyzer/languages/yaml_plugin.py +695 -0
  79. tree_sitter_analyzer/legacy_table_formatter.py +860 -0
  80. tree_sitter_analyzer/mcp/__init__.py +34 -0
  81. tree_sitter_analyzer/mcp/resources/__init__.py +43 -0
  82. tree_sitter_analyzer/mcp/resources/code_file_resource.py +208 -0
  83. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +586 -0
  84. tree_sitter_analyzer/mcp/server.py +869 -0
  85. tree_sitter_analyzer/mcp/tools/__init__.py +28 -0
  86. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +779 -0
  87. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +291 -0
  88. tree_sitter_analyzer/mcp/tools/base_tool.py +139 -0
  89. tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +816 -0
  90. tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +686 -0
  91. tree_sitter_analyzer/mcp/tools/list_files_tool.py +413 -0
  92. tree_sitter_analyzer/mcp/tools/output_format_validator.py +148 -0
  93. tree_sitter_analyzer/mcp/tools/query_tool.py +443 -0
  94. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +464 -0
  95. tree_sitter_analyzer/mcp/tools/search_content_tool.py +836 -0
  96. tree_sitter_analyzer/mcp/tools/table_format_tool.py +572 -0
  97. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +653 -0
  98. tree_sitter_analyzer/mcp/utils/__init__.py +113 -0
  99. tree_sitter_analyzer/mcp/utils/error_handler.py +569 -0
  100. tree_sitter_analyzer/mcp/utils/file_output_factory.py +217 -0
  101. tree_sitter_analyzer/mcp/utils/file_output_manager.py +322 -0
  102. tree_sitter_analyzer/mcp/utils/gitignore_detector.py +358 -0
  103. tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -0
  104. tree_sitter_analyzer/mcp/utils/search_cache.py +343 -0
  105. tree_sitter_analyzer/models.py +840 -0
  106. tree_sitter_analyzer/mypy_current_errors.txt +2 -0
  107. tree_sitter_analyzer/output_manager.py +255 -0
  108. tree_sitter_analyzer/platform_compat/__init__.py +3 -0
  109. tree_sitter_analyzer/platform_compat/adapter.py +324 -0
  110. tree_sitter_analyzer/platform_compat/compare.py +224 -0
  111. tree_sitter_analyzer/platform_compat/detector.py +67 -0
  112. tree_sitter_analyzer/platform_compat/fixtures.py +228 -0
  113. tree_sitter_analyzer/platform_compat/profiles.py +217 -0
  114. tree_sitter_analyzer/platform_compat/record.py +55 -0
  115. tree_sitter_analyzer/platform_compat/recorder.py +155 -0
  116. tree_sitter_analyzer/platform_compat/report.py +92 -0
  117. tree_sitter_analyzer/plugins/__init__.py +280 -0
  118. tree_sitter_analyzer/plugins/base.py +647 -0
  119. tree_sitter_analyzer/plugins/manager.py +384 -0
  120. tree_sitter_analyzer/project_detector.py +328 -0
  121. tree_sitter_analyzer/queries/__init__.py +27 -0
  122. tree_sitter_analyzer/queries/csharp.py +216 -0
  123. tree_sitter_analyzer/queries/css.py +615 -0
  124. tree_sitter_analyzer/queries/go.py +275 -0
  125. tree_sitter_analyzer/queries/html.py +543 -0
  126. tree_sitter_analyzer/queries/java.py +402 -0
  127. tree_sitter_analyzer/queries/javascript.py +724 -0
  128. tree_sitter_analyzer/queries/kotlin.py +192 -0
  129. tree_sitter_analyzer/queries/markdown.py +258 -0
  130. tree_sitter_analyzer/queries/php.py +95 -0
  131. tree_sitter_analyzer/queries/python.py +859 -0
  132. tree_sitter_analyzer/queries/ruby.py +92 -0
  133. tree_sitter_analyzer/queries/rust.py +223 -0
  134. tree_sitter_analyzer/queries/sql.py +555 -0
  135. tree_sitter_analyzer/queries/typescript.py +871 -0
  136. tree_sitter_analyzer/queries/yaml.py +236 -0
  137. tree_sitter_analyzer/query_loader.py +272 -0
  138. tree_sitter_analyzer/security/__init__.py +22 -0
  139. tree_sitter_analyzer/security/boundary_manager.py +277 -0
  140. tree_sitter_analyzer/security/regex_checker.py +297 -0
  141. tree_sitter_analyzer/security/validator.py +599 -0
  142. tree_sitter_analyzer/table_formatter.py +782 -0
  143. tree_sitter_analyzer/utils/__init__.py +53 -0
  144. tree_sitter_analyzer/utils/logging.py +433 -0
  145. tree_sitter_analyzer/utils/tree_sitter_compat.py +289 -0
  146. tree_sitter_analyzer-1.9.17.1.dist-info/METADATA +485 -0
  147. tree_sitter_analyzer-1.9.17.1.dist-info/RECORD +149 -0
  148. tree_sitter_analyzer-1.9.17.1.dist-info/WHEEL +4 -0
  149. tree_sitter_analyzer-1.9.17.1.dist-info/entry_points.txt +25 -0
@@ -0,0 +1,555 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ SQL Language Queries
4
+
5
+ Tree-sitter queries specific to SQL language constructs.
6
+ Covers tables, views, procedures, functions, triggers, indexes, and other SQL-specific elements.
7
+ """
8
+
9
+ # SQL-specific comprehensive query library
10
+ SQL_QUERIES: dict[str, str] = {
11
+ # --- Basic DDL Statements ---
12
+ "table": """
13
+ (create_table_statement
14
+ table_name: (identifier) @table_name) @table
15
+ """,
16
+ "create_table": """
17
+ (create_table_statement
18
+ table_name: (identifier) @table_name
19
+ (column_definitions
20
+ (column_definition
21
+ column_name: (identifier) @column_name
22
+ data_type: (_) @column_type)*) @columns) @create_table
23
+ """,
24
+ "view": """
25
+ (create_view_statement
26
+ view_name: (identifier) @view_name) @view
27
+ """,
28
+ "create_view": """
29
+ (create_view_statement
30
+ view_name: (identifier) @view_name
31
+ (select_statement) @view_query) @create_view
32
+ """,
33
+ "index": """
34
+ (create_index_statement
35
+ index_name: (identifier) @index_name
36
+ table_name: (identifier) @table_name) @index
37
+ """,
38
+ "create_index": """
39
+ (create_index_statement
40
+ index_name: (identifier) @index_name
41
+ table_name: (identifier) @table_name
42
+ (column_list
43
+ (identifier) @index_column)*) @create_index
44
+ """,
45
+ # --- Stored Procedures and Functions ---
46
+ "procedure": """
47
+ (create_procedure_statement
48
+ procedure_name: (identifier) @procedure_name) @procedure
49
+ """,
50
+ "create_procedure": """
51
+ (create_procedure_statement
52
+ procedure_name: (identifier) @procedure_name
53
+ (parameter_list
54
+ (parameter
55
+ parameter_name: (identifier) @param_name
56
+ data_type: (_) @param_type)*)?
57
+ (compound_statement) @procedure_body) @create_procedure
58
+ """,
59
+ "function": """
60
+ (create_function_statement
61
+ function_name: (identifier) @function_name) @function
62
+ """,
63
+ "create_function": """
64
+ (create_function_statement
65
+ function_name: (identifier) @function_name
66
+ (parameter_list
67
+ (parameter
68
+ parameter_name: (identifier) @param_name
69
+ data_type: (_) @param_type)*)?
70
+ return_type: (_) @return_type
71
+ (compound_statement) @function_body) @create_function
72
+ """,
73
+ # --- Triggers ---
74
+ "trigger": """
75
+ (create_trigger_statement
76
+ trigger_name: (identifier) @trigger_name) @trigger
77
+ """,
78
+ "create_trigger": """
79
+ (create_trigger_statement
80
+ trigger_name: (identifier) @trigger_name
81
+ timing: (_) @trigger_timing
82
+ event: (_) @trigger_event
83
+ table_name: (identifier) @table_name
84
+ (compound_statement) @trigger_body) @create_trigger
85
+ """,
86
+ # --- DML Statements ---
87
+ "select": """
88
+ (select_statement) @select
89
+ """,
90
+ "select_detailed": """
91
+ (select_statement
92
+ (select_clause
93
+ (select_list
94
+ (_) @select_item)*) @select_clause
95
+ (from_clause
96
+ (table_reference) @from_table)?
97
+ (where_clause
98
+ (_) @where_condition)?
99
+ (group_by_clause
100
+ (_) @group_by_item)*
101
+ (having_clause
102
+ (_) @having_condition)?
103
+ (order_by_clause
104
+ (order_by_item) @order_by_item)*) @select_detailed
105
+ """,
106
+ "insert": """
107
+ (insert_statement
108
+ table_name: (identifier) @table_name) @insert
109
+ """,
110
+ "update": """
111
+ (update_statement
112
+ table_name: (identifier) @table_name) @update
113
+ """,
114
+ "delete": """
115
+ (delete_statement
116
+ table_name: (identifier) @table_name) @delete
117
+ """,
118
+ # --- Constraints ---
119
+ "primary_key": """
120
+ (primary_key_constraint
121
+ (column_list
122
+ (identifier) @pk_column)*) @primary_key
123
+ """,
124
+ "foreign_key": """
125
+ (foreign_key_constraint
126
+ (column_list
127
+ (identifier) @fk_column)*
128
+ referenced_table: (identifier) @referenced_table
129
+ (column_list
130
+ (identifier) @referenced_column)*) @foreign_key
131
+ """,
132
+ "unique_constraint": """
133
+ (unique_constraint
134
+ (column_list
135
+ (identifier) @unique_column)*) @unique_constraint
136
+ """,
137
+ "check_constraint": """
138
+ (check_constraint
139
+ (_) @check_condition) @check_constraint
140
+ """,
141
+ # --- Column Definitions ---
142
+ "column": """
143
+ (column_definition
144
+ column_name: (identifier) @column_name
145
+ data_type: (_) @data_type) @column
146
+ """,
147
+ "column_with_constraints": """
148
+ (column_definition
149
+ column_name: (identifier) @column_name
150
+ data_type: (_) @data_type
151
+ (column_constraint)* @constraints) @column_with_constraints
152
+ """,
153
+ # --- Joins ---
154
+ "join": """
155
+ (join_clause
156
+ join_type: (_)? @join_type
157
+ table_reference: (_) @joined_table
158
+ join_condition: (_) @join_condition) @join
159
+ """,
160
+ "inner_join": """
161
+ (join_clause
162
+ join_type: (inner_join) @join_type
163
+ table_reference: (_) @joined_table
164
+ join_condition: (_) @join_condition) @inner_join
165
+ """,
166
+ "left_join": """
167
+ (join_clause
168
+ join_type: (left_join) @join_type
169
+ table_reference: (_) @joined_table
170
+ join_condition: (_) @join_condition) @left_join
171
+ """,
172
+ "right_join": """
173
+ (join_clause
174
+ join_type: (right_join) @join_type
175
+ table_reference: (_) @joined_table
176
+ join_condition: (_) @join_condition) @right_join
177
+ """,
178
+ # --- Aggregate Functions ---
179
+ "aggregate_function": """
180
+ (function_call
181
+ function_name: (identifier) @function_name
182
+ (#match? @function_name "COUNT|SUM|AVG|MIN|MAX|GROUP_CONCAT")
183
+ arguments: (argument_list) @arguments) @aggregate_function
184
+ """,
185
+ "count_function": """
186
+ (function_call
187
+ function_name: (identifier) @function_name
188
+ (#match? @function_name "COUNT")
189
+ arguments: (argument_list) @arguments) @count_function
190
+ """,
191
+ "sum_function": """
192
+ (function_call
193
+ function_name: (identifier) @function_name
194
+ (#match? @function_name "SUM")
195
+ arguments: (argument_list) @arguments) @sum_function
196
+ """,
197
+ # --- Window Functions ---
198
+ "window_function": """
199
+ (window_function
200
+ function_name: (identifier) @function_name
201
+ arguments: (argument_list)? @arguments
202
+ (over_clause
203
+ (partition_by_clause)? @partition_by
204
+ (order_by_clause)? @order_by)) @window_function
205
+ """,
206
+ # --- Common Table Expressions (CTE) ---
207
+ "cte": """
208
+ (with_clause
209
+ (cte_definition
210
+ cte_name: (identifier) @cte_name
211
+ (select_statement) @cte_query)) @cte
212
+ """,
213
+ "with_statement": """
214
+ (with_statement
215
+ (with_clause
216
+ (cte_definition
217
+ cte_name: (identifier) @cte_name
218
+ (select_statement) @cte_query)*) @with_clause
219
+ (select_statement) @main_query) @with_statement
220
+ """,
221
+ # --- Subqueries ---
222
+ "subquery": """
223
+ (subquery
224
+ (select_statement) @subquery_select) @subquery
225
+ """,
226
+ "exists_subquery": """
227
+ (exists_expression
228
+ (subquery
229
+ (select_statement) @exists_query)) @exists_subquery
230
+ """,
231
+ "in_subquery": """
232
+ (in_expression
233
+ left: (_) @in_left
234
+ right: (subquery
235
+ (select_statement) @in_query)) @in_subquery
236
+ """,
237
+ # --- Data Types ---
238
+ "varchar_type": """
239
+ (varchar_type
240
+ size: (integer) @varchar_size) @varchar_type
241
+ """,
242
+ "decimal_type": """
243
+ (decimal_type
244
+ precision: (integer) @decimal_precision
245
+ scale: (integer)? @decimal_scale) @decimal_type
246
+ """,
247
+ "enum_type": """
248
+ (enum_type
249
+ (string_literal) @enum_value*) @enum_type
250
+ """,
251
+ # --- Comments ---
252
+ "comment": """
253
+ (comment) @comment
254
+ """,
255
+ "line_comment": """
256
+ (line_comment) @line_comment
257
+ """,
258
+ "block_comment": """
259
+ (block_comment) @block_comment
260
+ """,
261
+ # --- Name-only Extraction ---
262
+ "table_name": """
263
+ (create_table_statement
264
+ table_name: (identifier) @table_name)
265
+ """,
266
+ "view_name": """
267
+ (create_view_statement
268
+ view_name: (identifier) @view_name)
269
+ """,
270
+ "procedure_name": """
271
+ (create_procedure_statement
272
+ procedure_name: (identifier) @procedure_name)
273
+ """,
274
+ "function_name": """
275
+ (create_function_statement
276
+ function_name: (identifier) @function_name)
277
+ """,
278
+ "trigger_name": """
279
+ (create_trigger_statement
280
+ trigger_name: (identifier) @trigger_name)
281
+ """,
282
+ "index_name": """
283
+ (create_index_statement
284
+ index_name: (identifier) @index_name)
285
+ """,
286
+ "column_name": """
287
+ (column_definition
288
+ column_name: (identifier) @column_name)
289
+ """,
290
+ # --- Advanced Patterns ---
291
+ "stored_procedure_call": """
292
+ (call_statement
293
+ procedure_name: (identifier) @procedure_name
294
+ arguments: (argument_list)? @arguments) @procedure_call
295
+ """,
296
+ "transaction": """
297
+ (transaction_statement) @transaction
298
+ """,
299
+ "begin_transaction": """
300
+ (begin_transaction_statement) @begin_transaction
301
+ """,
302
+ "commit_transaction": """
303
+ (commit_transaction_statement) @commit_transaction
304
+ """,
305
+ "rollback_transaction": """
306
+ (rollback_transaction_statement) @rollback_transaction
307
+ """,
308
+ # --- Database-specific Features ---
309
+ "auto_increment": """
310
+ (column_definition
311
+ column_name: (identifier) @column_name
312
+ data_type: (_) @data_type
313
+ (auto_increment_constraint) @auto_increment) @auto_increment_column
314
+ """,
315
+ "default_value": """
316
+ (column_definition
317
+ column_name: (identifier) @column_name
318
+ data_type: (_) @data_type
319
+ (default_constraint
320
+ value: (_) @default_value)) @column_with_default
321
+ """,
322
+ "not_null": """
323
+ (column_definition
324
+ column_name: (identifier) @column_name
325
+ data_type: (_) @data_type
326
+ (not_null_constraint) @not_null) @not_null_column
327
+ """,
328
+ # --- Error Handling (for tree-sitter-sql ERROR nodes) ---
329
+ "error_node": """
330
+ (ERROR) @error_node
331
+ """,
332
+ "procedure_in_error": """
333
+ (ERROR
334
+ "PROCEDURE" @procedure_keyword
335
+ (identifier) @procedure_name) @procedure_error
336
+ """,
337
+ "function_in_error": """
338
+ (ERROR
339
+ "FUNCTION" @function_keyword
340
+ (identifier) @function_name) @function_error
341
+ """,
342
+ "trigger_in_error": """
343
+ (ERROR
344
+ "TRIGGER" @trigger_keyword
345
+ (identifier) @trigger_name) @trigger_error
346
+ """,
347
+ }
348
+
349
+ # Query descriptions
350
+ SQL_QUERY_DESCRIPTIONS: dict[str, str] = {
351
+ "table": "Extract table creation statements",
352
+ "create_table": "Extract detailed table creation with columns",
353
+ "view": "Extract view creation statements",
354
+ "create_view": "Extract detailed view creation with query",
355
+ "index": "Extract index creation statements",
356
+ "create_index": "Extract detailed index creation with columns",
357
+ "procedure": "Extract stored procedure definitions",
358
+ "create_procedure": "Extract detailed procedure creation with parameters",
359
+ "function": "Extract function definitions",
360
+ "create_function": "Extract detailed function creation with parameters and return type",
361
+ "trigger": "Extract trigger definitions",
362
+ "create_trigger": "Extract detailed trigger creation with timing and events",
363
+ "select": "Extract SELECT statements",
364
+ "select_detailed": "Extract detailed SELECT statements with clauses",
365
+ "insert": "Extract INSERT statements",
366
+ "update": "Extract UPDATE statements",
367
+ "delete": "Extract DELETE statements",
368
+ "primary_key": "Extract primary key constraints",
369
+ "foreign_key": "Extract foreign key constraints",
370
+ "unique_constraint": "Extract unique constraints",
371
+ "check_constraint": "Extract check constraints",
372
+ "column": "Extract column definitions",
373
+ "column_with_constraints": "Extract columns with constraints",
374
+ "join": "Extract JOIN clauses",
375
+ "inner_join": "Extract INNER JOIN clauses",
376
+ "left_join": "Extract LEFT JOIN clauses",
377
+ "right_join": "Extract RIGHT JOIN clauses",
378
+ "aggregate_function": "Extract aggregate functions (COUNT, SUM, AVG, etc.)",
379
+ "count_function": "Extract COUNT functions",
380
+ "sum_function": "Extract SUM functions",
381
+ "window_function": "Extract window functions with OVER clause",
382
+ "cte": "Extract Common Table Expressions (CTE)",
383
+ "with_statement": "Extract WITH statements",
384
+ "subquery": "Extract subqueries",
385
+ "exists_subquery": "Extract EXISTS subqueries",
386
+ "in_subquery": "Extract IN subqueries",
387
+ "varchar_type": "Extract VARCHAR data types",
388
+ "decimal_type": "Extract DECIMAL data types",
389
+ "enum_type": "Extract ENUM data types",
390
+ "comment": "Extract all comments",
391
+ "line_comment": "Extract line comments (--)",
392
+ "block_comment": "Extract block comments (/* */)",
393
+ "table_name": "Extract table names only",
394
+ "view_name": "Extract view names only",
395
+ "procedure_name": "Extract procedure names only",
396
+ "function_name": "Extract function names only",
397
+ "trigger_name": "Extract trigger names only",
398
+ "index_name": "Extract index names only",
399
+ "column_name": "Extract column names only",
400
+ "stored_procedure_call": "Extract stored procedure calls",
401
+ "transaction": "Extract transaction statements",
402
+ "begin_transaction": "Extract BEGIN TRANSACTION statements",
403
+ "commit_transaction": "Extract COMMIT statements",
404
+ "rollback_transaction": "Extract ROLLBACK statements",
405
+ "auto_increment": "Extract AUTO_INCREMENT columns",
406
+ "default_value": "Extract columns with DEFAULT values",
407
+ "not_null": "Extract NOT NULL columns",
408
+ "error_node": "Extract ERROR nodes (parsing issues)",
409
+ "procedure_in_error": "Extract procedures that appear as ERROR nodes",
410
+ "function_in_error": "Extract functions that appear as ERROR nodes",
411
+ "trigger_in_error": "Extract triggers that appear as ERROR nodes",
412
+ }
413
+
414
+
415
+ def get_sql_query(name: str) -> str:
416
+ """
417
+ Get the specified SQL query
418
+
419
+ Args:
420
+ name: Query name
421
+
422
+ Returns:
423
+ Query string
424
+
425
+ Raises:
426
+ ValueError: When query is not found
427
+ """
428
+ if name not in SQL_QUERIES:
429
+ available = list(SQL_QUERIES.keys())
430
+ raise ValueError(f"SQL query '{name}' does not exist. Available: {available}")
431
+
432
+ return SQL_QUERIES[name]
433
+
434
+
435
+ def get_sql_query_description(name: str) -> str:
436
+ """
437
+ Get the description of the specified SQL query
438
+
439
+ Args:
440
+ name: Query name
441
+
442
+ Returns:
443
+ Query description
444
+ """
445
+ return SQL_QUERY_DESCRIPTIONS.get(name, "No description")
446
+
447
+
448
+ # Convert to ALL_QUERIES format for dynamic loader compatibility
449
+ ALL_QUERIES = {}
450
+ for query_name, query_string in SQL_QUERIES.items():
451
+ description = SQL_QUERY_DESCRIPTIONS.get(query_name, "No description")
452
+ ALL_QUERIES[query_name] = {"query": query_string, "description": description}
453
+
454
+ # Add common query aliases for cross-language compatibility
455
+ ALL_QUERIES["functions"] = {
456
+ "query": SQL_QUERIES["function"],
457
+ "description": "Search all function definitions (alias for function)",
458
+ }
459
+
460
+ ALL_QUERIES["procedures"] = {
461
+ "query": SQL_QUERIES["procedure"],
462
+ "description": "Search all procedure definitions (alias for procedure)",
463
+ }
464
+
465
+ ALL_QUERIES["tables"] = {
466
+ "query": SQL_QUERIES["table"],
467
+ "description": "Search all table definitions (alias for table)",
468
+ }
469
+
470
+ ALL_QUERIES["views"] = {
471
+ "query": SQL_QUERIES["view"],
472
+ "description": "Search all view definitions (alias for view)",
473
+ }
474
+
475
+ ALL_QUERIES["indexes"] = {
476
+ "query": SQL_QUERIES["index"],
477
+ "description": "Search all index definitions (alias for index)",
478
+ }
479
+
480
+ ALL_QUERIES["triggers"] = {
481
+ "query": SQL_QUERIES["trigger"],
482
+ "description": "Search all trigger definitions (alias for trigger)",
483
+ }
484
+
485
+ # Add comprehensive aliases
486
+ ALL_QUERIES["ddl_statements"] = {
487
+ "query": SQL_QUERIES["table"]
488
+ + "\n\n"
489
+ + SQL_QUERIES["view"]
490
+ + "\n\n"
491
+ + SQL_QUERIES["index"],
492
+ "description": "Search all DDL statements (tables, views, indexes)",
493
+ }
494
+
495
+ ALL_QUERIES["dml_statements"] = {
496
+ "query": SQL_QUERIES["select"]
497
+ + "\n\n"
498
+ + SQL_QUERIES["insert"]
499
+ + "\n\n"
500
+ + SQL_QUERIES["update"]
501
+ + "\n\n"
502
+ + SQL_QUERIES["delete"],
503
+ "description": "Search all DML statements (SELECT, INSERT, UPDATE, DELETE)",
504
+ }
505
+
506
+ ALL_QUERIES["constraints"] = {
507
+ "query": SQL_QUERIES["primary_key"]
508
+ + "\n\n"
509
+ + SQL_QUERIES["foreign_key"]
510
+ + "\n\n"
511
+ + SQL_QUERIES["unique_constraint"]
512
+ + "\n\n"
513
+ + SQL_QUERIES["check_constraint"],
514
+ "description": "Search all constraint definitions",
515
+ }
516
+
517
+ ALL_QUERIES["joins"] = {
518
+ "query": SQL_QUERIES["join"]
519
+ + "\n\n"
520
+ + SQL_QUERIES["inner_join"]
521
+ + "\n\n"
522
+ + SQL_QUERIES["left_join"]
523
+ + "\n\n"
524
+ + SQL_QUERIES["right_join"],
525
+ "description": "Search all JOIN clauses",
526
+ }
527
+
528
+
529
+ def get_query(name: str) -> str:
530
+ """Get a specific query by name."""
531
+ if name in ALL_QUERIES:
532
+ return ALL_QUERIES[name]["query"]
533
+ raise ValueError(
534
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
535
+ )
536
+
537
+
538
+ def get_all_queries() -> dict:
539
+ """Get all available queries."""
540
+ return ALL_QUERIES
541
+
542
+
543
+ def list_queries() -> list:
544
+ """List all available query names."""
545
+ return list(ALL_QUERIES.keys())
546
+
547
+
548
+ def get_available_sql_queries() -> list[str]:
549
+ """
550
+ Get list of available SQL queries
551
+
552
+ Returns:
553
+ List of query names
554
+ """
555
+ return list(SQL_QUERIES.keys())