-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.go
89 lines (79 loc) · 2.61 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package redis_orm
import "strings"
type IndexType int
const (
IndexType_UnSupport IndexType = 0
IndexType_IdMember IndexType = 1
IndexType_IdScore IndexType = 2 //todo:sortedset -> hash
)
type SchemaIndexsTb struct {
Id int64 `redis_orm:"pk autoincr comment 'ID'"`
TableId int64 `redis_orm:"index comment '表ID'"`
Seq byte `redis_orm:"comment '索引顺序'"`
IndexName string `redis_orm:"comment '索引名'"`
IndexComment string `redis_orm:"dft '' comment '索引注释'"`
IndexColumn string `redis_orm:"comment '索引字段,&分割'"`
IndexType int `redis_orm:"comment '数据类型'"`
IsUnique bool `redis_orm:"comment '是否唯一索引'"`
TableIdIndexName string `redis_orm:"combinedindex TableId&IndexName comment '组合索引(表ID&索引名)'"`
CreatedAt int64 `redis_orm:"created_at comment '创建时间'"`
UpdatedAt int64 `redis_orm:"updated_at comment '修改时间'"`
}
func SchemaIndexsFromColumn(tableId int64, v *Index) *SchemaIndexsTb {
return &SchemaIndexsTb{
TableId: tableId,
Seq: v.Seq,
IndexName: v.NameKey,
IndexComment: v.Comment,
IndexColumn: strings.Join(v.IndexColumn, "&"),
IsUnique: v.IsUnique,
IndexType: int(v.Type),
}
}
type Index struct {
Seq byte
NameKey string
IndexColumn []string
Comment string
Type IndexType
IsUnique bool
}
func IndexFromSchemaIndexs(v *SchemaIndexsTb) *Index {
column := &Index{
NameKey: v.IndexName,
Seq: v.Seq,
Comment: v.IndexComment,
IndexColumn: strings.Split(v.IndexColumn, "&"),
IsUnique: v.IsUnique,
Type: IndexType(v.IndexType),
}
return column
}
type SearchCondition struct {
SearchColumn []string
//IndexType IndexType
FieldMaxValue interface{}
FieldMinValue interface{}
IsAsc bool
}
//NewSearchCondition will be deprecated, please use NewSearchConditionV2 instead
func NewSearchCondition(indexType IndexType, minVal, maxVal interface{}, column ...string) *SearchCondition {
return &SearchCondition{
SearchColumn: column,
FieldMaxValue: maxVal,
FieldMinValue: minVal,
}
}
func NewSearchConditionV2(minVal, maxVal interface{}, column ...string) *SearchCondition {
return &SearchCondition{
SearchColumn: column,
FieldMaxValue: maxVal,
FieldMinValue: minVal,
}
}
func (s *SearchCondition) IsEqualIndexName(index *Index) bool {
return strings.ToLower(strings.Join(s.SearchColumn, "&")) == strings.ToLower(strings.Join(index.IndexColumn, "&"))
}
func (s *SearchCondition) Name() string {
return strings.Join(s.SearchColumn, "&")
}