Skip to content

Commit 565bf3e

Browse files
Nthalkclaude
andcommitted
refactor: rename ColumnName → FieldColumnName
Disambiguates from metaquery.Column.Name (the column's actual name on a query) — same identifier was overloaded for two unrelated concepts. FieldColumnName makes the input direction (struct field → column) clear at the call site. No deprecation alias: the previous name shipped in v1.1.0 only hours ago, well before realistic consumer adoption. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ebefce0 commit 565bf3e

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

metaquery/mqsqlite/scan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ func scanRowInto[T any](rows *sql.Rows) (T, error) {
167167
}
168168

169169
// buildFieldIndex maps column names (from `db` tag or snake_case of the Go
170-
// field name) to the field's index in t. Uses metaquery.ColumnName so Scan
171-
// and Validate agree on the name resolution.
170+
// field name) to the field's index in t. Uses metaquery.FieldColumnName so
171+
// Scan and Validate agree on the name resolution.
172172
func buildFieldIndex(t reflect.Type) map[string]int {
173173
for t.Kind() == reflect.Pointer {
174174
t = t.Elem()
@@ -179,7 +179,7 @@ func buildFieldIndex(t reflect.Type) map[string]int {
179179
if !f.IsExported() {
180180
continue
181181
}
182-
name := metaquery.ColumnName(f)
182+
name := metaquery.FieldColumnName(f)
183183
if name == "-" {
184184
continue
185185
}

metaquery/validate.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func validateShape(t reflect.Type, cols []Column) error {
4747
if !f.IsExported() {
4848
continue
4949
}
50-
name := ColumnName(f)
50+
name := FieldColumnName(f)
5151
if name == "-" {
5252
continue
5353
}
@@ -77,13 +77,14 @@ func validateShape(t reflect.Type, cols []Column) error {
7777
return fmt.Errorf("metaquery: Validate[%s] shape mismatch: %s", t.Name(), strings.Join(all, "; "))
7878
}
7979

80-
// ColumnName returns the column name a struct field should match against
81-
// when scanning rows: the `db` tag if set, otherwise snake_case of the Go
82-
// name. A `db:"-"` tag is returned verbatim so callers can skip the field.
80+
// FieldColumnName returns the column name a struct field should match
81+
// against when scanning rows: the `db` tag if set, otherwise snake_case of
82+
// the Go name. A `db:"-"` tag is returned verbatim so callers can skip the
83+
// field.
8384
//
8485
// Exported so adapters (mqpgx, mqsqlite, future ones) and Validate share
8586
// one source of truth for the field-to-column convention.
86-
func ColumnName(f reflect.StructField) string {
87+
func FieldColumnName(f reflect.StructField) string {
8788
if tag, ok := f.Tag.Lookup("db"); ok {
8889
if comma := strings.IndexByte(tag, ','); comma >= 0 {
8990
tag = tag[:comma]

0 commit comments

Comments
 (0)