MCPcopy
hub / github.com/jackc/pgx / tryScanStringCopyValueThenEncode

Function tryScanStringCopyValueThenEncode

values.go:46–63  ·  view source on GitHub ↗
(m *pgtype.Map, buf []byte, oid uint32, arg any)

Source from the content-addressed store, hash-verified

44}
45
46func tryScanStringCopyValueThenEncode(m *pgtype.Map, buf []byte, oid uint32, arg any) ([]byte, error) {
47 s, ok := arg.(string)
48 if !ok {
49 textBuf, err := m.Encode(oid, TextFormatCode, arg, nil)
50 if err != nil {
51 return nil, errors.New("not a string and cannot be encoded as text")
52 }
53 s = string(textBuf)
54 }
55
56 var v any
57 err := m.Scan(oid, TextFormatCode, []byte(s), &v)
58 if err != nil {
59 return nil, err
60 }
61
62 return m.Encode(oid, BinaryFormatCode, v, buf)
63}

Callers 1

encodeCopyValueFunction · 0.85

Calls 2

EncodeMethod · 0.65
ScanMethod · 0.65

Tested by

no test coverage detected