-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_int64.go
91 lines (77 loc) · 2.23 KB
/
access_int64.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
package pgtalk
import (
"strings"
)
// int64Access can Read a column value (int8) and Write a column value and Set a struct field (int64).
type int64Access struct {
unimplementedBooleanExpression
ColumnInfo
fieldWriter fieldAccessFunc
valueToInsert int64
}
func NewInt64Access(
info ColumnInfo,
valueWriter func(dest any) any) int64Access {
return int64Access{
ColumnInfo: info,
fieldWriter: valueWriter}
}
func (a int64Access) BetweenAnd(begin int64, end int64) betweenAnd {
return makeBetweenAnd(a, valuePrinter{v: begin}, valuePrinter{v: end})
}
func (a int64Access) FieldValueToScan(entity any) any {
return a.fieldWriter(entity)
}
func (a int64Access) ValueToInsert() any {
return a.valueToInsert
}
func (a int64Access) Set(v int64) int64Access {
a.valueToInsert = v
return a
}
func (a int64Access) Equals(intLike any) binaryExpression {
if i, ok := intLike.(int); ok {
return makeBinaryOperator(a, "=", valuePrinter{v: i})
}
if ia, ok := intLike.(int64Access); ok {
return makeBinaryOperator(a, "=", ia)
}
if p, ok := intLike.(*QueryParameter); ok {
return makeBinaryOperator(a, "=", p)
}
panic("int or Int64Access or *QueryParameter expected")
}
func (a int64Access) Compare(op string, i int) binaryExpression {
if !strings.Contains(validComparisonOperators, op) {
panic("invalid comparison operator:" + op)
}
return makeBinaryOperator(a, op, valuePrinter{v: i})
}
func (a int64Access) Column() ColumnInfo { return a.ColumnInfo }
// TableAlias changes the table alias for this column accessor.
func (a int64Access) TableAlias(alias string) int64Access {
a.ColumnInfo = a.ColumnInfo.TableAlias(alias)
return a
}
// AppendScannable is part of ColumnAccessor
func (a int64Access) AppendScannable(list []any) []any {
return append(list, &a.valueToInsert)
}
// Get returns the value for its columnName from a map (row).
func (a int64Access) Get(values map[string]any) any {
v, ok := values[a.columnName]
if !ok {
return int64(0)
}
return v
}
func (a int64Access) In(values ...int32) SQLExpression {
if len(values) == 0 {
return makeConstantExpression(false)
}
vs := make([]any, len(values))
for i := 0; i < len(values); i++ {
vs[i] = values[i]
}
return makeBinaryOperator(a, "IN", valuesPrinter{vs: vs})
}