github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/query/scanner/data.go (about)

     1  package scanner
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
     7  
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
    10  )
    11  
    12  type data struct {
    13  	columns []*Ydb.Column
    14  	values  []*Ydb.Value
    15  }
    16  
    17  func Data(columns []*Ydb.Column, values []*Ydb.Value) *data {
    18  	return &data{
    19  		columns: columns,
    20  		values:  values,
    21  	}
    22  }
    23  
    24  func (s data) seekByName(name string) (value.Value, error) {
    25  	for i := range s.columns {
    26  		if s.columns[i].GetName() == name {
    27  			return value.FromYDB(s.columns[i].GetType(), s.values[i]), nil
    28  		}
    29  	}
    30  
    31  	return nil, xerrors.WithStackTrace(fmt.Errorf("'%s': %w", name, errColumnsNotFoundInRow))
    32  }
    33  
    34  func (s data) seekByIndex(idx int) value.Value {
    35  	return value.FromYDB(s.columns[idx].GetType(), s.values[idx])
    36  }