-
Notifications
You must be signed in to change notification settings - Fork 18
feat: improve Go snippets in connect to DB dialog #2268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@greptile review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (3)
-
src/components/ConnectToDB/snippets.ts, line 70-96 (link)logic:
getGoDatabaseSqlSnippetCodeis never called. Either integrate it into the UI (add a tab/selector for "Go database/sql" vs "Go native SDK") or remove it.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
src/components/ConnectToDB/snippets.ts, line 43-46 (link)style: Inconsistent context usage -
ctxis created on line 43 butcontext.Background()is passed toydb.Open()on line 46. Should usectxfor consistency.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
-
src/components/ConnectToDB/snippets.ts, line 82 (link)style: Consider using proper URL building with
url.Valuesfor DSN construction instead of string concatenation for better readability and safety.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
1 file reviewed, 3 comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the Go code snippet generation for the "Connect to DB" dialog by splitting it into two separate functions: one for the native YDB SDK and one for the database/sql interface. The native SDK snippet is updated with a cleaner implementation and better example code, while a new database/sql variant is introduced.
Key Changes:
- Renamed
getGoSnippetCodetogetGoNativeSdkSnippetCodewith simplified query execution using the newerdb.Query().QueryRow()API - Added new
getGoDatabaseSqlSnippetCodefunction providing a database/sql-based connection example - Updated imports and formatting to use proper Go tab indentation throughout both snippets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional Comments (2)
-
src/components/ConnectToDB/snippets.ts, line 43 (link)logic: creating a context (
ctx) and then not using it forydb.Open()on line 46 -
src/components/ConnectToDB/snippets.ts, line 70-95 (link)style:
getGoDatabaseSqlSnippetCodeis defined but never used - remove or export it for useIf this is intended for future use, it should be integrated into the snippet selection logic in
ConnectToDBDialog.tsxContext Used: Rule from
dashboard- Remove unused interfaces and CSS classes that are added during development. Clean up duplicate code ... (source)
1 file reviewed, 2 comments
Greptile Summary
This PR modernizes the Go connection snippets by replacing the deprecated table-based API with the newer Query API and adds a database/sql compatibility example.
getGoSnippetCodetogetGoNativeSdkSnippetCodefor claritydb.Query().QueryRow()instead ofdb.Table().Do()getGoDatabaseSqlSnippetCodefunction for database/sql interface (but not integrated)ydb.Open()call (line 46 usescontext.Background()instead ofctx)getGoDatabaseSqlSnippetCodeis unused and should be removed or integratedConfidence Score: 3/5
context.Background(). Additionally, an unused function violates code cleanup standards.src/components/ConnectToDB/snippets.ts- the context bug needs immediate fixingImportant Files Changed
Sequence Diagram
sequenceDiagram participant User participant ConnectToDBDialog participant getSnippetCode participant getGoNativeSdkSnippetCode participant getGoDatabaseSqlSnippetCode User->>ConnectToDBDialog: Opens dialog, selects "Go" tab ConnectToDBDialog->>getSnippetCode: Calls with lang='go', params getSnippetCode->>getGoNativeSdkSnippetCode: Routes to native SDK function getGoNativeSdkSnippetCode-->>getSnippetCode: Returns Go code snippet getSnippetCode-->>ConnectToDBDialog: Returns snippet ConnectToDBDialog-->>User: Displays syntax-highlighted code Note over getGoDatabaseSqlSnippetCode: Function exists but never called<br/>(unused code)Context used:
dashboard- Remove unused interfaces and CSS classes that are added during development. Clean up duplicate code ... (source)