mirror of
https://github.com/stashapp/stash-box.git
synced 2026-02-06 01:18:33 -06:00
* split out enum functions to utils * split out ApplyEdit to a function * fix InsertJoinsWithConflictHandling comment * getRepoFactory once Co-authored-by: Infinite <infinitekittens@protonmail.com>
43 lines
647 B
Go
43 lines
647 B
Go
package utils
|
|
|
|
import (
|
|
"database/sql"
|
|
"reflect"
|
|
)
|
|
|
|
type validator interface {
|
|
IsValid() bool
|
|
}
|
|
|
|
func validateEnum(value interface{}) bool {
|
|
v, ok := value.(validator)
|
|
if !ok {
|
|
// shouldn't happen
|
|
return false
|
|
}
|
|
|
|
return v.IsValid()
|
|
}
|
|
|
|
func ResolveEnum(value sql.NullString, out interface{}) bool {
|
|
if !value.Valid {
|
|
return false
|
|
}
|
|
|
|
outValue := reflect.ValueOf(out).Elem()
|
|
outValue.SetString(value.String)
|
|
|
|
return validateEnum(out)
|
|
}
|
|
|
|
func ResolveEnumString(value string, out interface{}) bool {
|
|
if value == "" {
|
|
return false
|
|
}
|
|
|
|
outValue := reflect.ValueOf(out).Elem()
|
|
outValue.SetString(value)
|
|
|
|
return validateEnum(out)
|
|
}
|