aboutsummaryrefslogtreecommitdiff
path: root/plan.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-15 18:54:36 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-15 18:54:36 +0200
commita818aab2a4b48e399d5186c235149ef21011a4af (patch)
treedb0b8c60ab5a2767a6489fb1ae50047712b63cfc /plan.go
parent1bb7ef5779aa3c27417eedf84aac6a8ea896871a (diff)
downloadgo-oblast-a818aab2a4b48e399d5186c235149ef21011a4af.tar.gz
before scanning, spawn member structs within pointers as necessary
Diffstat (limited to 'plan.go')
-rw-r--r--plan.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/plan.go b/plan.go
index d00b5c2..245deab 100644
--- a/plan.go
+++ b/plan.go
@@ -21,8 +21,10 @@ type plan struct {
PrimaryKeyColumnNames []string // from info.PrimaryKeyIs marker (if any)
AutoColumnNames []string // subset of AllColumnNames where field has `,auto` marker
- // Argument for reflect.Value.FieldByIndex() for each column name.
+ // Field index (i.e. argument for reflect.Value.FieldByIndex()) for each column name.
IndexByColumnName map[string][]int
+ // Indexes of pointer-typed fields that need to be initialized before scanning into this type.
+ IndexesOfTransparentPointerStructs [][]int
// In dialects with UsesLastInsertID() == true, whether the ID column must be written with reflect.Value.SetInt() or reflect.Value.SetUint().
FillIDWithSetUint bool
@@ -85,6 +87,11 @@ func buildPlan(t reflect.Type, dialect Dialect, opts planOpts) (plan, error) {
if field.Type.Kind() == reflect.Struct || (field.Type.Kind() == reflect.Pointer && field.Type.Elem().Kind() == reflect.Struct) {
if field.Tag.Get("db") == "" {
indexesOfUnusedTransparentStructs = append(indexesOfUnusedTransparentStructs, field.Index)
+ if field.Type.Kind() == reflect.Pointer {
+ // remember that, when scanning into a record of type `t`, we need to write a non-nil zeroed struct into this field
+ // to enable taking an address of its mapped member fields
+ p.IndexesOfTransparentPointerStructs = append(p.IndexesOfTransparentPointerStructs, field.Index)
+ }
continue
}
indexesOfOpaqueStructs = append(indexesOfOpaqueStructs, field.Index)