Scan implements the sql.Scanner interface.
(src any)
| 386 | |
| 387 | // Scan implements the sql.Scanner interface. |
| 388 | func (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 | |
| 420 | func (a GenericArray) scanBytes(src []byte, dv reflect.Value) error { |
| 421 | dtype, assign, del := a.evaluateDestination(dv.Type().Elem()) |