11package query
22
33import (
4+ "fmt"
5+ "reflect"
6+
7+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
48 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
59 "github.com/ydb-platform/ydb-go-sdk/v3/query"
610)
@@ -17,6 +21,45 @@ func newScannerNamed(data *scannerData) scannerNamed {
1721 }
1822}
1923
24+ func (s scannerNamed ) seekByName (name string ) (
25+ value.Value ,
26+ error ,
27+ ) {
28+ for i := range s .data .columns {
29+ if s .data .columns [i ].GetName () == name {
30+ return value .FromYDB (s .data .columns [i ].GetType (), s .data .values [i ]), nil
31+ }
32+ }
33+
34+ return nil , xerrors .WithStackTrace (fmt .Errorf ("'%s': %w" , name , errColumnNotFoundByName ))
35+ }
36+
2037func (s scannerNamed ) ScanNamed (dst ... query.NamedDestination ) error {
21- return xerrors .WithStackTrace (ErrNotImplemented )
38+ if len (dst ) != len (s .data .columns ) {
39+ return xerrors .WithStackTrace (errWrongArgumentsCount )
40+ }
41+
42+ for i := range dst {
43+ v , err := s .seekByName (dst [i ].Name ())
44+ if err != nil {
45+ return xerrors .WithStackTrace (err )
46+ }
47+ if err := value .CastTo (v , dst [i ].Destination ()); err != nil {
48+ to := reflect .ValueOf (dst [i ].Destination ())
49+ if to .Kind () != reflect .Pointer {
50+ return xerrors .WithStackTrace (
51+ fmt .Errorf ("dst[%d].Destination() type is not a pointer ('%s')" , i ,
52+ to .Kind ().String (),
53+ ))
54+ }
55+ vv := reflect .ValueOf (v )
56+ if vv .CanConvert (to .Elem ().Type ()) {
57+ to .Elem ().Set (vv .Convert (to .Elem ().Type ()))
58+ } else {
59+ return xerrors .WithStackTrace (err )
60+ }
61+ }
62+ }
63+
64+ return nil
2265}
0 commit comments