-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_float.go
77 lines (64 loc) · 2 KB
/
access_float.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
package pgtalk
import (
"strings"
"github.com/jackc/pgx/v5/pgtype"
)
// float64Access can Read a column value (float) and Write a column value and Set a struct field (float64).
type float64Access struct {
unimplementedBooleanExpression
ColumnInfo
fieldWriter fieldAccessFunc
nullableFieldWriter func(dest any, f pgtype.Float8)
valueToInsert float64
}
func NewFloat64Access(info ColumnInfo, writer fieldAccessFunc) float64Access {
return float64Access{ColumnInfo: info, fieldWriter: writer}
}
func (a float64Access) ValueToInsert() any {
return a.ValueToInsert
}
func (a float64Access) Set(v float64) float64Access {
a.valueToInsert = v
return a
}
func (a float64Access) Column() ColumnInfo { return a.ColumnInfo }
func (a float64Access) Equals(isFloatLike any) binaryExpression {
return a.Compare("=", isFloatLike)
}
func (a float64Access) Compare(op string, isFloatLike any) binaryExpression {
if !strings.Contains(validComparisonOperators, op) {
panic("invalid comparison operator:" + op)
}
if f, ok := isFloatLike.(float64); ok {
return makeBinaryOperator(a, op, valuePrinter{v: f})
}
if ta, ok := isFloatLike.(float64Access); ok {
return makeBinaryOperator(a, op, ta)
}
if qa, ok := isFloatLike.(*QueryParameter); ok {
if _, ok := qa.value.(float64); ok {
return makeBinaryOperator(a, op, qa)
}
}
panic("float64, Float64Access or *QueryArgument[float64] expected")
}
func (a float64Access) FieldValueToScan(entity any) any {
return a.fieldWriter(entity)
}
// TableAlias changes the table alias for this column accessor.
func (a float64Access) TableAlias(alias string) float64Access {
a.ColumnInfo = a.ColumnInfo.TableAlias(alias)
return a
}
// AppendScannable is part of ColumnAccessor
func (a float64Access) AppendScannable(list []any) []any {
return append(list, &a.valueToInsert)
}
// Get returns the value for its columnName from a map (row).
func (a float64Access) Get(values map[string]any) any {
v, ok := values[a.columnName]
if !ok {
return float64(0.0)
}
return v
}