Skip to content

Commit 055a7bd

Browse files
committed
added db.QueryStructSlice
1 parent 1494361 commit 055a7bd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

db/query.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,12 @@ func pkColumnsOfStruct(conn sqldb.Connection, t reflect.Type) (table string, col
118118
}
119119
return table, columns, nil
120120
}
121+
122+
// QueryStructSlice returns queried rows as slice of pointers to the generic struct type S
123+
func QueryStructSlice[S any](ctx context.Context, query string, args ...any) (rows []*S, err error) {
124+
err = Conn(ctx).QueryRows(query, args...).ScanStructSlice(&rows)
125+
if err != nil {
126+
return nil, err
127+
}
128+
return rows, nil
129+
}

0 commit comments

Comments
 (0)