MCPcopy Create free account
hub / github.com/lib/pq / Scan

Method Scan

array.go:388–418  ·  view source on GitHub ↗

Scan implements the sql.Scanner interface.

(src any)

Source from the content-addressed store, hash-verified

386
387// Scan implements the sql.Scanner interface.
388func (a GenericArray) Scan(src any) error {
389 dpv := reflect.ValueOf(a.A)
390 switch {
391 case dpv.Kind() != reflect.Pointer:
392 return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A)
393 case dpv.IsNil():
394 return fmt.Errorf("pq: destination %T is nil", a.A)
395 }
396
397 dv := dpv.Elem()
398 switch dv.Kind() {
399 case reflect.Slice:
400 case reflect.Array:
401 default:
402 return fmt.Errorf("pq: destination %T is not a pointer to array or slice", a.A)
403 }
404
405 switch src := src.(type) {
406 case []byte:
407 return a.scanBytes(src, dv)
408 case string:
409 return a.scanBytes([]byte(src), dv)
410 case nil:
411 if dv.Kind() == reflect.Slice {
412 dv.Set(reflect.Zero(dv.Type()))
413 return nil
414 }
415 }
416
417 return fmt.Errorf("pq: cannot convert %T to %s", src, dv.Type())
418}
419
420func (a GenericArray) scanBytes(src []byte, dv reflect.Value) error {
421 dtype, assign, del := a.evaluateDestination(dv.Type().Elem())

Callers

nothing calls this directly

Calls 2

scanBytesMethod · 0.95
TypeMethod · 0.80

Tested by

no test coverage detected