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 {
|
if len(vals) != 1 {
|
||||||
panic(fmt.Errorf("tried to query a scalar value, but got %v values in the row", len(vals)))
|
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
|
return result.Interface().(*T), true
|
||||||
} else {
|
} else {
|
||||||
var currentField reflect.StructField
|
var currentField reflect.StructField
|
||||||
|
@ -463,12 +463,7 @@ func (it *Iterator[T]) Next() (*T, bool) {
|
||||||
}
|
}
|
||||||
currentValue = valReflected
|
currentValue = valReflected
|
||||||
|
|
||||||
switch field.Kind() {
|
setValueFromDB(field, valReflected)
|
||||||
case reflect.Int:
|
|
||||||
field.SetInt(valReflected.Int())
|
|
||||||
default:
|
|
||||||
field.Set(valReflected)
|
|
||||||
}
|
|
||||||
|
|
||||||
currentField = reflect.StructField{}
|
currentField = reflect.StructField{}
|
||||||
currentValue = reflect.Value{}
|
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() {
|
func (it *Iterator[any]) Close() {
|
||||||
it.rows.Close()
|
it.rows.Close()
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in New Issue