Repository navigation
Fix wrong generated output (names, outer-join embeds, PG arrays) - #42
Merged
Merged
Conversation
…le/attribute names, outer-join embeds, nested and undecoded PG arrays Co-Authored-By: Doron Eli Rachman <doron050@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
doron050
added a commit
that referenced
this pull request
Nov 3, 2026
…wn-option errors, engine check, comments (#44) ## Summary Fixes the configuration and option gaps from the feature-gap analysis (section 1c). **Stacked on #43**, which is stacked on #42; retarget to `main` once those are merged. - **Overrides now apply to models.** Before, `overrides:` only affected query rows and parameters, so `Author#bio` kept the database type while `GetAuthorRow#bio` used the override. `*:<column>` now also applies to models. Two new forms work like sqlc's Go overrides: - `column: "<table>.<column>"` (or `"<schema>.<table>.<column>"`): the table's model plus every query column that sqlc reports as coming from that table. - `db_type: "uuid"`: every column or parameter of that database type. - Order of precedence: `Query:col` > `table.col` > `*:col` > `db_type`. - **`rename`**: `{authors: Writer, bio: biography}`. A table name (or `schema.table`) sets the model class name. A column name sets the attribute name in rows and models; the value is still read by the original column name. Class names are validated. - **`exactTableNames`** (the equivalent of `emit_exact_table_names`): `authors` gives `Authors` instead of `Author`. - **Global options**: `GenerateRequest.global_options` (field 6, the plugin's entry in the top-level `options:` of `sqlc.yaml`) used to be ignored. It is now merged under the codegen options: the codegen options win, and the `overrides` of both apply. - **Unknown options are rejected** instead of silently ignored, with a hint for near misses: `unknown plugin options: generate_types (did you mean generateTypes?)`. - **Engine check**: `GenerateRequest.settings` (`version`, `engine`) is now decoded. A driver used with another engine (e.g. `driver: pg` with `engine: mysql`) is an error. - **Comments**: table and enum comments become doc comments of the models (`.rb` + `.rbs`), and column comments become comments in the RBS. The PG example gains `COMMENT ON` statements to show this. **Breaking:** configs with misspelled or unsupported option keys now fail. Models change type when an existing `*:<column>` override matches one of their columns. The fixtures are recaptured; they now include `settings`. ## Checklist - [x] `examples/` is regenerated (`rake sqlc_generate_process`) and committed - [x] Tests added or updated (`rake test`, and `rake end2end_*` when the generated code changes) - [x] The generated code stays RuboCop-clean (`rake rubocop`) and Steep-clean (`rake steep`) - [x] Labelled (`feature`, `bug`, `breaking`, `documentation`) so the release notes are grouped correctly Tested locally: `rake test`, `rake rubocop steep`, `rake end2end_pg` (postgres:16). Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Doron Eli Rachman <doron050@gmail.com>
…wrong-output Co-Authored-By: Doron Eli Rachman <doron050@gmail.com> # Conflicts: # examples/authors/postgresql/query.sql # examples/authors/postgresql/schema.sql # examples/pg/models.rb # examples/pg/models.rbs # examples/pg/query_sql.rb # examples/pg/query_sql.rbs # lib/sqlc_gen_ruby/code.rb # lib/sqlc_gen_ruby/drivers/pg.rb # lib/sqlc_gen_ruby/generator.rb # lib/sqlc_gen_ruby/method_gen.rb # lib/sqlc_gen_ruby/row_layout.rb # lib/sqlc_gen_ruby/type_resolver.rb # steep_expectations.yml # test/features_test.rb # test/fixtures/pg.bin # test/golden/pg/default/models.rb # test/golden/pg/default/models.rbs # test/golden/pg/default/my_queries_sql.rb # test/golden/pg/default/other_sql.rb # test/golden/pg/default/query_sql.rb # test/golden/pg/default/query_sql.rbs # test/golden/pg/ruby31_gemfile/models.rb # test/golden/pg/ruby31_gemfile/models.rbs # test/golden/pg/ruby31_gemfile/my_queries_sql.rb # test/golden/pg/ruby31_gemfile/other_sql.rb # test/golden/pg/ruby31_gemfile/query_sql.rb # test/golden/pg/ruby31_gemfile/query_sql.rbs # test/golden/pg/ruby32_notypes/models.rb # test/golden/pg/ruby32_notypes/my_queries_sql.rb # test/golden/pg/ruby32_notypes/other_sql.rb # test/golden/pg/ruby32_notypes/query_sql.rb # tests/end2end_pg.rb
doron050
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the cases from the feature-gap analysis (section 1a) where the plugin generated code that was wrong or did not load:
WHERE id > $1 AND id < $2generateddef m(id:, id:)(SyntaxError). The second one is nowid_2:.Transaction,Initialize,Connect,WithClient,Hash, ... silently overrode the generated method (q.transaction { }ran the query). These names are now rejected with a clear error.authorandauthorsboth becameAuthor(superclass mismatch). The plural table now keeps its plural name (Authors); any collision that is left raises an error.user-queries.sqlgeneratedclass User-queriesSql. It is nowUserQueriesSql(my_queries.sqlstaysMy_queriesSql). Two files that would write the same.rbare rejected.class,hash,end,to_h,Full Name, ... becameDataattributes that override core methods or are not valid. They now get a trailing_(class_) or are sanitized (full_Name). The value is still read by the original column name.sqlc.embedin outer joins: a missingLEFT JOINside gave a model full ofnils. In queries withLEFT/RIGHT/FULL JOIN, embedded models are now typedModel?and arenilwhen the table's NOT NULL columns are all NULL. (sqlc doesn't say which side of the join an embed is on.)array_dims:int[][]is nowArray[Array[Integer]], notArray[Integer].uuid[], enum arrays,citext[], ...) came back as raw"{a,b}"strings while being typedArray[String].configurenow registers aPG::TextDecoder::Arrayfor every array type inpg_typeas a fallback (one extra query per new connection).The PG example gains
postgres_array_types,ListAuthorsWithOptionalBook(LEFT JOIN embed) andListAuthorsBetweenIds(repeated param).test/fixtures/pg.binis recaptured andsteep_expectations.ymlis refreshed (line shifts plus 3 morePGconstant warnings).Breaking for code that relied on the old names: result columns named after keywords or core methods, query files with non-identifier characters, and query names that are now rejected.
Checklist
examples/is regenerated (rake sqlc_generate_process) and committedrake test, andrake end2end_*when the generated code changes)rake rubocop) and Steep-clean (rake steep)feature,bug,breaking,documentation) so the release notes are grouped correctlyTested locally:
rake test,rake rubocop steep,rake end2end_pg(postgres:16),rake end2end_sqlite3.