Skip to content

Comments

feat: automate replacement for sqlite#52

Merged
murfffi merged 4 commits intomainfrom
feat/replace_sqlite
Apr 12, 2025
Merged

feat: automate replacement for sqlite#52
murfffi merged 4 commits intomainfrom
feat/replace_sqlite

Conversation

@murfffi
Copy link
Member

@murfffi murfffi commented Apr 11, 2025

usql assigns that sqlite3 alias to moderncsqlite, if the former driver is excluded, but the later is available. usqlgen builds on that feature to automatically exclude sqlite3, and include moderncsqlite in the base set of drivers if cgo is not available.

usql assigns that sqlite3 alias to moderncsqlite, if the former driver is excluded, but the later is available.
usqlgen builds on that feature to automatically exclude sqlite3, and include moderncsqlite in the base set
of drivers if cgo is not available.
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @murfffi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request enhances usqlgen's ability to handle environments without CGO support. It introduces a new --dboptions keepcgo flag to prevent the automatic replacement of the sqlite3 driver with moderncsqlite when CGO is unavailable. The changes also include improvements to the documentation, build process, and testing to ensure that usqlgen and the generated usql binaries are more portable.

Highlights

  • CGO Handling: Extends usqlgen to automatically exclude sqlite3 and include moderncsqlite in the base set of drivers if CGO is not available, and introduces a --dboptions keepcgo to opt out of this behavior.
  • Documentation Updates: Updates the README to reflect the changes in CGO handling and provides more detailed instructions on how to use usqlgen in different environments.
  • Build Process Improvements: Modifies the build process to handle cases where go mod download returns a non-zero exit code but still successfully downloads the package.
  • Testing Enhancements: Adds new tests to verify the CGO handling logic and ensures that the sqlite3 driver is correctly replaced with moderncsqlite when CGO is not available.

Changelog

Click here to see the changelog
  • README.md
    • Updated CGO usage instructions to reflect the automatic replacement of sqlite3 with moderncsqlite when CGO is not available.
    • Added information about the --dboptions keepcgo flag.
    • Added a section on "Off-label" usage of usqlgen.
  • internal/gen/gen.go
    • Added KeepCgo field to the Input struct.
    • Modified AllDownload function to adjust CGO tags based on the KeepCgo flag.
    • Added adjustCgoTags function to replace sqlite3 with moderncsqlite when CGO is not available.
    • Added log function for logging messages to stderr.
    • Added replaceInUsqlFile function to replace strings in files.
    • Modified AllDownload to ignore exit code 1 from go mod download if the package was likely successfully downloaded.
  • internal/gen/gen_test.go
    • Modified runGenAll function to accept an environment variable slice.
    • Added -tags no_base to the go run command in runGenAll.
    • Set the Env field for the go list command in runGenAll.
  • internal/gen/main.go.tpl
    • Added _ "github.com/xo/usql/internal" import.
  • internal/integrationtest/clickhouse/clickhouse_test.go
    • Modified RunGeneratedUsqlE call to pass nil for addEnv.
  • internal/integrationtest/common.go
    • Modified RunGeneratedUsqlE function to accept an addEnv slice.
    • Appended addEnv to cmd.Env in RunGeneratedUsqlE.
  • internal/integrationtest/sqlite/sqlite_cgo_test.go
    • Added new file sqlite_cgo_test.go with a CGO-enabled test.
  • internal/integrationtest/sqlite/sqlite_test.go
    • Added new file sqlite_test.go with tests for SQLite without CGO.
    • Added tests for no_cgo_base, no_cgo_no_replacement, and no_cgo_keepcgo scenarios.
  • internal/shell/dboptions.go
    • Added keepcgo option to the allOptions slice.
    • Updated descriptions and apply functions for includesemicolon and keepcgo options.
    • Updated listOptions and writeOpt functions to improve output formatting.
  • internal/shell/run.go
    • Updated the description for the options subcommand.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


CGO's dance, a tricky feat,
Linking C and Go, bittersweet.
No CGO? Fear not, friend,
moderncsqlite to lend,
A portable, pure-Go treat.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new keepcgo option and modifies the behavior of usqlgen to automatically exclude the sqlite3 driver and include moderncsqlite when CGO is not available. The changes also include updates to the README to reflect these changes and provide more clarity on CGO usage. Overall, the changes seem well-structured and address the issue of CGO dependency effectively.

Summary of Findings

  • Error handling in adjustCgoTags: The error handling in the adjustCgoTags function logs the error but doesn't return it, which might lead to unexpected behavior if the tag adjustment fails. It would be better to return the error to allow the caller to handle it appropriately.
  • Inconsistent error message in AllDownload: The log message in AllDownload uses err instead of adjustErr when logging the error from adjustCgoTags. This should be corrected to log the actual error.

Merge Readiness

The pull request is almost ready for merging. However, the error handling in adjustCgoTags should be improved to ensure that errors are properly propagated. Additionally, the inconsistent error message in AllDownload should be corrected. Once these issues are addressed, the pull request can be merged. I am unable to approve the pull request in any circumstance, and users should have others review and approve this code before merging.

murfffi and others added 3 commits April 11, 2025 21:03
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@murfffi murfffi force-pushed the feat/replace_sqlite branch from 86720e5 to 1d841e9 Compare April 12, 2025 10:02
@murfffi murfffi changed the title feat: extends replacement for sqlite feat: automate replacement for sqlite Apr 12, 2025
@murfffi murfffi merged commit d5ed79d into main Apr 12, 2025
4 checks passed
@murfffi murfffi deleted the feat/replace_sqlite branch April 12, 2025 11:05
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.

1 participant