Skip to content

Commit

Permalink
remove heavy checking
Browse files Browse the repository at this point in the history
  • Loading branch information
yinloo-ola committed Dec 14, 2023
1 parent 39af31a commit 273bc8a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions coredb/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (e *InvalidScanError) Error() string {
//
// The function returns a slice of pointers to T structs and an error.
func RowsToStructSlice[T any](rows *sql.Rows) (result []*T, err error) {
defer rows.Close()

var u *T
for rows.Next() {
u = new(T)
Expand All @@ -38,6 +40,7 @@ func RowsToStructSlice[T any](rows *sql.Rows) (result []*T, err error) {
}
result = append(result, u)
}
err = rows.Err()
return
}

Expand All @@ -59,14 +62,7 @@ func RowToStruct[T any](row *sql.Row) (result *T, err error) {

// StrutForScan returns value pointers of given obj
func StrutForScan(u any) (pointers []any) {
val := reflect.ValueOf(u)
if val.Kind() != reflect.Pointer || val.IsNil() {
err := &InvalidScanError{reflect.TypeOf(u)}
panic(err)
}

val = val.Elem()

val := reflect.ValueOf(u).Elem()
pointers = make([]any, 0, val.NumField())
for i := 0; i < val.NumField(); i++ {
valueField := val.Field(i)
Expand Down

0 comments on commit 273bc8a

Please sign in to comment.