sqlc
sqlc copied to clipboard
Generated query will return row struct instead of table model struct selecting columns out of defined order.
Version
1.26.0
What happened?
When a query specifies all columns, the generated function should return the struct from models.go. However, if the column order from the query is not identical to the column order in the table definition, the generated function will instead return a *Row struct.
Relevant log output
// generated code, note it does not return our Test model struct
type TestGetRow struct {
Name string
ID int32
}
func (q *Queries) TestGet(ctx context.Context, id int32) (TestGetRow, error) {
row := q.db.QueryRowContext(ctx, testGet, id)
var i TestGetRow
err := row.Scan(&i.Name, &i.ID)
return i, err
}
Database schema
CREATE TABLE IF NOT EXISTS test (
id INTEGER NOT NULL PRIMARY KEY,
name TEXT NOT NULL
);
SQL queries
-- name: TestGet :one
SELECT name, id FROM test WHERE id = $1;
Configuration
version: "2"
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "schema.sql"
gen:
go:
out: "db"
Playground URL
https://play.sqlc.dev/p/b9e31f8d197736d3d2bfac8395a0236bce0a7f6bac3b6e3ddfbe54875eabda31
What operating system are you using?
Windows
What database engines are you using?
MySQL, PostgreSQL, SQLite
What type of code are you generating?
Go