-
Notifications
You must be signed in to change notification settings - Fork 0
/
sql_libs.go
108 lines (85 loc) · 3.02 KB
/
sql_libs.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package sql
import (
"github.com/go-xe2/x/xf/ef/xdriveri"
"github.com/go-xe2/x/xf/ef/xq/xqcomm"
. "github.com/go-xe2/x/xf/ef/xqi"
)
func Sum(expr interface{}) SqlField {
return xqcomm.SqlFunSum(Static(expr))
}
func Max(expr interface{}) SqlField {
return xqcomm.SqlFunMax(Static(expr))
}
func Min(expr interface{}) SqlField {
return xqcomm.SqlFunMin(Static(expr))
}
func Avg(expr interface{}) SqlField {
return xqcomm.SqlFunAvg(Static(expr))
}
func Count(expr interface{}) SqlField {
return xqcomm.SqlFunCount(Static(expr))
}
func IfNull(expr interface{}, nullVal interface{}) SqlField {
return xqcomm.SqlFunIfNull(Static(expr), Static(nullVal))
}
func If(expr interface{}, trueValue, falseValue interface{}) SqlField {
return xqcomm.SqlFunIf(Static(expr), Static(trueValue), Static(falseValue))
}
func Cast(expr interface{}, asType DbType) SqlField {
return xqcomm.SqlFunCast(Static(expr), asType)
}
func Case(expr interface{}, cases map[interface{}]interface{}, caseElse ...interface{}) SqlField {
var caseExpr SqlCase = xqcomm.NewSqlFunCase(Static(expr))
for k, v := range cases {
caseExpr = caseExpr.When(Static(k), Static(v))
}
if len(caseElse) > 0 {
return caseExpr.ElseEnd(Static(caseElse[0]))
}
return caseExpr.End()
}
func CaseThen(condition interface{}, caseTrue, caseFalse interface{}) SqlField {
return xqcomm.NewSqlFunCase(Static(condition)).ThenElse(Static(caseTrue), Static(caseFalse))
}
func DateFormat(expr interface{}, format string) SqlField {
return xqcomm.SqlFunDateFormat(Static(expr), format)
}
func DateDiff(date1, date2 interface{}, datePart xdriveri.DatePart) SqlField {
return xqcomm.SqlFunDateDiff(Static(date1), Static(date2), datePart)
}
func DateAdd(date interface{}, interval int, datePart xdriveri.DatePart) SqlField {
return xqcomm.SqlFunDateAdd(Static(date), interval, datePart)
}
func DateSub(date interface{}, interval int, datePart xdriveri.DatePart) SqlField {
return xqcomm.SqlFunDateSub(Static(date), interval, datePart)
}
func DateToUnix(date interface{}) SqlField {
return xqcomm.SqlFunDateToUnix(Static(date))
}
func UnixToDate(unix interface{}) SqlField {
return xqcomm.SqlFunUnixToDate(Static(unix))
}
// 字符串截取
func Substring(str interface{}, from, len int) SqlField {
return xqcomm.SqlFunSubstring(Static(str), from, len)
}
// 字符串连接
func Concat(str interface{}, str1 interface{}, more ...interface{}) SqlField {
return xqcomm.SqlFunStrConcat(str, str1, more...)
}
// 加法运算
func OpPlus(v1, v2 interface{}) SqlField {
return xqcomm.NewSqlField(xqcomm.NewSqlAriExp(Static(v1), Static(v2), SqlAriPlusType), "")
}
// 减法运算
func OpSub(v1, v2 interface{}) SqlField {
return xqcomm.NewSqlField(xqcomm.NewSqlAriExp(Static(v1), Static(v2), SqlAriSubType), "")
}
// 乘法运算
func OpMul(v1, v2 interface{}) SqlField {
return xqcomm.NewSqlField(xqcomm.NewSqlAriExp(Static(v1), Static(v2), SqlAriMulType), "")
}
// 除法运算
func OpDiv(v1, v2 interface{}) SqlField {
return xqcomm.NewSqlField(xqcomm.NewSqlAriExp(Static(v1), Static(v2), SqlAriDivType), "")
}