Skip to content

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

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1793571093-fix-wrong-output
Open

devin-ai-integration[bot] wants to merge 1 commit 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

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