Repository navigation
[Feature] Add SQL editor page - #549
Conversation
WalkthroughAdds a frontend SQL Editor feature: a reusable CodeEditor, a SQLEditorPage to run raw SQL, a client AdvanceService and useRawSQL hook, DataGrid padding option, sidebar navigation, and dependency/version updates. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant SQLEditor as SQLEditorPage
participant Hook as useRawSQL Hook
participant Service as AdvanceService
participant API as Backend API
participant Store as LocalStorage
User->>SQLEditor: Type SQL query
SQLEditor->>Store: Persist query (localStorage)
User->>SQLEditor: Click Run
SQLEditor->>Hook: executeSQL(query)
Hook->>Service: runRawSQL(query, params)
Service->>API: POST /database/advance/rawsql
alt Success
API-->>Service: RawSQLResponse
Service-->>Hook: return data
Hook->>SQLEditor: update data (isSuccess)
SQLEditor->>SQLEditor: detect tabular vs JSON
alt Tabular
SQLEditor->>SQLEditor: render DataGrid
else JSON
SQLEditor->>SQLEditor: render formatted JSON
end
else Error
API-->>Service: error
Service-->>Hook: throw
Hook->>SQLEditor: update error (isError)
SQLEditor->>User: display error
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (11)
frontend/package.json(2 hunks)frontend/src/components/CodeEditor.tsx(1 hunks)frontend/src/components/datagrid/DataGrid.tsx(3 hunks)frontend/src/components/layout/AppSidebar.tsx(2 hunks)frontend/src/features/database/hooks/useRawSQL.ts(1 hunks)frontend/src/features/database/page/SQLEditorPage.tsx(1 hunks)frontend/src/features/database/services/advance.service.ts(1 hunks)frontend/src/features/functions/components/FunctionViewer.tsx(0 hunks)frontend/src/features/functions/components/FunctionsContent.tsx(1 hunks)frontend/src/lib/routing/AppRoutes.tsx(3 hunks)package.json(1 hunks)
💤 Files with no reviewable changes (1)
- frontend/src/features/functions/components/FunctionViewer.tsx
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx}: Use TypeScript for all code files
Use ES modules (import/export syntax)
Prefer descriptive, unabbreviated variable and function names
Implement proper error handling with try-catch blocks and logging where appropriate
Use single quotes for strings
Include semicolons at the end of statements
Use arrow functions for callbacks and inline functions
Prefer const over let; avoid var
Use template literals for string interpolation
Maintain 2-space indentation
Format code with the repository Prettier configuration
Variables, parameters, properties, and functions must use camelCase
Constants and enum members must use UPPER_CASE
Include JSDoc comments for complex functions
Files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.tsfrontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
frontend/src/**/*.{tsx,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
frontend/src/**/*.{tsx,ts}: Use functional React components with hooks exclusively
Use Radix UI primitives for accessibility
Optimize React component re-renders
Files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.tsfrontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
frontend/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
frontend/src/**/*.{ts,tsx}: Use TanStack Query for server state management
Use React Hook Form for form handling with Zod validation
Optimize bundle size with proper imports
Files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.tsfrontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
**/*.{tsx,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
React components and TypeScript types/interfaces must use PascalCase
Files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.tsfrontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
frontend/src/**/use[A-Z]*.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Hook files must be named usePascalCase.ts (e.g., useAuth.ts)
Files:
frontend/src/features/database/hooks/useRawSQL.ts
**/[a-z][a-z0-9-]*.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Utility files should use kebab-case or camelCase (kebab-case validated here)
Files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.ts
**/[a-z][a-zA-Z0-9]*.service.ts
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Service files must be named camelCase.service.ts (e.g., auth.service.ts)
Files:
frontend/src/features/database/services/advance.service.ts
frontend/src/**/*.tsx
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
frontend/src/**/*.tsx: Implement TypeScript interfaces/types for all component props
Follow component composition patterns; keep components focused and single-purpose
Implement proper loading and error states in UI
Use a consistent icon set from lucide-react
Files:
frontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
frontend/src/**/[A-Z]*.tsx
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Component files must use PascalCase filenames (e.g., DataGrid.tsx)
Files:
frontend/src/components/CodeEditor.tsxfrontend/src/components/layout/AppSidebar.tsxfrontend/src/features/functions/components/FunctionsContent.tsxfrontend/src/components/datagrid/DataGrid.tsxfrontend/src/lib/routing/AppRoutes.tsxfrontend/src/features/database/page/SQLEditorPage.tsx
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/**/*.{ts,tsx} : Use prepared statements for SQL queries
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/**/*.{ts,tsx} : Use prepared statements for SQL queries
Applied to files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.tsfrontend/src/features/database/page/SQLEditorPage.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.{ts,tsx} : Use TanStack Query for server state management
Applied to files:
frontend/src/features/database/hooks/useRawSQL.ts
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to backend/src/{controllers,core}/**/*.ts : Implement proper database transaction handling
Applied to files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/database/services/advance.service.ts
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/use[A-Z]*.ts : Hook files must be named usePascalCase.ts (e.g., useAuth.ts)
Applied to files:
frontend/src/features/database/hooks/useRawSQL.ts
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.{tsx,ts} : Use functional React components with hooks exclusively
Applied to files:
frontend/src/features/database/hooks/useRawSQL.tsfrontend/src/features/functions/components/FunctionsContent.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.tsx : Implement TypeScript interfaces/types for all component props
Applied to files:
frontend/src/components/CodeEditor.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.{tsx} : Use lazy loading for code splitting
Applied to files:
frontend/src/components/CodeEditor.tsxfrontend/src/features/functions/components/FunctionsContent.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.tsx : Use a consistent icon set from lucide-react
Applied to files:
frontend/src/components/layout/AppSidebar.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.{tsx,ts} : Use Radix UI primitives for accessibility
Applied to files:
frontend/src/components/layout/AppSidebar.tsxfrontend/package.json
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to frontend/src/**/*.{ts,tsx} : Optimize bundle size with proper imports
Applied to files:
frontend/src/features/functions/components/FunctionsContent.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to **/*.{ts,tsx} : Use ES modules (import/export syntax)
Applied to files:
frontend/src/features/functions/components/FunctionsContent.tsx
📚 Learning: 2025-10-15T18:18:47.519Z
Learnt from: CR
Repo: InsForge/InsForge PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-10-15T18:18:47.519Z
Learning: Applies to **/*.{ts,tsx} : Use arrow functions for callbacks and inline functions
Applied to files:
frontend/src/features/functions/components/FunctionsContent.tsx
🧬 Code graph analysis (5)
frontend/src/features/database/hooks/useRawSQL.ts (2)
frontend/src/features/database/services/advance.service.ts (2)
RawSQLResponse(8-16)advanceService(40-40)frontend/src/lib/hooks/useToast.tsx (1)
useToast(223-229)
frontend/src/features/database/services/advance.service.ts (1)
frontend/src/lib/api/client.ts (1)
apiClient(163-163)
frontend/src/components/datagrid/DataGrid.tsx (1)
frontend/src/lib/utils/utils.ts (1)
cn(19-21)
frontend/src/lib/routing/AppRoutes.tsx (1)
frontend/src/features/database/page/SQLEditorPage.tsx (1)
SQLEditorPage(106-186)
frontend/src/features/database/page/SQLEditorPage.tsx (4)
frontend/src/components/datagrid/datagridTypes.tsx (2)
DataGridRow(42-44)DataGridColumn(57-65)frontend/src/components/datagrid/DataGrid.tsx (1)
DataGrid(46-257)frontend/src/features/database/hooks/useRawSQL.ts (1)
useRawSQL(17-50)frontend/src/components/CodeEditor.tsx (1)
CodeEditor(19-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: E2E Tests
🔇 Additional comments (15)
package.json (1)
3-3: LGTM! Version bump is appropriate.The patch version increment from 1.1.6 to 1.1.7 is appropriate for adding the SQL Editor feature.
frontend/src/components/layout/AppSidebar.tsx (2)
16-16: LGTM! Consistent icon usage.Terminal icon import follows the established pattern of using lucide-react icons.
45-45: LGTM! Navigation item properly configured.The SQL Editor navigation item is correctly positioned in the navigation array with the appropriate path that matches the route configuration.
frontend/src/features/functions/components/FunctionsContent.tsx (1)
4-4: LGTM! Appropriate refactor for shared component.Moving CodeEditor to a shared location enables reuse across features (Functions and SQL Editor), improving code maintainability.
frontend/package.json (2)
17-18: LGTM! Appropriate language support for code editing.CodeMirror language extensions for SQL and JavaScript support the new SQL Editor feature and existing Functions editor.
36-37: LGTM! Well-established React CodeMirror integration.The UIW React CodeMirror wrapper and VSCode theme provide a production-ready code editing experience.
frontend/src/lib/routing/AppRoutes.tsx (2)
18-18: LGTM! Proper import for the new page.SQLEditorPage import follows the established naming and path conventions.
36-36: LGTM! Routes properly configured for both layouts.SQL Editor routes are correctly added to both cloud and main layout contexts with consistent paths that match the sidebar navigation.
Also applies to: 58-58
frontend/src/components/datagrid/DataGrid.tsx (2)
42-42: LGTM! Clean addition of layout control prop.The
noPaddingprop with a default value offalsemaintains backward compatibility while enabling flexible layout control.Also applies to: 68-68
203-208: LGTM! Conditional padding applied correctly.The conditional
mx-3padding is properly applied using thecn()utility, and the implementation is clean and maintainable.frontend/src/features/database/hooks/useRawSQL.ts (2)
5-15: LGTM! Well-typed interfaces.The interfaces provide clear type definitions for options and parameters with appropriate optional fields.
17-50: Backend SQL injection protection and authorization verified as correctly implemented.All three backend requirements have been confirmed:
Prepared statements: The backend correctly uses
client.query(query, params)at line 144 inbackend/src/core/database/advance.ts, which implements parameterized queries in node-postgres with separate parameter binding.Admin authorization: Both
/api/database/advance/rawsqland/rawsql/unrestrictedendpoints enforceverifyAdminmiddleware (lines 29 and 92).Error handling: Proper try-catch blocks with timeout enforcement (30 seconds at session level, line 141) and specific error messages for timeout scenarios (line 164).
The frontend hook design is also correct—it separates query from params, enabling backend parameter binding. No changes needed.
frontend/src/features/database/services/advance.service.ts (3)
3-16: Note: Flexible response interface accommodates multiple scenarios.The
RawSQLResponseinterface has many optional fields, suggesting the backend returns different response shapes for different query types (SELECT vs. INSERT/UPDATE/DELETE) and error scenarios. This is acceptable but requires careful null-checking in consuming code.
40-40: LGTM! Singleton pattern applied correctly.The exported singleton instance follows the established service pattern in the codebase.
18-38: Add rate limiting specific to the raw SQL endpoint.The backend correctly enforces admin-level authorization, uses parameterized queries, implements SQL sanitization, and logs all raw SQL executions. However, the endpoint lacks specific rate limiting—only the global limiter (1000 requests/15 minutes) applies. This is inadequate for such a sensitive operation and leaves it vulnerable to abuse.
Add a dedicated rate limiter for
/rawsqlendpoints (e.g., 10 requests/minute per user or IP) to mitigate DoS risks:// In backend/src/api/middleware/rate-limiters.ts export const rawSQLLimiter = rateLimit({ windowMs: 60 * 1000, // 1 minute max: 10, // Strict limit for sensitive endpoint keyGenerator: (req) => req.user?.id || req.ip, // Per-user or IP message: 'Too many raw SQL requests, please try again later' }); // In backend/src/api/routes/database.advance.ts router.post('/rawsql', rawSQLLimiter, verifyAdmin, async (req, res) => { // handler }); router.post('/rawsql/unrestricted', rawSQLLimiter, verifyAdmin, async (req, res) => { // handler });⛔ Skipped due to learnings
Learnt from: CR Repo: InsForge/InsForge PR: 0 File: .github/copilot-instructions.md:0-0 Timestamp: 2025-10-15T18:18:47.519Z Learning: Applies to backend/src/api/**/*.ts : Implement rate limiting for API endpointsLearnt from: CR Repo: InsForge/InsForge PR: 0 File: .github/copilot-instructions.md:0-0 Timestamp: 2025-10-15T18:18:47.519Z Learning: Applies to backend/src/**/*.{ts,tsx} : Use prepared statements for SQL queries
tonychang04
left a comment
There was a problem hiding this comment.
Downloaded code and it worked.
Summary
How did you test this change?
Tested locally.
Summary by CodeRabbit
New Features
Improvements
Chores