2016-04-13 15:51:58 +02:00
|
|
|
package boil
|
|
|
|
|
2016-04-16 09:25:00 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
)
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-04-16 09:25:00 +02:00
|
|
|
func (q *Query) Bind(obj interface{}) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkType(obj interface{}) (reflect.Type, bool, error) {
|
|
|
|
val := reflect.ValueOf(obj)
|
|
|
|
typ := val.Type()
|
|
|
|
kind := val.Kind()
|
|
|
|
|
|
|
|
if kind != reflect.Ptr {
|
|
|
|
return nil, false, fmt.Errorf("Bind must be given pointers to structs but got type: %s, kind: %s", typ.String(), kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
typ = typ.Elem()
|
|
|
|
kind = typ.Kind()
|
|
|
|
isSlice := false
|
|
|
|
|
|
|
|
switch kind {
|
|
|
|
case reflect.Slice:
|
|
|
|
typ = typ.Elem()
|
|
|
|
kind = typ.Kind()
|
|
|
|
isSlice = true
|
|
|
|
case reflect.Struct:
|
|
|
|
return typ, isSlice, nil
|
|
|
|
default:
|
|
|
|
return nil, false, fmt.Errorf("Bind was given an invalid object must be []*T or *T but got type: %s, kind: %s", typ.String(), kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
if kind != reflect.Ptr {
|
|
|
|
return nil, false, fmt.Errorf("Bind must be given pointers to structs but got type: %s, kind: %s", typ.String(), kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
typ = typ.Elem()
|
|
|
|
kind = typ.Kind()
|
|
|
|
|
|
|
|
if kind != reflect.Struct {
|
|
|
|
return nil, false, fmt.Errorf("Bind must be a struct but got type: %s, kind: %s", typ.String(), kind)
|
|
|
|
}
|
|
|
|
|
|
|
|
return typ, isSlice, nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|