github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/params/tuple.go (about)

     1  package params
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/google/uuid"
     7  
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
     9  )
    10  
    11  type (
    12  	tuple struct {
    13  		parent Builder
    14  		name   string
    15  		values []value.Value
    16  	}
    17  	tupleItem struct {
    18  		parent *tuple
    19  	}
    20  )
    21  
    22  func (t *tuple) Add() *tupleItem {
    23  	return &tupleItem{
    24  		parent: t,
    25  	}
    26  }
    27  
    28  func (t *tuple) AddItems(items ...value.Value) *tuple {
    29  	t.values = append(t.values, items...)
    30  
    31  	return t
    32  }
    33  
    34  func (t *tuple) EndTuple() Builder {
    35  	t.parent.params = append(t.parent.params, &Parameter{
    36  		parent: t.parent,
    37  		name:   t.name,
    38  		value:  value.TupleValue(t.values...),
    39  	})
    40  
    41  	return t.parent
    42  }
    43  
    44  func (t *tupleItem) Text(v string) *tuple {
    45  	t.parent.values = append(t.parent.values, value.TextValue(v))
    46  
    47  	return t.parent
    48  }
    49  
    50  func (t *tupleItem) Bytes(v []byte) *tuple {
    51  	t.parent.values = append(t.parent.values, value.BytesValue(v))
    52  
    53  	return t.parent
    54  }
    55  
    56  func (t *tupleItem) Bool(v bool) *tuple {
    57  	t.parent.values = append(t.parent.values, value.BoolValue(v))
    58  
    59  	return t.parent
    60  }
    61  
    62  func (t *tupleItem) Uint64(v uint64) *tuple {
    63  	t.parent.values = append(t.parent.values, value.Uint64Value(v))
    64  
    65  	return t.parent
    66  }
    67  
    68  func (t *tupleItem) Int64(v int64) *tuple {
    69  	t.parent.values = append(t.parent.values, value.Int64Value(v))
    70  
    71  	return t.parent
    72  }
    73  
    74  func (t *tupleItem) Uint32(v uint32) *tuple {
    75  	t.parent.values = append(t.parent.values, value.Uint32Value(v))
    76  
    77  	return t.parent
    78  }
    79  
    80  func (t *tupleItem) Int32(v int32) *tuple {
    81  	t.parent.values = append(t.parent.values, value.Int32Value(v))
    82  
    83  	return t.parent
    84  }
    85  
    86  func (t *tupleItem) Uint16(v uint16) *tuple {
    87  	t.parent.values = append(t.parent.values, value.Uint16Value(v))
    88  
    89  	return t.parent
    90  }
    91  
    92  func (t *tupleItem) Int16(v int16) *tuple {
    93  	t.parent.values = append(t.parent.values, value.Int16Value(v))
    94  
    95  	return t.parent
    96  }
    97  
    98  func (t *tupleItem) Uint8(v uint8) *tuple {
    99  	t.parent.values = append(t.parent.values, value.Uint8Value(v))
   100  
   101  	return t.parent
   102  }
   103  
   104  func (t *tupleItem) Int8(v int8) *tuple {
   105  	t.parent.values = append(t.parent.values, value.Int8Value(v))
   106  
   107  	return t.parent
   108  }
   109  
   110  func (t *tupleItem) Float(v float32) *tuple {
   111  	t.parent.values = append(t.parent.values, value.FloatValue(v))
   112  
   113  	return t.parent
   114  }
   115  
   116  func (t *tupleItem) Double(v float64) *tuple {
   117  	t.parent.values = append(t.parent.values, value.DoubleValue(v))
   118  
   119  	return t.parent
   120  }
   121  
   122  func (t *tupleItem) Decimal(v [16]byte, precision, scale uint32) *tuple {
   123  	t.parent.values = append(t.parent.values, value.DecimalValue(v, precision, scale))
   124  
   125  	return t.parent
   126  }
   127  
   128  func (t *tupleItem) Timestamp(v time.Time) *tuple {
   129  	t.parent.values = append(t.parent.values, value.TimestampValueFromTime(v))
   130  
   131  	return t.parent
   132  }
   133  
   134  func (t *tupleItem) Date(v time.Time) *tuple {
   135  	t.parent.values = append(t.parent.values, value.DateValueFromTime(v))
   136  
   137  	return t.parent
   138  }
   139  
   140  func (t *tupleItem) Datetime(v time.Time) *tuple {
   141  	t.parent.values = append(t.parent.values, value.DatetimeValueFromTime(v))
   142  
   143  	return t.parent
   144  }
   145  
   146  func (t *tupleItem) Interval(v time.Duration) *tuple {
   147  	t.parent.values = append(t.parent.values, value.IntervalValueFromDuration(v))
   148  
   149  	return t.parent
   150  }
   151  
   152  func (t *tupleItem) JSON(v string) *tuple {
   153  	t.parent.values = append(t.parent.values, value.JSONValue(v))
   154  
   155  	return t.parent
   156  }
   157  
   158  func (t *tupleItem) JSONDocument(v string) *tuple {
   159  	t.parent.values = append(t.parent.values, value.JSONDocumentValue(v))
   160  
   161  	return t.parent
   162  }
   163  
   164  func (t *tupleItem) YSON(v []byte) *tuple {
   165  	t.parent.values = append(t.parent.values, value.YSONValue(v))
   166  
   167  	return t.parent
   168  }
   169  
   170  //// UUID has data corruption bug and will be removed in next version.
   171  ////
   172  //// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
   173  //// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
   174  //func (t *tupleItem) UUID(v [16]byte) *tuple {
   175  //	t.parent.values = append(t.parent.values, value.UUIDWithIssue1501Value(v))
   176  //
   177  //	return t.parent
   178  //}
   179  
   180  func (t *tupleItem) Uuid(v uuid.UUID) *tuple { //nolint:revive,stylecheck
   181  	t.parent.values = append(t.parent.values, value.Uuid(v))
   182  
   183  	return t.parent
   184  }
   185  
   186  func (t *tupleItem) UUIDWithIssue1501Value(v [16]byte) *tuple {
   187  	t.parent.values = append(t.parent.values, value.UUIDWithIssue1501Value(v))
   188  
   189  	return t.parent
   190  }
   191  
   192  func (t *tupleItem) TzDate(v time.Time) *tuple {
   193  	t.parent.values = append(t.parent.values, value.TzDateValueFromTime(v))
   194  
   195  	return t.parent
   196  }
   197  
   198  func (t *tupleItem) TzTimestamp(v time.Time) *tuple {
   199  	t.parent.values = append(t.parent.values, value.TzTimestampValueFromTime(v))
   200  
   201  	return t.parent
   202  }
   203  
   204  func (t *tupleItem) TzDatetime(v time.Time) *tuple {
   205  	t.parent.values = append(t.parent.values, value.TzDatetimeValueFromTime(v))
   206  
   207  	return t.parent
   208  }