MCPcopy Create free account
hub / github.com/uptrace/bun / arrayScanner

Function arrayScanner

dialect/pgdialect/array.go:339–412  ·  view source on GitHub ↗

------------------------------------------------------------------------------

(typ reflect.Type)

Source from the content-addressed store, hash-verified

337//------------------------------------------------------------------------------
338
339func arrayScanner(typ reflect.Type) schema.ScannerFunc {
340 kind := typ.Kind()
341
342 switch kind {
343 case reflect.Ptr:
344 if fn := arrayScanner(typ.Elem()); fn != nil {
345 return schema.PtrScanner(fn)
346 }
347 case reflect.Slice, reflect.Array:
348 // ok:
349 default:
350 return nil
351 }
352
353 elemType := typ.Elem()
354
355 if kind == reflect.Slice {
356 switch elemType {
357 case stringType:
358 return scanStringSliceValue
359 case intType:
360 return scanIntSliceValue
361 case int64Type:
362 return scanInt64SliceValue
363 case float64Type:
364 return scanFloat64SliceValue
365 }
366 }
367
368 scanElem := schema.Scanner(elemType)
369 return func(dest reflect.Value, src any) error {
370 dest = reflect.Indirect(dest)
371 if !dest.CanSet() {
372 return fmt.Errorf("bun: Scan(non-settable %s)", dest.Type())
373 }
374
375 kind := dest.Kind()
376
377 if src == nil {
378 if kind != reflect.Slice || !dest.IsNil() {
379 dest.Set(reflect.Zero(dest.Type()))
380 }
381 return nil
382 }
383
384 if kind == reflect.Slice {
385 if dest.IsNil() {
386 dest.Set(reflect.MakeSlice(dest.Type(), 0, 0))
387 } else if dest.Len() > 0 {
388 dest.Set(dest.Slice(0, 0))
389 }
390 }
391
392 if src == nil {
393 return nil
394 }
395
396 b, err := toBytes(src)

Callers 2

ArrayFunction · 0.85
onFieldMethod · 0.85

Calls 11

PtrScannerFunction · 0.92
ScannerFunction · 0.92
MakeSliceNextElemFuncFunction · 0.92
newArrayParserFunction · 0.85
scanElemFunction · 0.85
ElemMethod · 0.80
toBytesFunction · 0.70
SetMethod · 0.45
LenMethod · 0.45
NextMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…