forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
79 lines (63 loc) · 1.79 KB
/
field.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
package field
import (
"database/sql/driver"
"gorm.io/gorm/clause"
)
// ScanValuer interface for Field
type ScanValuer interface {
Scan(src interface{}) error // sql.Scanner
Value() (driver.Value, error) // driver.Valuer
}
// Field a standard field struct
type Field struct{ expr }
// Eq judge equal
func (field Field) Eq(value driver.Valuer) Expr {
return expr{e: clause.Eq{Column: field.RawExpr(), Value: value}}
}
// Neq judge not equal
func (field Field) Neq(value driver.Valuer) Expr {
return expr{e: clause.Neq{Column: field.RawExpr(), Value: value}}
}
// In ...
func (field Field) In(values ...driver.Valuer) Expr {
return expr{e: clause.IN{Column: field.RawExpr(), Values: field.toSlice(values...)}}
}
// Gt ...
func (field Field) Gt(value driver.Valuer) Expr {
return expr{e: clause.Gt{Column: field.RawExpr(), Value: value}}
}
// Gte ...
func (field Field) Gte(value driver.Valuer) Expr {
return expr{e: clause.Gte{Column: field.RawExpr(), Value: value}}
}
// Lt ...
func (field Field) Lt(value driver.Valuer) Expr {
return expr{e: clause.Lt{Column: field.RawExpr(), Value: value}}
}
// Lte ...
func (field Field) Lte(value driver.Valuer) Expr {
return expr{e: clause.Lte{Column: field.RawExpr(), Value: value}}
}
// Like ...
func (field Field) Like(value driver.Valuer) Expr {
return expr{e: clause.Like{Column: field.RawExpr(), Value: value}}
}
// Value ...
func (field Field) Value(value driver.Valuer) AssignExpr {
return field.value(value)
}
// Sum ...
func (field Field) Sum() Field {
return Field{field.sum()}
}
// IfNull ...
func (field Field) IfNull(value driver.Valuer) Expr {
return field.ifNull(value)
}
func (field Field) toSlice(values ...driver.Valuer) []interface{} {
slice := make([]interface{}, len(values))
for i, v := range values {
slice[i] = v
}
return slice
}