-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_bytes.go
50 lines (41 loc) · 1.2 KB
/
access_bytes.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
package pgtalk
// bytesAccess can Read a column value (jsonb) and Write a column value and Set a struct field ([]byte).
type bytesAccess struct {
ColumnInfo
valueFieldWriter func(dest any) *string
valueToInsert []byte
}
func NewBytesAccess(info ColumnInfo,
valueWriter func(dest any) *string) bytesAccess {
return bytesAccess{ColumnInfo: info,
valueFieldWriter: valueWriter,
}
}
func (a bytesAccess) Column() ColumnInfo { return a.ColumnInfo }
func (a bytesAccess) FieldValueToScan(entity any) any {
return a.valueFieldWriter(entity)
}
func (a bytesAccess) ValueToInsert() any {
return a.valueToInsert
}
func (a bytesAccess) Set(v []byte) bytesAccess {
a.valueToInsert = v
return a
}
// TableAlias changes the table alias for this column accessor.
func (a bytesAccess) TableAlias(alias string) bytesAccess {
a.ColumnInfo = a.ColumnInfo.TableAlias(alias)
return a
}
// AppendScannable is part of ColumnAccessor
func (a bytesAccess) AppendScannable(list []any) []any {
return append(list, &a.valueToInsert)
}
// Get returns the value for its columnName from a map (row).
func (a bytesAccess) Get(values map[string]any) any {
v, ok := values[a.columnName]
if !ok {
return []byte{}
}
return v
}