diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e82496d..033ed0fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v0.33.1] - 2025-04-26 + +### Changed + +- 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. + +### Fixed + +- Fix panic when scanning returned rows from generated queries. + ## [v0.33.0] - 2025-04-26 ### Added diff --git a/gen/templates/queries/query/01_query.go.tpl b/gen/templates/queries/query/01_query.go.tpl index 3df18628..765e026e 100644 --- a/gen/templates/queries/query/01_query.go.tpl +++ b/gen/templates/queries/query/01_query.go.tpl @@ -26,6 +26,11 @@ {{$queryType := (lower $query.Type.String | titleCase)}} {{$dialectType := printf "*dialect.%sQuery" $queryType}} {{$colParams := printf "%s, %s" $queryRowName (or $query.Config.RowSliceName (printf "[]%s" $queryRowName)) }} +{{if eq (len $query.Columns) 1}} + {{$col := index $query.Columns 0}} + {{$colType := $col.Type $.Importer $.Types}} + {{$colParams = printf "%s, %s" $colType (or $query.Config.RowSliceName (printf "[]%s" $colType)) }} +{{end}} const {{$lowerName}}SQL = `{{replace "`" "`+\"`\"+`" $query.SQL}}` @@ -71,6 +76,13 @@ func {{$upperName}} ({{join ", " $args}}) orm.ModExecQuery[{{$dialectType}}] { QueryType: bob.QueryType{{$queryType}}, }, }, + {{if gt (len $query.Columns) 1 -}} + {{- $.Importer.Import "github.com/stephenafamo/scan" -}} + Scanner: scan.StructMapper[{{$queryRowName}}](), + {{- else -}} + {{- $col := index $query.Columns 0 -}} + Scanner: scan.ColumnMapper[{{$col.Type $.Importer $.Types}}]("{{$col.DBName}}"), + {{- end}} }, } }