Quote column names + windows support#1354
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds Windows compilation support and improves SQL column name quoting in the gosoline framework. The changes enable the dbx package to correctly handle SQL reserved words (like index) as column names through automatic backtick quoting, and split OS-specific functionality into separate files with build tags to support Windows compilation.
Changes:
- Added automatic column/table name quoting in dbx package using backticks for simple identifiers
- Split Unix/Windows-specific code with appropriate build tags for kernel signal handling, exec error handling, and log status modules
- Added integration test demonstrating reserved word handling with
indexcolumn
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/dbx/expr.go | Implemented quoteIfNeeded function with regex pattern to auto-quote simple identifiers; applied to column names in WHERE/SET clauses and table names; refactored comparison operators for clarity |
| pkg/dbx/select.go | Applied quoting to table names and column names in FROM clauses |
| pkg/dbx/insert.go | Applied quoting to table names; cleaned up unused variable and improved parameter naming |
| pkg/dbx/update.go | Applied quoting to table and column names in UPDATE statements |
| pkg/dbx/delete.go | Applied quoting to table names in DELETE statements |
| pkg/dbx/get.go | Applied quoting to table names in GET queries |
| pkg/dbx/client_test.go | Updated test expectations to include backtick-quoted identifiers in SQL |
| test/dbx/client_test.go | Added Index field to test struct to verify reserved word handling |
| test/dbx/20240605153316_init.sql | Added index column (a MySQL reserved word) to test table schema |
| pkg/kernel/kernel_windows.go | Windows-specific interrupt signal handling (SIGINT only) |
| pkg/kernel/kernel_unix.go | Unix-specific interrupt signal handling (SIGINT and SIGTERM) |
| pkg/kernel/kernel.go | Refactored to use platform-specific interruptSignals variable |
| pkg/exec/error_windows.go | Windows-specific error type checking using Windows error codes |
| pkg/exec/error_unix.go | Unix-specific error type checking using Unix error codes |
| pkg/exec/error.go | Refactored to use platform-specific error checking functions |
| pkg/log/status/module_windows.go | No-op status module for Windows (SIGUSR1 not supported) |
| pkg/log/status/module_unix.go | Added build tags for Unix platforms |
| pkg/log/status/module_unix_test.go | Added build tags for Unix platforms |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| switch p := part.(type) { | ||
| case string: | ||
| sql += p | ||
| sql += quoteIfNeeded(p) |
There was a problem hiding this comment.
Applying quoteIfNeeded in concatExpr changes its behavior for simple column identifiers. While the documented example shows SQL fragments like "COALESCE(full_name," which won't be affected by the regex pattern, users passing simple identifiers like "column_name" will now have them automatically quoted. This is a subtle breaking change. Consider whether this automatic quoting aligns with the intended use case of ConcatExpr, which appears to be for concatenating raw SQL fragments based on the documentation.
| sql += quoteIfNeeded(p) | |
| sql += p |
2987027 to
0f0895f
Compare
|
🚀 Docs Preview Deployed! View the preview here: https://justtrackio.github.io/gosoline/pr-1354/ |
This PR improves the automatic quoting in the
dbxpackage such that you can use column names likeindexwithout running into syntax errors. It also splits some functions such that there is a*_unix.goand*_windows.gofile, making it possible to compile gosoline programs for windows as well.