-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerysupport.go
54 lines (43 loc) · 1.28 KB
/
querysupport.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
// A quickly mysql access component.
package godbx
// Pager 分页参数结构,PageSize 每一页的大小,PageNumber 页码,从1算起
type Pager struct {
PageSize int
PageNumber int
}
func NewPager(pageSize int, pageNumber int) *Pager {
return &Pager{pageSize, pageNumber}
}
// Order 描述sql中的单个 order 条件
type Order struct {
ColumnName string
Desc bool
}
func NewOrder(columnName string) *Order {
return &Order{columnName, false}
}
func NewDescOrder(columnName string) *Order {
return &Order{columnName, true}
}
// NewOrdersBuilder 构建 OrdersBuilder对象
func NewOrdersBuilder() *OrdersBuilder {
return &OrdersBuilder{}
}
// OrdersBuilder 构建order by 条件工具
type OrdersBuilder struct {
orderItems []*Order
}
// NewOrder 增加一个升序的条件
func (orders *OrdersBuilder) NewOrder(columnName string) *OrdersBuilder {
orders.orderItems = append(orders.orderItems, NewOrder(columnName))
return orders
}
// NewDescOrder 增加一个降序的条件
func (orders *OrdersBuilder) NewDescOrder(columnName string) *OrdersBuilder {
orders.orderItems = append(orders.orderItems, NewDescOrder(columnName))
return orders
}
// Build 构建出最终的 order by sql 片段
func (orders *OrdersBuilder) Build() []*Order {
return orders.orderItems
}