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

Method TypeForValue

pgtype/pgtype.go:330–341  ·  view source on GitHub ↗

TypeForValue finds a data type suitable for v. Use [Map.RegisterType] to register types that can encode and decode themselves. Use [Map.RegisterDefaultPgType] to register that can be handled by a registered data type. The returned [Type] must not be mutated.

(v any)

Source from the content-addressed store, hash-verified

328// themselves. Use [Map.RegisterDefaultPgType] to register that can be handled by a registered data type. The returned [Type]
329// must not be mutated.
330func (m *Map) TypeForValue(v any) (*Type, bool) {
331 if m.reflectTypeToType == nil {
332 m.buildReflectTypeToType()
333 }
334
335 if dt, ok := m.reflectTypeToType[reflect.TypeOf(v)]; ok {
336 return dt, true
337 }
338
339 dt, ok := defaultMap.reflectTypeToType[reflect.TypeOf(v)]
340 return dt, ok
341}
342
343// FormatCodeForOID returns the preferred format code for type oid. If the type is not registered it returns the text
344// format code.

Callers 3

planScanMethod · 0.95
planEncodeMethod · 0.95
ScanMethod · 0.80

Calls 1

Tested by

no test coverage detected