Skip to content

Commit 31b8fcd

Browse files
committed
fix db.QueryRowStruct
1 parent ad9f25b commit 31b8fcd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

db/queryrow.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func QueryRowStruct[S any](ctx context.Context, table string, pkValues ...any) (
2626
if len(pkColumns) != len(pkValues) {
2727
return nil, fmt.Errorf("got %d primary key values, but struct %s has %d primary key fields", len(pkValues), t, len(pkColumns))
2828
}
29-
query := fmt.Sprintf(`SELECT * FROM %s WHERE "%s" = $1`, table, pkValues[0])
30-
for i := 1; i < len(pkValues); i++ {
31-
query += fmt.Sprintf(` AND "%s" = $%d`, pkValues[i], i+1)
29+
query := fmt.Sprintf(`SELECT * FROM %s WHERE "%s" = $1`, table, pkColumns[0])
30+
for i := 1; i < len(pkColumns); i++ {
31+
query += fmt.Sprintf(` AND "%s" = $%d`, pkColumns[i], i+1)
3232
}
3333
err = conn.QueryRow(query, pkValues...).ScanStruct(&row)
3434
if err != nil {

0 commit comments

Comments
 (0)