-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathcast.go
75 lines (59 loc) · 1.66 KB
/
cast.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
package mysql
import (
"github.com/go-jet/jet/v2/internal/jet"
"strconv"
)
type cast struct {
jet.Cast
}
// CAST function converts a expr (of any type) into latter specified datatype.
func CAST(expr Expression) *cast {
ret := &cast{}
ret.Cast = jet.NewCastImpl(expr)
return ret
}
// AS casts expressions to castType
func (c *cast) AS(castType string) Expression {
return c.Cast.AS(castType)
}
// AS_DATETIME cast expression to DATETIME type
func (c *cast) AS_DATETIME() DateTimeExpression {
return DateTimeExp(c.AS("DATETIME"))
}
// AS_SIGNED casts expression to SIGNED type
func (c *cast) AS_SIGNED() IntegerExpression {
return IntExp(c.AS("SIGNED"))
}
// AS_UNSIGNED casts expression to UNSIGNED type
func (c *cast) AS_UNSIGNED() IntegerExpression {
return IntExp(c.AS("UNSIGNED"))
}
// AS_CHAR casts expression to CHAR type with optional length
func (c *cast) AS_CHAR(length ...int) StringExpression {
if len(length) > 0 {
return StringExp(c.AS("CHAR(" + strconv.Itoa(length[0]) + ")"))
}
return StringExp(c.AS("CHAR"))
}
// AS_DATE casts expression AS DATE type
func (c *cast) AS_DATE() DateExpression {
return DateExp(c.AS("DATE"))
}
func (c *cast) AS_FLOAT() FloatExpression {
return FloatExp(c.AS("FLOAT"))
}
func (c *cast) AS_DOUBLE() FloatExpression {
return FloatExp(c.AS("DOUBLE"))
}
// AS_DECIMAL casts expression AS DECIMAL type
func (c *cast) AS_DECIMAL() FloatExpression {
return FloatExp(c.AS("DECIMAL"))
}
// AS_TIME casts expression AS TIME type
func (c *cast) AS_TIME() TimeExpression {
return TimeExp(c.AS("TIME"))
}
// AS_BINARY casts expression as BINARY type
func (c *cast) AS_BINARY() BlobExpression {
return BlobExp(c.AS("BINARY"))
}