Skip to content

Conversation

@asmyasnikov
Copy link
Member

@asmyasnikov asmyasnikov commented May 10, 2025

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.

  • Renamed getGoSnippetCode to getGoNativeSdkSnippetCode for clarity
  • Simplified the native SDK example using db.Query().QueryRow() instead of db.Table().Do()
  • Fixed indentation from spaces to tabs (Go convention)
  • Added new getGoDatabaseSqlSnippetCode function for database/sql interface (but not integrated)
  • Critical bug: context created but not used in ydb.Open() call (line 46 uses context.Background() instead of ctx)
  • Code cleanup issue: getGoDatabaseSqlSnippetCode is unused and should be removed or integrated

Confidence Score: 3/5

  • This PR has a critical logic bug in the context usage that will cause the example to not respect cancellation
  • The PR improves code quality by modernizing the API usage, but introduces a critical bug where a context is created and then ignored in favor of context.Background(). Additionally, an unused function violates code cleanup standards.
  • Pay close attention to src/components/ConnectToDB/snippets.ts - the context bug needs immediate fixing

Important Files Changed

Filename Overview
src/components/ConnectToDB/snippets.ts Improved Go snippet with newer Query API, but has unused function and context bug

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)
Loading

Context used:

  • Rule from dashboard - Remove unused interfaces and CSS classes that are added during development. Clean up duplicate code ... (source)

@asmyasnikov asmyasnikov changed the title Updated Go snippets feat: improve Go snippets in connect to DB dialog May 10, 2025
@astandrik astandrik requested a review from Copilot December 22, 2025 14:19
@astandrik
Copy link
Collaborator

@greptile review

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (3)

  1. src/components/ConnectToDB/snippets.ts, line 70-96 (link)

    logic: getGoDatabaseSqlSnippetCode is 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!

  2. src/components/ConnectToDB/snippets.ts, line 43-46 (link)

    style: Inconsistent context usage - ctx is created on line 43 but context.Background() is passed to ydb.Open() on line 46. Should use ctx for 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!

  3. src/components/ConnectToDB/snippets.ts, line 82 (link)

    style: Consider using proper URL building with url.Values for 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

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

Copilot AI left a 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 getGoSnippetCode to getGoNativeSdkSnippetCode with simplified query execution using the newer db.Query().QueryRow() API
  • Added new getGoDatabaseSqlSnippetCode function providing a database/sql-based connection example
  • Updated imports and formatting to use proper Go tab indentation throughout both snippets

@astandrik astandrik enabled auto-merge December 22, 2025 14:24
@astandrik astandrik self-requested a review December 22, 2025 14:24
@astandrik astandrik added this pull request to the merge queue Dec 22, 2025
Merged via the queue into ydb-platform:main with commit 2857ffb Dec 22, 2025
1 check passed
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Comments (2)

  1. src/components/ConnectToDB/snippets.ts, line 43 (link)

    logic: creating a context (ctx) and then not using it for ydb.Open() on line 46

  2. src/components/ConnectToDB/snippets.ts, line 70-95 (link)

    style: getGoDatabaseSqlSnippetCode is defined but never used - remove or export it for use

    If this is intended for future use, it should be integrated into the snippet selection logic in ConnectToDBDialog.tsx

    Context 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

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants