Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are two concrete issues that can lead to failures (incorrect type qualification in generated code for some packages, and the new test helper not creating parent directories for nested file paths).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the code generator’s field-type selection so that named types whose underlying type is a scalar (e.g., enums over integers, time.Duration, string/bool aliases, and named []byte) are treated as scalar columns rather than associations, preventing incorrect association SQL in Where/Set.
Changes:
- Add
scalarHelperForNamedTypeto map named scalar-like types to the appropriate scalar field helper. - Use the new helper during field type selection to avoid emitting
field.Struct[...]for scalar named types. - Add a throwaway-module test harness plus a new test covering named scalar types (including
json.RawMessage).
File summaries
| File | Description |
|---|---|
| internal/gen/utils.go | Adds helper that maps named types over basic kinds / named byte slices to scalar field helpers. |
| internal/gen/generator.go | Uses the helper when determining the generated field helper type. |
| internal/gen/generator_support_test.go | Adds test helper to generate code from ad hoc sources in a temporary module. |
| internal/gen/named_scalar_types_test.go | Adds a test ensuring named scalar-like types get scalar helpers (and not field.Struct[...]). |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // A named type over a basic kind (an enum, a duration, a flag) is a scalar column and | ||
| // gets the helper of its kind instead of being mistaken for an association. | ||
| if helper, ok := scalarHelperForNamedType(typ, filepath.Base(goType)); ok { | ||
| return helper | ||
| } |
| for name, content := range files { | ||
| if err := os.WriteFile(filepath.Join(dir, name), []byte(content), 0o644); err != nil { | ||
| t.Fatalf("write %s: %v", name, err) | ||
| } | ||
| } |
9f5c48b to
83cf9c3
Compare
|
Addressed the review. The shared test helper now creates parent directories before writing, so a nested key like On the package qualifier: you are right that |
There was a problem hiding this comment.
🟢 Approval recommended
The change is localized, aligns with the stated problem, and includes a regression test covering the key named-scalar scenarios.
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
83cf9c3 to
f2828d5
Compare
|
Addressed the second round. The shared test helper now reads the whole output tree rather than its top level, so a fixture that spans packages is not silently truncated. That was only reachable once the helper started accepting nested source paths, so thank you for following it through. |
Problem
A named type whose underlying type is a basic kind is one scalar column: an integer enum (protobuf enums, for one), a
time.Duration, a string alias, a flag overbool. The generator emittedfield.Struct[...]for such fields, so using them inWhereorSetproduced association SQL.Fix
scalarHelperForNamedTypemaps a named type over a basic kind to the helper of its kind:field.Number[T]for integers and floats,field.String,field.Bool, andfield.Bytesfor a named byte slice such asjson.RawMessage.Test
TestNamedTypesOverBasicKindsGetScalarHelpersgenerates over a struct with an integer enum, a duration, a string alias, a bool alias and ajson.RawMessagefield, and asserts the helper of each.The first commit adds a small test helper (
generateFromSources,containsField) that writes ad hoc sources into a throwaway module and runs the generator over them. The other pull requests from this fork share that commit; git merges the identical addition without conflict, so they can land in any order.🤖 Generated with Claude Code