wtf it works
This commit is contained in:
parent
2229ac85d5
commit
8ff5f02916
18
src/db/db.go
18
src/db/db.go
|
@ -414,7 +414,7 @@ func (it *Iterator[T]) Next() (*T, bool) {
|
|||
if len(vals) != 1 {
|
||||
panic(fmt.Errorf("tried to query a scalar value, but got %v values in the row", len(vals)))
|
||||
}
|
||||
result.Set(reflect.ValueOf(vals[0]))
|
||||
setValueFromDB(result.Elem(), reflect.ValueOf(vals[0]))
|
||||
return result.Interface().(*T), true
|
||||
} else {
|
||||
var currentField reflect.StructField
|
||||
|
@ -463,12 +463,7 @@ func (it *Iterator[T]) Next() (*T, bool) {
|
|||
}
|
||||
currentValue = valReflected
|
||||
|
||||
switch field.Kind() {
|
||||
case reflect.Int:
|
||||
field.SetInt(valReflected.Int())
|
||||
default:
|
||||
field.Set(valReflected)
|
||||
}
|
||||
setValueFromDB(field, valReflected)
|
||||
|
||||
currentField = reflect.StructField{}
|
||||
currentValue = reflect.Value{}
|
||||
|
@ -478,6 +473,15 @@ func (it *Iterator[T]) Next() (*T, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func setValueFromDB(dest reflect.Value, value reflect.Value) {
|
||||
switch dest.Kind() {
|
||||
case reflect.Int:
|
||||
dest.SetInt(value.Int())
|
||||
default:
|
||||
dest.Set(value)
|
||||
}
|
||||
}
|
||||
|
||||
func (it *Iterator[any]) Close() {
|
||||
it.rows.Close()
|
||||
select {
|
||||
|
|
Loading…
Reference in New Issue