Skip to content

Commit 0c65b87

Browse files
authored
Merge pull request #397 from stephenafamo/queries
Fix panic when scanning generated queries
2 parents 1a97493 + f3512c9 commit 0c65b87

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [v0.33.1] - 2025-04-26
9+
10+
### Changed
11+
12+
- When a query returns only one column, instead of returning a struct with one field, it will return the type of the column. This is to make it easier to use the generated code.
13+
14+
### Fixed
15+
16+
- Fix panic when scanning returned rows from generated queries.
17+
818
## [v0.33.0] - 2025-04-26
919

1020
### Added

gen/templates/queries/query/01_query.go.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
{{$queryType := (lower $query.Type.String | titleCase)}}
2727
{{$dialectType := printf "*dialect.%sQuery" $queryType}}
2828
{{$colParams := printf "%s, %s" $queryRowName (or $query.Config.RowSliceName (printf "[]%s" $queryRowName)) }}
29+
{{if eq (len $query.Columns) 1}}
30+
{{$col := index $query.Columns 0}}
31+
{{$colType := $col.Type $.Importer $.Types}}
32+
{{$colParams = printf "%s, %s" $colType (or $query.Config.RowSliceName (printf "[]%s" $colType)) }}
33+
{{end}}
2934

3035
const {{$lowerName}}SQL = `{{replace "`" "`+\"`\"+`" $query.SQL}}`
3136

@@ -71,6 +76,13 @@ func {{$upperName}} ({{join ", " $args}}) orm.ModExecQuery[{{$dialectType}}] {
7176
QueryType: bob.QueryType{{$queryType}},
7277
},
7378
},
79+
{{if gt (len $query.Columns) 1 -}}
80+
{{- $.Importer.Import "github.com/stephenafamo/scan" -}}
81+
Scanner: scan.StructMapper[{{$queryRowName}}](),
82+
{{- else -}}
83+
{{- $col := index $query.Columns 0 -}}
84+
Scanner: scan.ColumnMapper[{{$col.Type $.Importer $.Types}}]("{{$col.DBName}}"),
85+
{{- end}}
7486
},
7587
}
7688
}

0 commit comments

Comments
 (0)