@houtini/lm 1.0.13 → 2.0.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.
Files changed (262) hide show
  1. package/dist/index.d.ts +5 -3
  2. package/dist/index.js +142 -213
  3. package/dist/index.js.map +1 -1
  4. package/package.json +10 -33
  5. package/CHANGELOG.md +0 -282
  6. package/dist/cache/analysis-cache.d.ts +0 -33
  7. package/dist/cache/analysis-cache.d.ts.map +0 -1
  8. package/dist/cache/analysis-cache.js +0 -56
  9. package/dist/cache/analysis-cache.js.map +0 -1
  10. package/dist/cache/cache-manager.d.ts +0 -29
  11. package/dist/cache/cache-manager.d.ts.map +0 -1
  12. package/dist/cache/cache-manager.js +0 -85
  13. package/dist/cache/cache-manager.js.map +0 -1
  14. package/dist/cache/index.d.ts +0 -16
  15. package/dist/cache/index.d.ts.map +0 -1
  16. package/dist/cache/index.js +0 -17
  17. package/dist/cache/index.js.map +0 -1
  18. package/dist/cache/prompt-cache.d.ts +0 -33
  19. package/dist/cache/prompt-cache.d.ts.map +0 -1
  20. package/dist/cache/prompt-cache.js +0 -61
  21. package/dist/cache/prompt-cache.js.map +0 -1
  22. package/dist/config.d.ts +0 -41
  23. package/dist/config.d.ts.map +0 -1
  24. package/dist/config.js +0 -71
  25. package/dist/config.js.map +0 -1
  26. package/dist/core/ThreeStagePromptManager.d.ts +0 -23
  27. package/dist/core/ThreeStagePromptManager.d.ts.map +0 -1
  28. package/dist/core/ThreeStagePromptManager.js +0 -118
  29. package/dist/core/ThreeStagePromptManager.js.map +0 -1
  30. package/dist/index.d.ts.map +0 -1
  31. package/dist/plugins/base-plugin.d.ts +0 -55
  32. package/dist/plugins/base-plugin.d.ts.map +0 -1
  33. package/dist/plugins/base-plugin.js +0 -120
  34. package/dist/plugins/base-plugin.js.map +0 -1
  35. package/dist/plugins/index.d.ts +0 -58
  36. package/dist/plugins/index.d.ts.map +0 -1
  37. package/dist/plugins/index.js +0 -162
  38. package/dist/plugins/index.js.map +0 -1
  39. package/dist/plugins/types.d.ts +0 -5
  40. package/dist/plugins/types.d.ts.map +0 -1
  41. package/dist/plugins/types.js +0 -5
  42. package/dist/plugins/types.js.map +0 -1
  43. package/dist/prompts/analyze/code-quality.d.ts +0 -116
  44. package/dist/prompts/analyze/code-quality.d.ts.map +0 -1
  45. package/dist/prompts/analyze/code-quality.js +0 -437
  46. package/dist/prompts/analyze/code-quality.js.map +0 -1
  47. package/dist/prompts/analyze/compare-integration.d.ts +0 -130
  48. package/dist/prompts/analyze/compare-integration.d.ts.map +0 -1
  49. package/dist/prompts/analyze/compare-integration.js +0 -547
  50. package/dist/prompts/analyze/compare-integration.js.map +0 -1
  51. package/dist/prompts/analyze/count-files.d.ts +0 -109
  52. package/dist/prompts/analyze/count-files.d.ts.map +0 -1
  53. package/dist/prompts/analyze/count-files.js +0 -403
  54. package/dist/prompts/analyze/count-files.js.map +0 -1
  55. package/dist/prompts/analyze/database-queries.d.ts +0 -156
  56. package/dist/prompts/analyze/database-queries.d.ts.map +0 -1
  57. package/dist/prompts/analyze/database-queries.js +0 -763
  58. package/dist/prompts/analyze/database-queries.js.map +0 -1
  59. package/dist/prompts/analyze/dependencies.d.ts +0 -97
  60. package/dist/prompts/analyze/dependencies.d.ts.map +0 -1
  61. package/dist/prompts/analyze/dependencies.js +0 -337
  62. package/dist/prompts/analyze/dependencies.js.map +0 -1
  63. package/dist/prompts/analyze/diff-signatures.d.ts +0 -139
  64. package/dist/prompts/analyze/diff-signatures.d.ts.map +0 -1
  65. package/dist/prompts/analyze/diff-signatures.js +0 -708
  66. package/dist/prompts/analyze/diff-signatures.js.map +0 -1
  67. package/dist/prompts/analyze/find-patterns.d.ts +0 -128
  68. package/dist/prompts/analyze/find-patterns.d.ts.map +0 -1
  69. package/dist/prompts/analyze/find-patterns.js +0 -524
  70. package/dist/prompts/analyze/find-patterns.js.map +0 -1
  71. package/dist/prompts/analyze/find-unused-css.d.ts +0 -151
  72. package/dist/prompts/analyze/find-unused-css.d.ts.map +0 -1
  73. package/dist/prompts/analyze/find-unused-css.js +0 -760
  74. package/dist/prompts/analyze/find-unused-css.js.map +0 -1
  75. package/dist/prompts/analyze/n8n-workflow.d.ts +0 -137
  76. package/dist/prompts/analyze/n8n-workflow.d.ts.map +0 -1
  77. package/dist/prompts/analyze/n8n-workflow.js +0 -533
  78. package/dist/prompts/analyze/n8n-workflow.js.map +0 -1
  79. package/dist/prompts/analyze/project-structure.d.ts +0 -126
  80. package/dist/prompts/analyze/project-structure.d.ts.map +0 -1
  81. package/dist/prompts/analyze/project-structure.js +0 -573
  82. package/dist/prompts/analyze/project-structure.js.map +0 -1
  83. package/dist/prompts/analyze/security-audit.d.ts +0 -142
  84. package/dist/prompts/analyze/security-audit.d.ts.map +0 -1
  85. package/dist/prompts/analyze/security-audit.js +0 -641
  86. package/dist/prompts/analyze/security-audit.js.map +0 -1
  87. package/dist/prompts/analyze/single-file.d.ts +0 -162
  88. package/dist/prompts/analyze/single-file.d.ts.map +0 -1
  89. package/dist/prompts/analyze/single-file.js +0 -669
  90. package/dist/prompts/analyze/single-file.js.map +0 -1
  91. package/dist/prompts/analyze/trace-execution.d.ts +0 -126
  92. package/dist/prompts/analyze/trace-execution.d.ts.map +0 -1
  93. package/dist/prompts/analyze/trace-execution.js +0 -613
  94. package/dist/prompts/analyze/trace-execution.js.map +0 -1
  95. package/dist/prompts/analyze/wordpress-plugin-audit.d.ts +0 -116
  96. package/dist/prompts/analyze/wordpress-plugin-audit.d.ts.map +0 -1
  97. package/dist/prompts/analyze/wordpress-plugin-audit.js +0 -456
  98. package/dist/prompts/analyze/wordpress-plugin-audit.js.map +0 -1
  99. package/dist/prompts/analyze/wordpress-plugin-readiness.d.ts +0 -103
  100. package/dist/prompts/analyze/wordpress-plugin-readiness.d.ts.map +0 -1
  101. package/dist/prompts/analyze/wordpress-plugin-readiness.js +0 -506
  102. package/dist/prompts/analyze/wordpress-plugin-readiness.js.map +0 -1
  103. package/dist/prompts/analyze/wordpress-security.d.ts +0 -146
  104. package/dist/prompts/analyze/wordpress-security.d.ts.map +0 -1
  105. package/dist/prompts/analyze/wordpress-security.js +0 -702
  106. package/dist/prompts/analyze/wordpress-security.js.map +0 -1
  107. package/dist/prompts/analyze/wordpress-theme-audit.d.ts +0 -114
  108. package/dist/prompts/analyze/wordpress-theme-audit.d.ts.map +0 -1
  109. package/dist/prompts/analyze/wordpress-theme-audit.js +0 -540
  110. package/dist/prompts/analyze/wordpress-theme-audit.js.map +0 -1
  111. package/dist/prompts/custom/custom-prompt.d.ts +0 -135
  112. package/dist/prompts/custom/custom-prompt.d.ts.map +0 -1
  113. package/dist/prompts/custom/custom-prompt.js +0 -421
  114. package/dist/prompts/custom/custom-prompt.js.map +0 -1
  115. package/dist/prompts/fun/arcade-game.d.ts +0 -152
  116. package/dist/prompts/fun/arcade-game.d.ts.map +0 -1
  117. package/dist/prompts/fun/arcade-game.js +0 -657
  118. package/dist/prompts/fun/arcade-game.js.map +0 -1
  119. package/dist/prompts/fun/create_text_adventure.d.ts +0 -100
  120. package/dist/prompts/fun/create_text_adventure.d.ts.map +0 -1
  121. package/dist/prompts/fun/create_text_adventure.js +0 -401
  122. package/dist/prompts/fun/create_text_adventure.js.map +0 -1
  123. package/dist/prompts/fun/css-art-generator.d.ts +0 -168
  124. package/dist/prompts/fun/css-art-generator.d.ts.map +0 -1
  125. package/dist/prompts/fun/css-art-generator.js +0 -831
  126. package/dist/prompts/fun/css-art-generator.js.map +0 -1
  127. package/dist/prompts/generate/project-documentation.d.ts +0 -137
  128. package/dist/prompts/generate/project-documentation.d.ts.map +0 -1
  129. package/dist/prompts/generate/project-documentation.js +0 -670
  130. package/dist/prompts/generate/project-documentation.js.map +0 -1
  131. package/dist/prompts/generate/refactoring.d.ts +0 -164
  132. package/dist/prompts/generate/refactoring.d.ts.map +0 -1
  133. package/dist/prompts/generate/refactoring.js +0 -625
  134. package/dist/prompts/generate/refactoring.js.map +0 -1
  135. package/dist/prompts/generate/responsive-component.d.ts +0 -147
  136. package/dist/prompts/generate/responsive-component.d.ts.map +0 -1
  137. package/dist/prompts/generate/responsive-component.js +0 -957
  138. package/dist/prompts/generate/responsive-component.js.map +0 -1
  139. package/dist/prompts/generate/typescript-conversion.d.ts +0 -144
  140. package/dist/prompts/generate/typescript-conversion.d.ts.map +0 -1
  141. package/dist/prompts/generate/typescript-conversion.js +0 -531
  142. package/dist/prompts/generate/typescript-conversion.js.map +0 -1
  143. package/dist/prompts/generate/unit-tests.d.ts +0 -139
  144. package/dist/prompts/generate/unit-tests.d.ts.map +0 -1
  145. package/dist/prompts/generate/unit-tests.js +0 -582
  146. package/dist/prompts/generate/unit-tests.js.map +0 -1
  147. package/dist/prompts/generate/wordpress-plugin.d.ts +0 -179
  148. package/dist/prompts/generate/wordpress-plugin.d.ts.map +0 -1
  149. package/dist/prompts/generate/wordpress-plugin.js +0 -767
  150. package/dist/prompts/generate/wordpress-plugin.js.map +0 -1
  151. package/dist/prompts/generate/wordpress-theme-from-static.d.ts +0 -177
  152. package/dist/prompts/generate/wordpress-theme-from-static.d.ts.map +0 -1
  153. package/dist/prompts/generate/wordpress-theme-from-static.js +0 -699
  154. package/dist/prompts/generate/wordpress-theme-from-static.js.map +0 -1
  155. package/dist/prompts/shared/cache-manager.d.ts +0 -45
  156. package/dist/prompts/shared/cache-manager.d.ts.map +0 -1
  157. package/dist/prompts/shared/cache-manager.js +0 -129
  158. package/dist/prompts/shared/cache-manager.js.map +0 -1
  159. package/dist/prompts/shared/helpers.d.ts +0 -39
  160. package/dist/prompts/shared/helpers.d.ts.map +0 -1
  161. package/dist/prompts/shared/helpers.js +0 -151
  162. package/dist/prompts/shared/helpers.js.map +0 -1
  163. package/dist/prompts/shared/templates.d.ts +0 -35
  164. package/dist/prompts/shared/templates.d.ts.map +0 -1
  165. package/dist/prompts/shared/templates.js +0 -77
  166. package/dist/prompts/shared/templates.js.map +0 -1
  167. package/dist/prompts/shared/types.d.ts +0 -112
  168. package/dist/prompts/shared/types.d.ts.map +0 -1
  169. package/dist/prompts/shared/types.js +0 -5
  170. package/dist/prompts/shared/types.js.map +0 -1
  171. package/dist/prompts/system/find-unused-files.d.ts +0 -106
  172. package/dist/prompts/system/find-unused-files.d.ts.map +0 -1
  173. package/dist/prompts/system/find-unused-files.js +0 -357
  174. package/dist/prompts/system/find-unused-files.js.map +0 -1
  175. package/dist/security/index.d.ts +0 -39
  176. package/dist/security/index.d.ts.map +0 -1
  177. package/dist/security/index.js +0 -46
  178. package/dist/security/index.js.map +0 -1
  179. package/dist/security/integration-helpers.d.ts +0 -121
  180. package/dist/security/integration-helpers.d.ts.map +0 -1
  181. package/dist/security/integration-helpers.js +0 -190
  182. package/dist/security/integration-helpers.js.map +0 -1
  183. package/dist/security/output-encoder.d.ts +0 -94
  184. package/dist/security/output-encoder.d.ts.map +0 -1
  185. package/dist/security/output-encoder.js +0 -295
  186. package/dist/security/output-encoder.js.map +0 -1
  187. package/dist/security/prompt-injection-guard.d.ts +0 -59
  188. package/dist/security/prompt-injection-guard.d.ts.map +0 -1
  189. package/dist/security/prompt-injection-guard.js +0 -249
  190. package/dist/security/prompt-injection-guard.js.map +0 -1
  191. package/dist/security/sanitisation.d.ts +0 -67
  192. package/dist/security/sanitisation.d.ts.map +0 -1
  193. package/dist/security/sanitisation.js +0 -398
  194. package/dist/security/sanitisation.js.map +0 -1
  195. package/dist/security/security-service.d.ts +0 -103
  196. package/dist/security/security-service.d.ts.map +0 -1
  197. package/dist/security/security-service.js +0 -303
  198. package/dist/security/security-service.js.map +0 -1
  199. package/dist/security-config.d.ts +0 -45
  200. package/dist/security-config.d.ts.map +0 -1
  201. package/dist/security-config.js +0 -63
  202. package/dist/security-config.js.map +0 -1
  203. package/dist/system/function-list.d.ts +0 -61
  204. package/dist/system/function-list.d.ts.map +0 -1
  205. package/dist/system/function-list.js +0 -111
  206. package/dist/system/function-list.js.map +0 -1
  207. package/dist/system/function-registry.d.ts +0 -23
  208. package/dist/system/function-registry.d.ts.map +0 -1
  209. package/dist/system/function-registry.js +0 -136
  210. package/dist/system/function-registry.js.map +0 -1
  211. package/dist/system/health-check.d.ts +0 -33
  212. package/dist/system/health-check.d.ts.map +0 -1
  213. package/dist/system/health-check.js +0 -98
  214. package/dist/system/health-check.js.map +0 -1
  215. package/dist/system/path-resolver.d.ts +0 -55
  216. package/dist/system/path-resolver.d.ts.map +0 -1
  217. package/dist/system/path-resolver.js +0 -90
  218. package/dist/system/path-resolver.js.map +0 -1
  219. package/dist/templates/plugin-template.d.ts +0 -121
  220. package/dist/templates/plugin-template.d.ts.map +0 -1
  221. package/dist/templates/plugin-template.js +0 -454
  222. package/dist/templates/plugin-template.js.map +0 -1
  223. package/dist/types/chunking-types.d.ts +0 -88
  224. package/dist/types/chunking-types.d.ts.map +0 -1
  225. package/dist/types/chunking-types.js +0 -18
  226. package/dist/types/chunking-types.js.map +0 -1
  227. package/dist/types/prompt-stages.d.ts +0 -30
  228. package/dist/types/prompt-stages.d.ts.map +0 -1
  229. package/dist/types/prompt-stages.js +0 -6
  230. package/dist/types/prompt-stages.js.map +0 -1
  231. package/dist/types.d.ts +0 -45
  232. package/dist/types.d.ts.map +0 -1
  233. package/dist/types.js +0 -6
  234. package/dist/types.js.map +0 -1
  235. package/dist/utils/css-parser.d.ts +0 -26
  236. package/dist/utils/css-parser.d.ts.map +0 -1
  237. package/dist/utils/css-parser.js +0 -117
  238. package/dist/utils/css-parser.js.map +0 -1
  239. package/dist/utils/path-resolver.d.ts +0 -13
  240. package/dist/utils/path-resolver.d.ts.map +0 -1
  241. package/dist/utils/path-resolver.js +0 -78
  242. package/dist/utils/path-resolver.js.map +0 -1
  243. package/dist/utils/plugin-utilities.d.ts +0 -176
  244. package/dist/utils/plugin-utilities.d.ts.map +0 -1
  245. package/dist/utils/plugin-utilities.js +0 -269
  246. package/dist/utils/plugin-utilities.js.map +0 -1
  247. package/dist/utils/streamHandler.d.ts +0 -3
  248. package/dist/utils/streamHandler.d.ts.map +0 -1
  249. package/dist/utils/streamHandler.js +0 -137
  250. package/dist/utils/streamHandler.js.map +0 -1
  251. package/dist/validation/output-validator.d.ts +0 -136
  252. package/dist/validation/output-validator.d.ts.map +0 -1
  253. package/dist/validation/output-validator.js +0 -262
  254. package/dist/validation/output-validator.js.map +0 -1
  255. package/dist/validation/response-factory.d.ts +0 -44
  256. package/dist/validation/response-factory.d.ts.map +0 -1
  257. package/dist/validation/response-factory.js +0 -202
  258. package/dist/validation/response-factory.js.map +0 -1
  259. package/dist/validation/schemas.d.ts +0 -519
  260. package/dist/validation/schemas.d.ts.map +0 -1
  261. package/dist/validation/schemas.js +0 -6
  262. package/dist/validation/schemas.js.map +0 -1
@@ -1,763 +0,0 @@
1
- /**
2
- * Plugin Template - Modern v4.2 (Single Source of Truth)
3
- *
4
- * Universal template that intelligently handles both single-file and multi-file analysis
5
- * Automatically detects analysis type based on provided parameters
6
- *
7
- * Copy this template for creating any new plugin - it adapts to your needs
8
- */
9
- import { BasePlugin } from '../../plugins/base-plugin.js';
10
- import { ThreeStagePromptManager } from '../../core/ThreeStagePromptManager.js';
11
- import { withSecurity } from '../../security/integration-helpers.js';
12
- import { readFileContent } from '../shared/helpers.js';
13
- import { ModelSetup, ResponseProcessor, ParameterValidator, ErrorHandler, MultiFileAnalysis, TokenCalculator } from '../../utils/plugin-utilities.js';
14
- import { getAnalysisCache } from '../../cache/index.js';
15
- // Common Node.js modules - Use these instead of require()
16
- import { basename, extname, relative } from 'path';
17
- import { readFile, stat } from 'fs/promises';
18
- export class DatabaseQueryAnalyzer extends BasePlugin {
19
- constructor() {
20
- super();
21
- this.name = 'analyze_database_queries';
22
- this.category = 'analyze';
23
- this.description = 'Analyze database queries for performance, security, and best practices in code files or entire projects';
24
- // Universal parameter set - supports both single and multi-file scenarios
25
- this.parameters = {
26
- // Single-file parameters
27
- code: {
28
- type: 'string',
29
- description: 'The code to analyze for database queries (for single-file analysis)',
30
- required: false
31
- },
32
- filePath: {
33
- type: 'string',
34
- description: 'Path to single file to analyze for database queries',
35
- required: false
36
- },
37
- // Multi-file parameters
38
- projectPath: {
39
- type: 'string',
40
- description: 'Path to project root (for multi-file database analysis)',
41
- required: false
42
- },
43
- files: {
44
- type: 'array',
45
- description: 'Array of specific file paths (for multi-file analysis)',
46
- required: false,
47
- items: { type: 'string' }
48
- },
49
- maxDepth: {
50
- type: 'number',
51
- description: 'Maximum directory depth for multi-file discovery (1-5)',
52
- required: false,
53
- default: 3
54
- },
55
- // Universal parameters
56
- language: {
57
- type: 'string',
58
- description: 'Programming language',
59
- required: false,
60
- default: 'php'
61
- },
62
- analysisDepth: {
63
- type: 'string',
64
- description: 'Level of analysis detail',
65
- enum: ['basic', 'detailed', 'comprehensive'],
66
- default: 'detailed',
67
- required: false
68
- },
69
- analysisType: {
70
- type: 'string',
71
- description: 'Type of database analysis to perform',
72
- enum: ['security', 'performance', 'best-practices', 'comprehensive'],
73
- default: 'comprehensive',
74
- required: false
75
- },
76
- // Database-specific parameters
77
- context: {
78
- type: 'object',
79
- description: 'Database and framework context for specialized analysis',
80
- required: false,
81
- properties: {
82
- database: {
83
- type: 'string',
84
- enum: ['mysql', 'postgresql', 'sqlite', 'mongodb', 'generic'],
85
- description: 'Database engine for engine-specific optimizations'
86
- },
87
- framework: {
88
- type: 'string',
89
- enum: ['wordpress', 'laravel', 'symfony', 'django', 'rails', 'express', 'generic'],
90
- description: 'Framework for framework-specific query patterns'
91
- },
92
- orm: {
93
- type: 'string',
94
- enum: ['eloquent', 'doctrine', 'sequelize', 'mongoose', 'activerecord', 'none'],
95
- description: 'ORM/Query builder being used'
96
- },
97
- environment: {
98
- type: 'string',
99
- enum: ['development', 'staging', 'production'],
100
- description: 'Environment context for performance recommendations'
101
- }
102
- }
103
- }
104
- };
105
- this.analysisCache = getAnalysisCache();
106
- this.multiFileAnalysis = new MultiFileAnalysis();
107
- // Cache and analysis utilities are initialized above
108
- }
109
- async execute(params, llmClient) {
110
- return await withSecurity(this, params, llmClient, async (secureParams) => {
111
- try {
112
- // 1. Auto-detect analysis mode based on parameters
113
- const analysisMode = this.detectAnalysisMode(secureParams);
114
- // 2. Validate parameters based on detected mode
115
- this.validateParameters(secureParams, analysisMode);
116
- // 3. Setup model
117
- const { model, contextLength } = await ModelSetup.getReadyModel(llmClient);
118
- // 4. Route to appropriate analysis method
119
- if (analysisMode === 'single-file') {
120
- return await this.executeSingleFileAnalysis(secureParams, model, contextLength);
121
- }
122
- else {
123
- return await this.executeMultiFileAnalysis(secureParams, model, contextLength);
124
- }
125
- }
126
- catch (error) {
127
- return ErrorHandler.createExecutionError('analyze_database_queries', error);
128
- }
129
- });
130
- }
131
- /**
132
- * Auto-detect whether this is single-file or multi-file analysis
133
- */
134
- detectAnalysisMode(params) {
135
- // Single-file indicators take priority
136
- if (params.code || params.filePath) {
137
- return 'single-file';
138
- }
139
- // Multi-file indicators
140
- if (params.projectPath || params.files) {
141
- return 'multi-file';
142
- }
143
- // Default to single-file for focused query analysis
144
- return 'single-file';
145
- }
146
- /**
147
- * Validate parameters based on detected analysis mode
148
- */
149
- validateParameters(params, mode) {
150
- if (mode === 'single-file') {
151
- ParameterValidator.validateCodeOrFile(params);
152
- }
153
- else {
154
- ParameterValidator.validateProjectPath(params);
155
- ParameterValidator.validateDepth(params);
156
- }
157
- // Universal validations
158
- ParameterValidator.validateEnum(params, 'analysisType', ['security', 'performance', 'best-practices', 'comprehensive']);
159
- ParameterValidator.validateEnum(params, 'analysisDepth', ['basic', 'detailed', 'comprehensive']);
160
- }
161
- /**
162
- * Execute single-file analysis
163
- */
164
- async executeSingleFileAnalysis(params, model, contextLength) {
165
- // Process single file input
166
- let codeToAnalyze = params.code;
167
- if (params.filePath) {
168
- codeToAnalyze = await readFileContent(params.filePath);
169
- }
170
- // Extract database queries from the code
171
- const extractedQueries = this.extractDatabaseQueries(codeToAnalyze, params.language, params.context);
172
- // Generate prompt stages for single file
173
- const promptStages = this.getSingleFilePromptStages({
174
- ...params,
175
- code: codeToAnalyze,
176
- extractedQueries
177
- });
178
- // Execute with appropriate method
179
- const promptManager = new ThreeStagePromptManager();
180
- const needsChunking = TokenCalculator.needsChunking(promptStages, contextLength);
181
- if (needsChunking) {
182
- const chunkSize = TokenCalculator.calculateOptimalChunkSize(promptStages, contextLength);
183
- const dataChunks = promptManager.chunkDataPayload(promptStages.dataPayload, chunkSize);
184
- const conversation = promptManager.createChunkedConversation(promptStages, dataChunks);
185
- const messages = [
186
- conversation.systemMessage,
187
- ...conversation.dataMessages,
188
- conversation.analysisMessage
189
- ];
190
- return await ResponseProcessor.executeChunked(messages, model, contextLength, 'analyze_database_queries', 'single');
191
- }
192
- else {
193
- return await ResponseProcessor.executeDirect(promptStages, model, contextLength, 'analyze_database_queries');
194
- }
195
- }
196
- /**
197
- * Execute multi-file analysis
198
- */
199
- async executeMultiFileAnalysis(params, model, contextLength) {
200
- // Discover files
201
- let filesToAnalyze = params.files ||
202
- await this.discoverRelevantFiles(params.projectPath, params.maxDepth, params.analysisType);
203
- // Perform multi-file analysis with caching
204
- const analysisResult = await this.performMultiFileAnalysis(filesToAnalyze, params, model, contextLength);
205
- // Generate prompt stages for multi-file
206
- const promptStages = this.getMultiFilePromptStages({
207
- ...params,
208
- analysisResult,
209
- fileCount: filesToAnalyze.length
210
- });
211
- // Always use chunking for multi-file
212
- const promptManager = new ThreeStagePromptManager();
213
- const chunkSize = TokenCalculator.calculateOptimalChunkSize(promptStages, contextLength);
214
- const dataChunks = promptManager.chunkDataPayload(promptStages.dataPayload, chunkSize);
215
- const conversation = promptManager.createChunkedConversation(promptStages, dataChunks);
216
- const messages = [
217
- conversation.systemMessage,
218
- ...conversation.dataMessages,
219
- conversation.analysisMessage
220
- ];
221
- return await ResponseProcessor.executeChunked(messages, model, contextLength, 'analyze_database_queries', 'multifile');
222
- }
223
- /**
224
- * Database Query Analysis - Single File Expert Analysis
225
- */
226
- getSingleFilePromptStages(params) {
227
- const { code, language, analysisDepth, analysisType, extractedQueries, filePath, context = {} } = params;
228
- const database = context.database || 'generic';
229
- const framework = context.framework || 'generic';
230
- const orm = context.orm || 'none';
231
- const environment = context.environment || 'production';
232
- const systemAndContext = `You are a world-class database performance expert and security specialist with 20+ years of experience optimizing database queries across all major platforms.
233
-
234
- **DATABASE ANALYSIS CONTEXT:**
235
- - Database Engine: ${database}
236
- - Framework: ${framework}
237
- - ORM/Query Builder: ${orm}
238
- - Programming Language: ${language}
239
- - Environment: ${environment}
240
- - Analysis Focus: ${analysisType}
241
- - Analysis Depth: ${analysisDepth}
242
- - File: ${filePath ? basename(filePath) : 'inline code'}
243
-
244
- **YOUR EXPERTISE:**
245
- You are recognized as a leading expert in:
246
- - SQL query optimization and execution plan analysis
247
- - Database security and injection prevention
248
- - Framework-specific query patterns (WordPress $wpdb, Laravel Eloquent, etc.)
249
- - Performance bottleneck identification and resolution
250
- - Index strategy and database schema optimization
251
- - N+1 query problem detection and solutions
252
- - Query caching strategies and implementation
253
- - Database-specific optimization techniques for ${database}
254
-
255
- ${this.getDatabaseSpecificInstructions(database, framework, orm)}
256
-
257
- **ANALYSIS APPROACH:**
258
- 1. **Query Detection**: Identify all database queries in the code
259
- 2. **Security Assessment**: Evaluate for SQL injection vulnerabilities
260
- 3. **Performance Analysis**: Identify bottlenecks, N+1 problems, and optimization opportunities
261
- 4. **Best Practices Review**: Check against framework and database best practices
262
- 5. **Actionable Recommendations**: Provide specific, implementable improvements with examples
263
-
264
- You provide expert-level analysis that helps developers write secure, performant database code.`;
265
- const dataPayload = `**CODE WITH DATABASE QUERIES:**
266
-
267
- \`\`\`${language}
268
- ${code}
269
- \`\`\`
270
-
271
- **EXTRACTED DATABASE QUERIES:**
272
- ${extractedQueries.length > 0 ?
273
- extractedQueries.map((query, index) => `**Query ${index + 1}** (Line ${query.line}):\n\`\`\`sql\n${query.query}\n\`\`\`\nContext: ${query.context}\n`).join('\n') :
274
- 'No explicit database queries detected. Analyzing for potential query patterns and ORM usage.'}
275
-
276
- ${filePath ? `\n**File Path:** ${filePath}` : ''}`;
277
- const outputInstructions = `**PROVIDE COMPREHENSIVE DATABASE QUERY ANALYSIS:**
278
-
279
- ## Executive Summary
280
- Provide a 2-3 sentence overview of database usage, query patterns, and main security/performance concerns found in this file.
281
-
282
- ## Query Analysis Overview
283
- - **Total Queries Found**: Count of database queries identified in the code
284
- - **Query Types**: Breakdown of query types (SELECT, INSERT, UPDATE, DELETE, etc.)
285
- - **Complex Queries**: Identification of complex queries that need attention
286
- - **Dynamic Queries**: Queries built dynamically at runtime
287
-
288
- ## Security Analysis
289
- For each security finding:
290
- - **Vulnerability Type**: SQL injection, prepared statements, input validation, etc.
291
- - **Severity Level**: Critical, high, medium, or low priority
292
- - **Vulnerable Query**: The specific problematic query
293
- - **Location**: Line number and context
294
- - **Security Risk**: Detailed description of the security issue
295
- - **Exploit Scenario**: How this vulnerability could be exploited
296
- - **Fix Recommendation**: Specific fix with secure code example
297
- - **Implementation**: Example of secure implementation
298
-
299
- ## Performance Analysis
300
- For each performance issue:
301
- - **Performance Problem**: N+1 queries, missing indexes, inefficient queries, excessive joins
302
- - **Impact Level**: Critical, high, medium, or low performance impact
303
- - **Problematic Query**: The query causing performance issues
304
- - **Location**: Line number and context
305
- "issue": "Detailed performance issue description",
306
- "impact": "Performance impact (queries/second, memory usage)",
307
- "optimization": "Specific optimization strategy",
308
- "optimizedQuery": "Improved query example"
309
- }
310
- ],
311
-
312
- "bestPracticeViolations": [
313
- {
314
- "practice": "Best practice being violated",
315
- "line": 78,
316
- "current": "Current implementation",
317
- "recommended": "Recommended implementation",
318
- "benefit": "Why this improvement matters"
319
- }
320
- ],
321
-
322
- "recommendations": {
323
- "immediate": [
324
- "Critical security fix 1",
325
- "Critical performance fix 1"
326
- ],
327
- "shortTerm": [
328
- "Performance optimization 1",
329
- "Code quality improvement 1"
330
- ],
331
- "longTerm": [
332
- "Architectural improvement 1",
333
- "Scalability enhancement 1"
334
- ]
335
- },
336
-
337
- "codeExamples": {
338
- "before": "// Current problematic database code",
339
- "after": "// Optimized and secure version",
340
- "explanation": "Why this improvement enhances security and performance"
341
- },
342
-
343
- "indexRecommendations": [
344
- {
345
- "table": "table_name",
346
- "columns": ["column1", "column2"],
347
- "type": "btree|hash|partial",
348
- "reasoning": "Why this index improves performance"
349
- }
350
- ],
351
-
352
- "metrics": {
353
- "estimatedQueriesPerRequest": 5,
354
- "potentialBottlenecks": 2,
355
- "securityRiskLevel": "high|medium|low",
356
- "optimizationPotential": "high|medium|low"
357
- },
358
-
359
- "confidence": 0.92
360
- }
361
-
362
- **CRITICAL REQUIREMENTS:**
363
- - Focus on real, exploitable security vulnerabilities
364
- - Provide specific query optimizations with measurable impact
365
- - Include framework-specific best practices for ${framework}
366
- - Consider ${database}-specific optimization techniques
367
- - Prioritize fixes by impact and implementation difficulty`;
368
- return { systemAndContext, dataPayload, outputInstructions };
369
- }
370
- /**
371
- * Multi-file database analysis for project-wide query patterns
372
- */
373
- getMultiFilePromptStages(params) {
374
- const { analysisResult, analysisType, analysisDepth, fileCount, context = {} } = params;
375
- const database = context.database || 'generic';
376
- const framework = context.framework || 'generic';
377
- const systemAndContext = `You are a senior database architect specializing in ${analysisDepth} multi-file database analysis and optimization.
378
-
379
- **PROJECT DATABASE ANALYSIS CONTEXT:**
380
- - Database Engine: ${database}
381
- - Framework: ${framework}
382
- - Analysis Type: ${analysisType}
383
- - Analysis Depth: ${analysisDepth}
384
- - Files Analyzed: ${fileCount}
385
- - Mode: Multi-File Database Architecture Analysis
386
-
387
- **YOUR EXPERTISE:**
388
- You excel at identifying cross-file database patterns, architectural issues, and system-wide database optimization opportunities. You understand how queries interact across modules, transaction boundaries, and data consistency patterns.
389
-
390
- **FOCUS AREAS:**
391
- - Cross-file query patterns and duplication
392
- - Database transaction boundaries and consistency
393
- - Query performance across the application
394
- - Security patterns and vulnerabilities at scale
395
- - Database schema utilization and optimization opportunities`;
396
- const dataPayload = `**PROJECT DATABASE ANALYSIS RESULTS:**
397
-
398
- ${JSON.stringify(analysisResult, null, 2)}`;
399
- const outputInstructions = `**PROVIDE PROJECT-WIDE DATABASE ANALYSIS:**
400
-
401
- ## Executive Summary
402
- Overall assessment of database usage patterns, architecture quality, and system-wide security/performance concerns across the project.
403
-
404
- ## Database Architecture Analysis
405
- - **Query Patterns**: Common patterns used throughout the project
406
- - **Data Access Layers**: How database access is organized across files
407
- - **Transaction Boundaries**: Transaction management patterns across the system
408
- - **Consistency Approach**: Eventual, strong, or mixed consistency patterns
409
-
410
- ## Cross-File Analysis
411
- For each system-wide issue identified:
412
- - **Issue Type**: Query duplication, transaction issues, N+1 patterns, security patterns
413
- - **Severity Impact**: Critical, high, medium, or low system impact
414
- - **Issue Title**: Descriptive name for the cross-file issue
415
- - **Description**: Detailed explanation of the system-wide problem
416
- - **Affected Files**: List of files involved in this issue
417
- - **System Impact**: How this affects overall performance/security
418
- - **Resolution Strategy**: System-wide fix approach
419
-
420
- ## Performance Architecture
421
- - **Query Distribution**: How database queries are distributed across the codebase
422
- - **Bottleneck Patterns**: Common performance bottlenecks across files
423
- - **Caching Strategy**: Current approach to database result caching
424
- - **Optimization Opportunities**: System-wide performance improvements
425
-
426
- ## Security Architecture
427
- - **Input Validation Patterns**: Consistency of input validation (consistent/inconsistent/missing)
428
- - **Prepared Statement Usage**: Overall usage of prepared statements (high/medium/low)
429
- - **Privilege Patterns**: Common privilege and access control patterns
430
- - **High Risk Areas**: Areas requiring immediate security attention
431
-
432
- ## System-Wide Recommendations
433
- - **Architecture Improvements**: Database architecture enhancements
434
- - **Performance Optimizations**: System-wide performance improvements
435
- - **Security Enhancements**: Security strengthening recommendations
436
- - **Maintainability Improvements**: Long-term maintenance considerations
437
-
438
- Focus on actionable recommendations that improve overall database architecture, performance, and security across the entire project.`;
439
- return { systemAndContext, dataPayload, outputInstructions };
440
- }
441
- /**
442
- * Backwards compatibility method
443
- */
444
- getPromptStages(params) {
445
- const mode = this.detectAnalysisMode(params);
446
- if (mode === 'single-file') {
447
- return this.getSingleFilePromptStages(params);
448
- }
449
- else {
450
- return this.getMultiFilePromptStages(params);
451
- }
452
- }
453
- // Multi-file helper methods
454
- async discoverRelevantFiles(projectPath, maxDepth, analysisType) {
455
- const extensions = this.getFileExtensions(analysisType);
456
- return await this.multiFileAnalysis.discoverFiles(projectPath, extensions, maxDepth);
457
- }
458
- async performMultiFileAnalysis(files, params, model, contextLength) {
459
- const cacheKey = this.analysisCache.generateKey('analyze_database_queries', params, files);
460
- const cached = await this.analysisCache.get(cacheKey);
461
- if (cached)
462
- return cached;
463
- const fileAnalysisResults = await this.multiFileAnalysis.analyzeBatch(files, (file) => this.analyzeIndividualFile(file, params, model), contextLength);
464
- // Aggregate database-specific results
465
- const aggregatedResult = {
466
- summary: `Multi-file database analysis of ${files.length} files`,
467
- findings: fileAnalysisResults,
468
- database: this.analyzeDatabasePatterns(fileAnalysisResults),
469
- queries: this.aggregateQueryAnalysis(fileAnalysisResults),
470
- security: this.aggregateSecurityFindings(fileAnalysisResults),
471
- performance: this.aggregatePerformanceFindings(fileAnalysisResults),
472
- data: {
473
- fileCount: files.length,
474
- totalQueries: fileAnalysisResults.reduce((sum, result) => sum + (result.queryCount || 0), 0),
475
- riskLevel: this.calculateRiskLevel(fileAnalysisResults),
476
- frameworks: this.identifyDatabaseFrameworks(fileAnalysisResults)
477
- }
478
- };
479
- await this.analysisCache.cacheAnalysis(cacheKey, aggregatedResult, {
480
- modelUsed: model.identifier || 'unknown',
481
- executionTime: Date.now(),
482
- timestamp: new Date().toISOString()
483
- });
484
- return aggregatedResult;
485
- }
486
- async analyzeIndividualFile(file, params, model) {
487
- const content = await readFile(file, 'utf-8');
488
- const stats = await stat(file);
489
- const queries = this.extractDatabaseQueries(content, params.language, params.context);
490
- return {
491
- filePath: file,
492
- fileName: basename(file),
493
- size: content.length,
494
- lines: content.split('\n').length,
495
- extension: extname(file),
496
- relativePath: relative(params.projectPath || '', file),
497
- // Database-specific analysis
498
- queryCount: queries.length,
499
- queries: queries,
500
- databaseCalls: this.countDatabaseCalls(content),
501
- securityRisks: this.identifySecurityRisks(queries),
502
- performanceIssues: this.identifyPerformanceIssues(queries),
503
- modified: stats.mtime
504
- };
505
- }
506
- /**
507
- * Extract database queries from code using patterns for different languages/frameworks
508
- */
509
- extractDatabaseQueries(code, language = 'php', context = {}) {
510
- const queries = [];
511
- const lines = code.split('\n');
512
- // WordPress $wpdb patterns
513
- const wpdbPatterns = [
514
- /\$wpdb->query\s*\(\s*['"](.*?)['"].*?\)/gi,
515
- /\$wpdb->get_results\s*\(\s*['"](.*?)['"].*?\)/gi,
516
- /\$wpdb->get_var\s*\(\s*['"](.*?)['"].*?\)/gi,
517
- /\$wpdb->get_row\s*\(\s*['"](.*?)['"].*?\)/gi,
518
- /\$wpdb->prepare\s*\(\s*['"](.*?)['"].*?\)/gi
519
- ];
520
- // Raw SQL patterns
521
- const sqlPatterns = [
522
- /(SELECT\s+.*?FROM\s+.*?)(?=;|\s*$|\s*\))/gis,
523
- /(INSERT\s+INTO\s+.*?)(?=;|\s*$|\s*\))/gis,
524
- /(UPDATE\s+.*?SET\s+.*?)(?=;|\s*$|\s*\))/gis,
525
- /(DELETE\s+FROM\s+.*?)(?=;|\s*$|\s*\))/gis
526
- ];
527
- // Laravel Eloquent patterns
528
- const eloquentPatterns = [
529
- /DB::select\s*\(\s*['"](.*?)['"].*?\)/gi,
530
- /DB::insert\s*\(\s*['"](.*?)['"].*?\)/gi,
531
- /DB::update\s*\(\s*['"](.*?)['"].*?\)/gi,
532
- /DB::delete\s*\(\s*['"](.*?)['"].*?\)/gi
533
- ];
534
- const patterns = [...wpdbPatterns, ...sqlPatterns, ...eloquentPatterns];
535
- lines.forEach((line, index) => {
536
- patterns.forEach(pattern => {
537
- let match;
538
- pattern.lastIndex = 0; // Reset regex
539
- while ((match = pattern.exec(line)) !== null) {
540
- queries.push({
541
- query: match[1] || match[0],
542
- line: index + 1,
543
- context: this.getQueryContext(line),
544
- type: this.getQueryType(match[1] || match[0]),
545
- framework: this.detectQueryFramework(line)
546
- });
547
- }
548
- });
549
- });
550
- return queries;
551
- }
552
- getQueryContext(line) {
553
- if (line.includes('$wpdb'))
554
- return 'WordPress';
555
- if (line.includes('DB::'))
556
- return 'Laravel';
557
- if (line.includes('query(') || line.includes('execute('))
558
- return 'Direct SQL';
559
- return 'Unknown';
560
- }
561
- getQueryType(query) {
562
- if (/^SELECT/i.test(query.trim()))
563
- return 'SELECT';
564
- if (/^INSERT/i.test(query.trim()))
565
- return 'INSERT';
566
- if (/^UPDATE/i.test(query.trim()))
567
- return 'UPDATE';
568
- if (/^DELETE/i.test(query.trim()))
569
- return 'DELETE';
570
- return 'OTHER';
571
- }
572
- detectQueryFramework(line) {
573
- if (line.includes('$wpdb'))
574
- return 'WordPress';
575
- if (line.includes('DB::'))
576
- return 'Laravel';
577
- if (line.includes('PDO'))
578
- return 'PDO';
579
- return 'Generic';
580
- }
581
- countDatabaseCalls(content) {
582
- const dbCallPatterns = [
583
- /\$wpdb->/g,
584
- /DB::/g,
585
- /->query\(/g,
586
- /->execute\(/g,
587
- /mysqli_/g,
588
- /pg_query/g
589
- ];
590
- return dbCallPatterns.reduce((count, pattern) => {
591
- const matches = content.match(pattern) || [];
592
- return count + matches.length;
593
- }, 0);
594
- }
595
- identifySecurityRisks(queries) {
596
- const risks = [];
597
- queries.forEach(query => {
598
- // Check for potential SQL injection
599
- if (query.query.includes('$') && !query.query.includes('prepare')) {
600
- risks.push('Potential SQL injection vulnerability');
601
- }
602
- // Check for dynamic query construction
603
- if (query.query.includes('{') || query.query.includes('}')) {
604
- risks.push('Dynamic query construction detected');
605
- }
606
- // Check for missing prepared statements
607
- if (query.framework === 'WordPress' && !query.context.includes('prepare')) {
608
- risks.push('Unprepared WordPress query');
609
- }
610
- });
611
- return [...new Set(risks)]; // Remove duplicates
612
- }
613
- identifyPerformanceIssues(queries) {
614
- const issues = [];
615
- queries.forEach(query => {
616
- // Check for SELECT *
617
- if (query.query.includes('SELECT *')) {
618
- issues.push('SELECT * usage detected');
619
- }
620
- // Check for missing WHERE clauses in UPDATE/DELETE
621
- if ((query.type === 'UPDATE' || query.type === 'DELETE') && !query.query.includes('WHERE')) {
622
- issues.push('Missing WHERE clause in destructive operation');
623
- }
624
- // Check for potential N+1 queries (simple heuristic)
625
- if (query.context.includes('foreach') || query.context.includes('for (')) {
626
- issues.push('Potential N+1 query pattern');
627
- }
628
- });
629
- return [...new Set(issues)];
630
- }
631
- // Database-specific aggregation methods
632
- analyzeDatabasePatterns(results) {
633
- return {
634
- totalQueries: results.reduce((sum, r) => sum + (r.queryCount || 0), 0),
635
- frameworks: this.identifyDatabaseFrameworks(results),
636
- queryTypes: this.aggregateQueryTypes(results)
637
- };
638
- }
639
- aggregateQueryAnalysis(results) {
640
- const allQueries = results.flatMap(r => r.queries || []);
641
- return {
642
- total: allQueries.length,
643
- byType: this.groupBy(allQueries, 'type'),
644
- byFramework: this.groupBy(allQueries, 'framework')
645
- };
646
- }
647
- aggregateSecurityFindings(results) {
648
- const allRisks = results.flatMap(r => r.securityRisks || []);
649
- return {
650
- totalRisks: allRisks.length,
651
- riskTypes: this.countOccurrences(allRisks)
652
- };
653
- }
654
- aggregatePerformanceFindings(results) {
655
- const allIssues = results.flatMap(r => r.performanceIssues || []);
656
- return {
657
- totalIssues: allIssues.length,
658
- issueTypes: this.countOccurrences(allIssues)
659
- };
660
- }
661
- calculateRiskLevel(results) {
662
- const totalRisks = results.reduce((sum, r) => sum + (r.securityRisks?.length || 0), 0);
663
- if (totalRisks > 10)
664
- return 'high';
665
- if (totalRisks > 5)
666
- return 'medium';
667
- return 'low';
668
- }
669
- identifyDatabaseFrameworks(results) {
670
- const frameworks = new Set();
671
- results.forEach(result => {
672
- if (result.queries) {
673
- result.queries.forEach((query) => {
674
- frameworks.add(query.framework);
675
- });
676
- }
677
- });
678
- return Array.from(frameworks);
679
- }
680
- aggregateQueryTypes(results) {
681
- const types = {};
682
- results.forEach(result => {
683
- if (result.queries) {
684
- result.queries.forEach((query) => {
685
- types[query.type] = (types[query.type] || 0) + 1;
686
- });
687
- }
688
- });
689
- return types;
690
- }
691
- groupBy(array, key) {
692
- return array.reduce((groups, item) => {
693
- const group = item[key] || 'unknown';
694
- groups[group] = (groups[group] || 0) + 1;
695
- return groups;
696
- }, {});
697
- }
698
- countOccurrences(array) {
699
- return array.reduce((counts, item) => {
700
- counts[item] = (counts[item] || 0) + 1;
701
- return counts;
702
- }, {});
703
- }
704
- getFileExtensions(analysisType) {
705
- const extensionMap = {
706
- 'security': ['.php', '.js', '.ts', '.py', '.rb', '.java', '.cs', '.sql'],
707
- 'performance': ['.php', '.js', '.ts', '.py', '.rb', '.java', '.cs', '.sql'],
708
- 'best-practices': ['.php', '.js', '.ts', '.py', '.rb', '.java', '.cs', '.sql'],
709
- 'comprehensive': ['.php', '.js', '.ts', '.py', '.rb', '.java', '.cs', '.sql', '.jsp', '.asp', '.aspx']
710
- };
711
- return extensionMap[analysisType] || extensionMap.comprehensive;
712
- }
713
- /**
714
- * Database and framework-specific expert instructions
715
- */
716
- getDatabaseSpecificInstructions(database, framework, orm) {
717
- const instructions = {
718
- 'wordpress': `
719
- **WORDPRESS DATABASE EXPERTISE:**
720
- - $wpdb best practices: Always use $wpdb->prepare() for dynamic queries
721
- - WordPress query functions: get_results(), get_var(), get_row(), get_col()
722
- - Custom table naming: Use $wpdb->prefix for table prefixes
723
- - Caching integration: wp_cache_* functions for query result caching
724
- - Security: Validate and sanitize all input, use wpdb::esc_like() for LIKE queries
725
- - Performance: Avoid queries in loops, use WP_Query efficiently, leverage object caching
726
- - Schema: Follow WordPress database schema conventions, use dbDelta() for table creation`,
727
- 'laravel': `
728
- **LARAVEL DATABASE EXPERTISE:**
729
- - Eloquent ORM: Use relationships to avoid N+1 queries, eager loading with with()
730
- - Query Builder: DB::table() with proper parameter binding
731
- - Raw queries: Always use DB::select() with parameter binding, never string concatenation
732
- - Migrations: Use Schema builder for database changes, maintain rollback capability
733
- - Performance: Query scopes, database indexes, query caching with Redis/Memcached
734
- - Security: Always use parameter binding, validate inputs with Form Requests
735
- - Transactions: Use DB::transaction() for data consistency`,
736
- 'django': `
737
- **DJANGO DATABASE EXPERTISE:**
738
- - ORM QuerySets: Use select_related() and prefetch_related() to minimize queries
739
- - Raw SQL: Always use parameterized queries, never string formatting
740
- - Migrations: Use Django migrations for schema changes
741
- - Performance: Database indexes, QuerySet optimization, database connection pooling
742
- - Security: Django ORM provides SQL injection protection by default
743
- - Caching: Use Django's cache framework for query result caching`,
744
- 'generic': `
745
- **GENERAL DATABASE EXPERTISE:**
746
- - Always use prepared statements or parameterized queries
747
- - Validate and sanitize all user inputs before database operations
748
- - Use appropriate indexes for query performance
749
- - Avoid SELECT * and fetch only required columns
750
- - Implement proper error handling and logging
751
- - Use transactions for data consistency
752
- - Consider connection pooling for high-traffic applications`
753
- };
754
- return instructions[framework] || instructions[database] || instructions.generic;
755
- }
756
- generateCacheKey(files, params) {
757
- const fileHash = files.join('|');
758
- const paramHash = JSON.stringify(params);
759
- return `${fileHash}_${paramHash}`.substring(0, 64);
760
- }
761
- }
762
- export default DatabaseQueryAnalyzer;
763
- //# sourceMappingURL=database-queries.js.map