* add query builder to facilitate dynamic SQL construction * leverage query builder to refactor user store This is partially setup work for MM-13120, but merged to master to avoid further conflicts. * fix unrelated unit test breakage * documentation tweaks * Apply suggestions from code review Co-Authored-By: lieut-data <jesse.hallam@gmail.com> * prefer comma separated case options to fallthrough * vendor github.com/Masterminds/squirrel and deps * switch to using github.com/Masterminds/squirrel * rm querybuilder
25 строки
479 B
Go
25 строки
479 B
Go
package builder
|
|
|
|
import "reflect"
|
|
|
|
func convert(from interface{}, to interface{}) interface{} {
|
|
return reflect.
|
|
ValueOf(from).
|
|
Convert(reflect.TypeOf(to)).
|
|
Interface()
|
|
}
|
|
|
|
func forEach(s interface{}, f func(interface{})) {
|
|
val := reflect.ValueOf(s)
|
|
|
|
kind := val.Kind()
|
|
if kind != reflect.Slice && kind != reflect.Array {
|
|
panic(&reflect.ValueError{Method: "builder.forEach", Kind: kind})
|
|
}
|
|
|
|
l := val.Len()
|
|
for i := 0; i < l; i++ {
|
|
f(val.Index(i).Interface())
|
|
}
|
|
}
|