Conversation
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.
There was a problem hiding this comment.
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
usqlgento automatically excludesqlite3and includemoderncsqlitein the base set of drivers if CGO is not available, and introduces a--dboptions keepcgoto 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
usqlgenin different environments. - Build Process Improvements: Modifies the build process to handle cases where
go mod downloadreturns 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
sqlite3driver is correctly replaced withmoderncsqlitewhen CGO is not available.
Changelog
Click here to see the changelog
- README.md
- Updated CGO usage instructions to reflect the automatic replacement of
sqlite3withmoderncsqlitewhen CGO is not available. - Added information about the
--dboptions keepcgoflag. - Added a section on "Off-label" usage of
usqlgen.
- Updated CGO usage instructions to reflect the automatic replacement of
- internal/gen/gen.go
- Added
KeepCgofield to theInputstruct. - Modified
AllDownloadfunction to adjust CGO tags based on theKeepCgoflag. - Added
adjustCgoTagsfunction to replacesqlite3withmoderncsqlitewhen CGO is not available. - Added
logfunction for logging messages to stderr. - Added
replaceInUsqlFilefunction to replace strings in files. - Modified
AllDownloadto ignore exit code 1 fromgo mod downloadif the package was likely successfully downloaded.
- Added
- internal/gen/gen_test.go
- Modified
runGenAllfunction to accept an environment variable slice. - Added
-tags no_baseto thego runcommand inrunGenAll. - Set the
Envfield for thego listcommand inrunGenAll.
- Modified
- internal/gen/main.go.tpl
- Added
_ "github.com/xo/usql/internal"import.
- Added
- internal/integrationtest/clickhouse/clickhouse_test.go
- Modified
RunGeneratedUsqlEcall to passnilforaddEnv.
- Modified
- internal/integrationtest/common.go
- Modified
RunGeneratedUsqlEfunction to accept anaddEnvslice. - Appended
addEnvtocmd.EnvinRunGeneratedUsqlE.
- Modified
- internal/integrationtest/sqlite/sqlite_cgo_test.go
- Added new file
sqlite_cgo_test.gowith a CGO-enabled test.
- Added new file
- internal/integrationtest/sqlite/sqlite_test.go
- Added new file
sqlite_test.gowith tests for SQLite without CGO. - Added tests for
no_cgo_base,no_cgo_no_replacement, andno_cgo_keepcgoscenarios.
- Added new file
- internal/shell/dboptions.go
- Added
keepcgooption to theallOptionsslice. - Updated descriptions and apply functions for
includesemicolonandkeepcgooptions. - Updated
listOptionsandwriteOptfunctions to improve output formatting.
- Added
- internal/shell/run.go
- Updated the description for the
optionssubcommand.
- Updated the description for the
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,
moderncsqliteto lend,
A portable, pure-Go treat.
Footnotes
-
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. ↩
There was a problem hiding this comment.
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 theadjustCgoTagsfunction 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 inAllDownloaduseserrinstead ofadjustErrwhen logging the error fromadjustCgoTags. 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.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
86720e5 to
1d841e9
Compare
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.