-
Notifications
You must be signed in to change notification settings - Fork 4
/
query_table.go
61 lines (54 loc) · 1.38 KB
/
query_table.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package orm
import (
"reflect"
"strings"
)
type queryTable struct {
table Table
tableStruct reflect.Value
tableStructType reflect.Type
ormFields map[any]string
joinType JoinType //(left|right) join
joinCondition where
alias string
rawSql string
bindings []any
}
func (q queryTable) getAlias() string {
return q.alias
}
func (q queryTable) getAliasOrTableName() string {
if q.alias != "" {
return q.alias
}
return q.getTableName()
}
func (q queryTable) getTableNameAndAlias() string {
var strs []string
temp := q.getTableName()
if temp != "" {
strs = append(strs, temp)
}
temp = q.getAlias()
if temp != "" {
strs = append(strs, temp)
}
return strings.Join(strs, " ")
}
func (q queryTable) getTableName() string {
if q.table.TableName() != "" {
if q.table.DatabaseName() != "" {
return q.table.DatabaseName() + "." + q.table.TableName()
} else {
return q.table.TableName()
}
}
return ""
}
func (q queryTable) getTags(index int, tagName string) []string {
tags := strings.Split(q.tableStructType.Field(index).Tag.Get(tagName), ",")
return tags
}
func (q queryTable) getTag(index int, tagName string) string {
return q.tableStructType.Field(index).Tag.Get(tagName)
}