github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/table/result/named/named.go (about)

     1  package named
     2  
     3  type Type uint8
     4  
     5  const (
     6  	TypeUnknown Type = iota
     7  	TypeRequired
     8  	TypeOptional
     9  	TypeOptionalWithUseDefault
    10  )
    11  
    12  type Value struct {
    13  	Name  string
    14  	Value interface{}
    15  	Type  Type
    16  }
    17  
    18  // Optional makes an object with destination address for column value with name columnName
    19  //
    20  // # If column value is NULL, then ScanNamed will write a nil into destination
    21  //
    22  // Warning: value must double-pointed data destination
    23  func Optional(columnName string, destination interface{}) Value {
    24  	if columnName == "" {
    25  		panic("columnName must be not empty")
    26  	}
    27  
    28  	return Value{
    29  		Name:  columnName,
    30  		Value: destination,
    31  		Type:  TypeOptional,
    32  	}
    33  }
    34  
    35  // Required makes an object with destination address for column value with name columnName
    36  //
    37  // Warning: value must single-pointed data destination
    38  func Required(columnName string, destinationValueReference interface{}) Value {
    39  	if columnName == "" {
    40  		panic("columnName must be not empty")
    41  	}
    42  
    43  	return Value{
    44  		Name:  columnName,
    45  		Value: destinationValueReference,
    46  		Type:  TypeRequired,
    47  	}
    48  }
    49  
    50  // OptionalWithDefault makes an object with destination address for column value with name columnName
    51  //
    52  // If scanned YDB value is NULL - default type value will be applied to value destination
    53  // Warning: value must single-pointed data destination
    54  func OptionalWithDefault(columnName string, destinationValueReference interface{}) Value {
    55  	if columnName == "" {
    56  		panic("columnName must be not empty")
    57  	}
    58  
    59  	return Value{
    60  		Name:  columnName,
    61  		Value: destinationValueReference,
    62  		Type:  TypeOptionalWithUseDefault,
    63  	}
    64  }