/
util.go
40 lines (34 loc) · 1.06 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package goq
import (
"fmt"
"reflect"
)
const mapKeyNotSelectedErrMsg = "cannot use non collected value for `By` (or use `ByWith` instead)"
// For map collectors.
func isKeyCol(col *Selection, key *Selection) bool {
if col.Alias != "" && col.Alias == key.Alias {
return true
}
return col.StructName != "" && col.StructName == key.StructName &&
col.TableAlias == key.TableAlias && col.FieldName == key.FieldName
}
func isSameTable(col Selection, tbl tableInfo) bool {
return col.TableAlias == tbl.tableAlias && col.StructName == tbl.structName
}
func checkPtrKind(ptr interface{}, kind reflect.Kind) error {
tp := reflect.TypeOf(ptr)
if tp.Kind() != reflect.Ptr || tp.Elem().Kind() != kind {
return fmt.Errorf("required: pointer of %s, got: %s", kind, tp)
}
return nil
}
func checkSliceMapPtrKind(ptr interface{}) error {
tp := reflect.TypeOf(ptr)
if tp.Kind() == reflect.Ptr {
elem := tp.Elem()
if elem.Kind() == reflect.Map && elem.Elem().Kind() == reflect.Slice {
return nil
}
}
return fmt.Errorf("required: pointer of a map of slices, got: %s", tp)
}