Skip to content

Fix wrong generated output (names, outer-join embeds, PG arrays) - #42

Merged
doron050 merged 2 commits into
mainfrom
devin/1793571093-fix-wrong-output
Nov 3, 2026
Merged

doron050 merged 2 commits into
mainfrom
devin/1793571093-fix-wrong-output

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the cases from the feature-gap analysis (section 1a) where the plugin generated code that was wrong or did not load:

  • Repeated parameters: WHERE id > $1 AND id < $2 generated def m(id:, id:) (SyntaxError). The second one is now id_2:.
  • Query names that replace generated methods: a query named Transaction, Initialize, Connect, WithClient, Hash, ... silently overrode the generated method (q.transaction { } ran the query). These names are now rejected with a clear error.
  • Model name collisions: tables author and authors both became Author (superclass mismatch). The plural table now keeps its plural name (Authors); any collision that is left raises an error.
  • Query file names: user-queries.sql generated class User-queriesSql. It is now UserQueriesSql (my_queries.sql stays My_queriesSql). Two files that would write the same .rb are rejected.
  • Result column / model attribute names: class, hash, end, to_h, Full Name, ... became Data attributes 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.embed in outer joins: a missing LEFT JOIN side gave a model full of nils. In queries with LEFT / RIGHT / FULL JOIN, embedded models are now typed Model? and are nil when 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 now Array[Array[Integer]], not Array[Integer].
  • PostgreSQL arrays of types without a decoder (uuid[], enum arrays, citext[], ...) came back as raw "{a,b}" strings while being typed Array[String]. configure now registers a PG::TextDecoder::Array for every array type in pg_type as a fallback (one extra query per new connection).

The PG example gains postgres_array_types, ListAuthorsWithOptionalBook (LEFT JOIN embed) and ListAuthorsBetweenIds (repeated param). test/fixtures/pg.bin is recaptured and steep_expectations.yml is refreshed (line shifts plus 3 more PG constant 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 committed
  • Tests added or updated (rake test, and rake end2end_* when the generated code changes)
  • The generated code stays RuboCop-clean (rake rubocop) and Steep-clean (rake steep)
  • Labelled (feature, bug, breaking, documentation) so the release notes are grouped correctly

Tested locally: rake test, rake rubocop steep, rake end2end_pg (postgres:16), rake end2end_sqlite3.

…le/attribute names, outer-join embeds, nested and undecoded PG arrays

Co-Authored-By: Doron Eli Rachman <doron050@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the bug Something isn't working label Nov 1, 2026
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
doron050 merged commit 7e98f8c into main Nov 3, 2026
14 checks passed
@doron050
doron050 deleted the devin/1793571093-fix-wrong-output branch November 12, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant