MCPcopy Index your code
hub / github.com/lib/pq / evaluateDestination

Method evaluateDestination

array.go:352–385  ·  view source on GitHub ↗
(rt reflect.Type)

Source from the content-addressed store, hash-verified

350type GenericArray struct{ A any }
351
352func (GenericArray) evaluateDestination(rt reflect.Type) (reflect.Type, func([]byte, reflect.Value) error, string) {
353 var assign func([]byte, reflect.Value) error
354 var del = ","
355
356 // TODO calculate the assign function for other types
357 // TODO repeat this section on the element type of arrays or slices (multidimensional)
358 {
359 if reflect.PointerTo(rt).Implements(typeSQLScanner) {
360 // dest is always addressable because it is an element of a slice.
361 assign = func(src []byte, dest reflect.Value) (err error) {
362 ss := dest.Addr().Interface().(sql.Scanner)
363 if src == nil {
364 err = ss.Scan(nil)
365 } else {
366 err = ss.Scan(src)
367 }
368 return
369 }
370 goto FoundType
371 }
372
373 assign = func([]byte, reflect.Value) error {
374 return fmt.Errorf("pq: scanning to %s is not implemented; only sql.Scanner", rt)
375 }
376 }
377
378FoundType:
379
380 if ad, ok := reflect.Zero(rt).Interface().(ArrayDelimiter); ok {
381 del = ad.ArrayDelimiter()
382 }
383
384 return rt, assign, del
385}
386
387// Scan implements the sql.Scanner interface.
388func (a GenericArray) Scan(src any) error {

Callers 1

scanBytesMethod · 0.95

Calls 2

ArrayDelimiterMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected