@@ -115,12 +115,12 @@ func (q *Query) BindGP(ctx context.Context, obj any) {
115115// For custom objects that want to use eager loading, please see the
116116// loadRelationships function.
117117func Bind (rows * sql.Rows , obj any ) error {
118- structType , sliceType , singular , err := bindChecks (obj )
118+ structType , _ , singular , err := bindChecks (obj )
119119 if err != nil {
120120 return err
121121 }
122122
123- return bind (rows , obj , structType , sliceType , singular )
123+ return bind (rows , obj , structType , singular )
124124}
125125
126126// Bind executes the query and inserts the
@@ -133,7 +133,7 @@ func Bind(rows *sql.Rows, obj any) error {
133133//
134134// Also see documentation for Bind()
135135func (q * Query ) Bind (ctx context.Context , exec boil.Executor , obj any ) error {
136- structType , sliceType , bkind , err := bindChecks (obj )
136+ structType , _ , bkind , err := bindChecks (obj )
137137 if err != nil {
138138 return err
139139 }
@@ -147,7 +147,7 @@ func (q *Query) Bind(ctx context.Context, exec boil.Executor, obj any) error {
147147 if err != nil {
148148 return errors .Wrap (err , "bind failed to execute query" )
149149 }
150- if err = bind (rows , obj , structType , sliceType , bkind ); err != nil {
150+ if err = bind (rows , obj , structType , bkind ); err != nil {
151151 if innerErr := rows .Close (); innerErr != nil {
152152 return errors .Wrapf (err , "error on rows.Close after bind error: %+v" , innerErr )
153153 }
@@ -223,7 +223,7 @@ func bindChecks(obj any) (structType reflect.Type, sliceType reflect.Type, bkind
223223 }
224224}
225225
226- func bind (rows * sql.Rows , obj any , structType , sliceType reflect.Type , bkind bindKind ) error {
226+ func bind (rows * sql.Rows , obj any , structType reflect.Type , bkind bindKind ) error {
227227 cols , err := rows .Columns ()
228228 if err != nil {
229229 return errors .Wrap (err , "bind failed to get column names" )
@@ -240,11 +240,6 @@ func bind(rows *sql.Rows, obj any, structType, sliceType reflect.Type, bkind bin
240240 return err
241241 }
242242
243- var oneStruct reflect.Value
244- if bkind == kindSliceStruct {
245- oneStruct = reflect .Indirect (reflect .New (structType ))
246- }
247-
248243 foundOne := false
249244Rows:
250245 for rows .Next () {
@@ -256,14 +251,12 @@ Rows:
256251 case kindStruct :
257252 pointers = PtrsFromMapping (reflect .Indirect (reflect .ValueOf (obj )), mapping )
258253 case kindSliceStruct :
259- pointers = PtrsFromMapping (oneStruct , mapping )
254+ newStruct = reflect .Indirect (reflect .New (structType ))
255+ pointers = PtrsFromMapping (newStruct , mapping )
260256 case kindPtrSliceStruct :
261257 newStruct = makeStructPtr (structType )
262258 pointers = PtrsFromMapping (reflect .Indirect (newStruct ), mapping )
263259 }
264- if err != nil {
265- return err
266- }
267260
268261 if err := rows .Scan (pointers ... ); err != nil {
269262 return errors .Wrap (err , "failed to bind pointers to obj" )
@@ -272,9 +265,7 @@ Rows:
272265 switch bkind {
273266 case kindStruct :
274267 break Rows
275- case kindSliceStruct :
276- ptrSlice .Set (reflect .Append (ptrSlice , oneStruct ))
277- case kindPtrSliceStruct :
268+ case kindSliceStruct , kindPtrSliceStruct :
278269 ptrSlice .Set (reflect .Append (ptrSlice , newStruct ))
279270 }
280271 }
@@ -871,4 +862,4 @@ func unTitleCase(n string) string {
871862 ret := buf .String ()
872863 strmangle .PutBuffer (buf )
873864 return ret
874- }
865+ }
0 commit comments