orm: add execute method to Connection interface for raw SQL queries - #27416
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6a41aa23be
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4231bf9a7d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Add a new `Row` struct for representing raw SQL result rows, and an `execute` method on the `Connection` interface that returns `![]Row`. All three DB backends (mysql, pg, sqlite) implement the new method; sqlite also populates column names from the underlying driver Row type. The `orm.DB` and `orm.Tx` wrappers expose `execute` as well, including transaction-active checks via `ensure_active`. Update mock implementations and add integration tests for the execute path through scope and transaction wrappers.
Addresses the Codex review feedback: the PG backend now uses exec_result (which returns pg.Result with cols metadata) instead of exec, and the MySQL backend uses the raw result/fields API to extract column names. Both populate orm.Row.names, matching the SQLite implementation. Co-authored-by: Codex <codex@vlang.io>
Instead of reconstructing column names from the pg.Result.cols map (which collapses duplicate names), add a names []string field to Result populated by ordinal position in res_to_result, and use res.names directly in the ORM execute implementation. The map-based approach could produce a names array shorter than the actual column count when a query returns duplicate column labels (e.g. SELECT a.id, b.id FROM ...), causing runtime panics or misaligned names.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e243873cfb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Addresses two Codex review findings: - Check get_errno when mysql_store_result returns NULL before treating it as a no-result statement; a NULL result with a non-zero errno means the result set read failed, not that there are zero rows. - Free the MYSQL_RES allocated by mysql_store_result via defer so that repeated execute calls do not leak native result-set memory.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a458a24da
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
res_to_result collected column names inside the row loop with an if i == 0 guard, so names and cols were empty when PQntuples returned zero (e.g. SELECT ... WHERE false). Move column name collection before the row loop so metadata is always populated. Add regression tests: synthetic tests for the Result data model with zero tuples + column names, and an integration test that exercises the full res_to_result path via SELECT ... WHERE false.
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cfedd41d25
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c260110d03
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
The previous commit (afd648b) renamed local variables from to to work around a Windows GCC shadow-warning issue, but this defeat the purpose of the test, which specifically guards the path where a local variable shadows the field. This reverts the rename, restoring the original name-shadowing regression test as written in commit c2f124c.
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary
Add
execute(query string) ![]orm.Rowto theorm.Connectioninterface,enabling users to run raw SQL queries through the ORM abstraction and
receive results as a driver-agnostic
[]orm.Row.All three DB backends (mysql, pg, sqlite) implement the method, and the
orm.DB/orm.Txwrappers expose it with proper transaction-active checks.Behavior change
Yes — new public API:
orm.Connection.execute(query string) ![]orm.Roworm.DB.execute(query string) ![]orm.Roworm.Tx.execute(query string) ![]orm.Roworm.Rowstruct withvals []stringandnames []stringfieldsThe interface addition is a breaking change for any external type
implementing
orm.Connection; they must addexecuteto compile.Why
executeinstead ofexec?The new
Connection.executemethod returns![]orm.Row, a driver-agnosticrow representation. The name
execute(rather thanexec) was chosen deliberately.fix #27415