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

     1  package types
     2  
     3  import (
     4  	"math/big"
     5  	"time"
     6  
     7  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/decimal"
     8  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
     9  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/xstring"
    10  )
    11  
    12  type Value = value.Value
    13  
    14  func BoolValue(v bool) Value { return value.BoolValue(v) }
    15  
    16  func Int8Value(v int8) Value { return value.Int8Value(v) }
    17  
    18  func Uint8Value(v uint8) Value { return value.Uint8Value(v) }
    19  
    20  func Int16Value(v int16) Value { return value.Int16Value(v) }
    21  
    22  func Uint16Value(v uint16) Value { return value.Uint16Value(v) }
    23  
    24  func Int32Value(v int32) Value { return value.Int32Value(v) }
    25  
    26  func Uint32Value(v uint32) Value { return value.Uint32Value(v) }
    27  
    28  func Int64Value(v int64) Value { return value.Int64Value(v) }
    29  
    30  func Uint64Value(v uint64) Value { return value.Uint64Value(v) }
    31  
    32  func FloatValue(v float32) Value { return value.FloatValue(v) }
    33  
    34  func DoubleValue(v float64) Value { return value.DoubleValue(v) }
    35  
    36  // DateValue returns ydb date value by given days since Epoch
    37  func DateValue(v uint32) Value { return value.DateValue(v) }
    38  
    39  // DatetimeValue makes ydb datetime value from seconds since Epoch
    40  func DatetimeValue(v uint32) Value { return value.DatetimeValue(v) }
    41  
    42  // TimestampValue makes ydb timestamp value from microseconds since Epoch
    43  func TimestampValue(v uint64) Value { return value.TimestampValue(v) }
    44  
    45  // IntervalValueFromMicroseconds makes Value from given microseconds value
    46  func IntervalValueFromMicroseconds(v int64) Value { return value.IntervalValue(v) }
    47  
    48  // IntervalValue makes Value from given microseconds value
    49  //
    50  // Deprecated: use IntervalValueFromMicroseconds instead
    51  func IntervalValue(v int64) Value { return value.IntervalValue(v) }
    52  
    53  // TzDateValue makes TzDate value from string
    54  func TzDateValue(v string) Value { return value.TzDateValue(v) }
    55  
    56  // TzDatetimeValue makes TzDatetime value from string
    57  func TzDatetimeValue(v string) Value { return value.TzDatetimeValue(v) }
    58  
    59  // TzTimestampValue makes TzTimestamp value from string
    60  func TzTimestampValue(v string) Value { return value.TzTimestampValue(v) }
    61  
    62  // DateValueFromTime makes Date value from time.Time
    63  //
    64  // Warning: all *From* helpers will be removed at next major release
    65  // (functional will be implements with go1.18 type lists)
    66  func DateValueFromTime(t time.Time) Value {
    67  	return value.DateValueFromTime(t)
    68  }
    69  
    70  // DatetimeValueFromTime makes Datetime value from time.Time
    71  //
    72  // Warning: all *From* helpers will be removed at next major release
    73  // (functional will be implements with go1.18 type lists)
    74  func DatetimeValueFromTime(t time.Time) Value {
    75  	return value.DatetimeValueFromTime(t)
    76  }
    77  
    78  // TimestampValueFromTime makes Timestamp value from time.Time
    79  //
    80  // Warning: all *From* helpers will be removed at next major release
    81  // (functional will be implements with go1.18 type lists)
    82  func TimestampValueFromTime(t time.Time) Value {
    83  	return value.TimestampValueFromTime(t)
    84  }
    85  
    86  // IntervalValueFromDuration makes Interval value from time.Duration
    87  //
    88  // Warning: all *From* helpers will be removed at next major release
    89  // (functional will be implements with go1.18 type lists)
    90  func IntervalValueFromDuration(v time.Duration) Value {
    91  	return value.IntervalValueFromDuration(v)
    92  }
    93  
    94  // TzDateValueFromTime makes TzDate value from time.Time
    95  //
    96  // Warning: all *From* helpers will be removed at next major release
    97  // (functional will be implements with go1.18 type lists)
    98  func TzDateValueFromTime(t time.Time) Value {
    99  	return value.TzDateValueFromTime(t)
   100  }
   101  
   102  // TzDatetimeValueFromTime makes TzDatetime value from time.Time
   103  //
   104  // Warning: all *From* helpers will be removed at next major release
   105  // (functional will be implements with go1.18 type lists)
   106  func TzDatetimeValueFromTime(t time.Time) Value {
   107  	return value.TzDatetimeValueFromTime(t)
   108  }
   109  
   110  // TzTimestampValueFromTime makes TzTimestamp value from time.Time
   111  //
   112  // Warning: all *From* helpers will be removed at next major release
   113  // (functional will be implements with go1.18 type lists)
   114  func TzTimestampValueFromTime(t time.Time) Value {
   115  	return value.TzTimestampValueFromTime(t)
   116  }
   117  
   118  // StringValue returns bytes value
   119  //
   120  // Deprecated: use BytesValue instead
   121  func StringValue(v []byte) Value { return value.BytesValue(v) }
   122  
   123  func BytesValue(v []byte) Value { return value.BytesValue(v) }
   124  
   125  func BytesValueFromString(v string) Value { return value.BytesValue(xstring.ToBytes(v)) }
   126  
   127  // StringValueFromString makes String value from string
   128  //
   129  // Warning: all *From* helpers will be removed at next major release
   130  // (functional will be implements with go1.18 type lists)
   131  func StringValueFromString(v string) Value { return value.BytesValue(xstring.ToBytes(v)) }
   132  
   133  func UTF8Value(v string) Value { return value.TextValue(v) }
   134  
   135  func TextValue(v string) Value { return value.TextValue(v) }
   136  
   137  func YSONValue(v string) Value { return value.YSONValue(xstring.ToBytes(v)) }
   138  
   139  // YSONValueFromBytes makes YSON value from bytes
   140  //
   141  // Warning: all *From* helpers will be removed at next major release
   142  // (functional will be implements with go1.18 type lists)
   143  func YSONValueFromBytes(v []byte) Value { return value.YSONValue(v) }
   144  
   145  func JSONValue(v string) Value { return value.JSONValue(v) }
   146  
   147  // JSONValueFromBytes makes JSON value from bytes
   148  //
   149  // Warning: all *From* helpers will be removed at next major release
   150  // (functional will be implements with go1.18 type lists)
   151  func JSONValueFromBytes(v []byte) Value { return value.JSONValue(xstring.FromBytes(v)) }
   152  
   153  func UUIDValue(v [16]byte) Value { return value.UUIDValue(v) }
   154  
   155  func JSONDocumentValue(v string) Value { return value.JSONDocumentValue(v) }
   156  
   157  // JSONDocumentValueFromBytes makes JSONDocument value from bytes
   158  //
   159  // Warning: all *From* helpers will be removed at next major release
   160  // (functional will be implements with go1.18 type lists)
   161  func JSONDocumentValueFromBytes(v []byte) Value {
   162  	return value.JSONDocumentValue(xstring.FromBytes(v))
   163  }
   164  
   165  func DyNumberValue(v string) Value { return value.DyNumberValue(v) }
   166  
   167  func VoidValue() Value { return value.VoidValue() }
   168  
   169  func NullValue(t Type) Value { return value.NullValue(t) }
   170  
   171  func ZeroValue(t Type) Value { return value.ZeroValue(t) }
   172  
   173  func OptionalValue(v Value) Value { return value.OptionalValue(v) }
   174  
   175  // Decimal supported in scanner API
   176  type Decimal = decimal.Decimal
   177  
   178  // DecimalValue creates decimal value of given types t and value v.
   179  // Note that Decimal.Bytes interpreted as big-endian int128.
   180  func DecimalValue(v *Decimal) Value {
   181  	return value.DecimalValue(v.Bytes, v.Precision, v.Scale)
   182  }
   183  
   184  func DecimalValueFromBigInt(v *big.Int, precision, scale uint32) Value {
   185  	return value.DecimalValueFromBigInt(v, precision, scale)
   186  }
   187  
   188  func TupleValue(vs ...Value) Value {
   189  	return value.TupleValue(vs...)
   190  }
   191  
   192  func ListValue(vs ...Value) Value {
   193  	return value.ListValue(vs...)
   194  }
   195  
   196  func SetValue(vs ...Value) Value {
   197  	return value.SetValue(vs...)
   198  }
   199  
   200  type structValueFields struct {
   201  	fields []value.StructValueField
   202  }
   203  
   204  type StructValueOption func(*structValueFields)
   205  
   206  func StructFieldValue(name string, v Value) StructValueOption {
   207  	return func(t *structValueFields) {
   208  		t.fields = append(t.fields, value.StructValueField{Name: name, V: v})
   209  	}
   210  }
   211  
   212  func StructValue(opts ...StructValueOption) Value {
   213  	var p structValueFields
   214  	for _, opt := range opts {
   215  		if opt != nil {
   216  			opt(&p)
   217  		}
   218  	}
   219  
   220  	return value.StructValue(p.fields...)
   221  }
   222  
   223  type dictValueFields struct {
   224  	fields []value.DictValueField
   225  }
   226  
   227  type DictValueOption func(*dictValueFields)
   228  
   229  func DictFieldValue(k, v Value) DictValueOption {
   230  	return func(t *dictValueFields) {
   231  		t.fields = append(t.fields, value.DictValueField{K: k, V: v})
   232  	}
   233  }
   234  
   235  func DictValue(opts ...DictValueOption) Value {
   236  	var p dictValueFields
   237  	for _, opt := range opts {
   238  		if opt != nil {
   239  			opt(&p)
   240  		}
   241  	}
   242  
   243  	return value.DictValue(p.fields...)
   244  }
   245  
   246  func VariantValueStruct(v Value, name string, variantT Type) Value {
   247  	return value.VariantValueStruct(v, name, variantT)
   248  }
   249  
   250  func VariantValueTuple(v Value, i uint32, variantT Type) Value {
   251  	return value.VariantValueTuple(v, i, variantT)
   252  }
   253  
   254  func NullableBoolValue(v *bool) Value {
   255  	return value.NullableBoolValue(v)
   256  }
   257  
   258  func NullableInt8Value(v *int8) Value {
   259  	return value.NullableInt8Value(v)
   260  }
   261  
   262  func NullableInt16Value(v *int16) Value {
   263  	return value.NullableInt16Value(v)
   264  }
   265  
   266  func NullableInt32Value(v *int32) Value {
   267  	return value.NullableInt32Value(v)
   268  }
   269  
   270  func NullableInt64Value(v *int64) Value {
   271  	return value.NullableInt64Value(v)
   272  }
   273  
   274  func NullableUint8Value(v *uint8) Value {
   275  	return value.NullableUint8Value(v)
   276  }
   277  
   278  func NullableUint16Value(v *uint16) Value {
   279  	return value.NullableUint16Value(v)
   280  }
   281  
   282  func NullableUint32Value(v *uint32) Value {
   283  	return value.NullableUint32Value(v)
   284  }
   285  
   286  func NullableUint64Value(v *uint64) Value {
   287  	return value.NullableUint64Value(v)
   288  }
   289  
   290  func NullableFloatValue(v *float32) Value {
   291  	return value.NullableFloatValue(v)
   292  }
   293  
   294  func NullableDoubleValue(v *float64) Value {
   295  	return value.NullableDoubleValue(v)
   296  }
   297  
   298  func NullableDateValue(v *uint32) Value {
   299  	return value.NullableDateValue(v)
   300  }
   301  
   302  func NullableDateValueFromTime(v *time.Time) Value {
   303  	return value.NullableDateValueFromTime(v)
   304  }
   305  
   306  func NullableDatetimeValue(v *uint32) Value {
   307  	return value.NullableDatetimeValue(v)
   308  }
   309  
   310  func NullableDatetimeValueFromTime(v *time.Time) Value {
   311  	return value.NullableDatetimeValueFromTime(v)
   312  }
   313  
   314  func NullableTzDateValue(v *string) Value {
   315  	return value.NullableTzDateValue(v)
   316  }
   317  
   318  func NullableTzDateValueFromTime(v *time.Time) Value {
   319  	return value.NullableTzDateValueFromTime(v)
   320  }
   321  
   322  func NullableTzDatetimeValue(v *string) Value {
   323  	return value.NullableTzDatetimeValue(v)
   324  }
   325  
   326  func NullableTzDatetimeValueFromTime(v *time.Time) Value {
   327  	return value.NullableTzDatetimeValueFromTime(v)
   328  }
   329  
   330  func NullableTimestampValue(v *uint64) Value {
   331  	return value.NullableTimestampValue(v)
   332  }
   333  
   334  func NullableTimestampValueFromTime(v *time.Time) Value {
   335  	return value.NullableTimestampValueFromTime(v)
   336  }
   337  
   338  func NullableTzTimestampValue(v *string) Value {
   339  	return value.NullableTzTimestampValue(v)
   340  }
   341  
   342  func NullableTzTimestampValueFromTime(v *time.Time) Value {
   343  	return value.NullableTzTimestampValueFromTime(v)
   344  }
   345  
   346  // NullableIntervalValue makes Value which maybe nil or valued
   347  //
   348  // Deprecated: use NullableIntervalValueFromMicroseconds instead
   349  func NullableIntervalValue(v *int64) Value {
   350  	return value.NullableIntervalValueFromMicroseconds(v)
   351  }
   352  
   353  func NullableIntervalValueFromMicroseconds(v *int64) Value {
   354  	return value.NullableIntervalValueFromMicroseconds(v)
   355  }
   356  
   357  func NullableIntervalValueFromDuration(v *time.Duration) Value {
   358  	return value.NullableIntervalValueFromDuration(v)
   359  }
   360  
   361  // NullableStringValue
   362  //
   363  // Deprecated: use NullableBytesValue instead
   364  func NullableStringValue(v *[]byte) Value {
   365  	return value.NullableBytesValue(v)
   366  }
   367  
   368  func NullableBytesValue(v *[]byte) Value {
   369  	return value.NullableBytesValue(v)
   370  }
   371  
   372  func NullableStringValueFromString(v *string) Value {
   373  	return value.NullableBytesValueFromString(v)
   374  }
   375  
   376  func NullableBytesValueFromString(v *string) Value {
   377  	return value.NullableBytesValueFromString(v)
   378  }
   379  
   380  func NullableUTF8Value(v *string) Value {
   381  	return value.NullableTextValue(v)
   382  }
   383  
   384  func NullableTextValue(v *string) Value {
   385  	return value.NullableTextValue(v)
   386  }
   387  
   388  func NullableYSONValue(v *string) Value {
   389  	return value.NullableYSONValue(v)
   390  }
   391  
   392  func NullableYSONValueFromBytes(v *[]byte) Value {
   393  	return value.NullableYSONValueFromBytes(v)
   394  }
   395  
   396  func NullableJSONValue(v *string) Value {
   397  	return value.NullableJSONValue(v)
   398  }
   399  
   400  func NullableJSONValueFromBytes(v *[]byte) Value {
   401  	return value.NullableJSONValueFromBytes(v)
   402  }
   403  
   404  func NullableUUIDValue(v *[16]byte) Value {
   405  	return value.NullableUUIDValue(v)
   406  }
   407  
   408  func NullableJSONDocumentValue(v *string) Value {
   409  	return value.NullableJSONDocumentValue(v)
   410  }
   411  
   412  func NullableJSONDocumentValueFromBytes(v *[]byte) Value {
   413  	return value.NullableJSONDocumentValueFromBytes(v)
   414  }
   415  
   416  func NullableDyNumberValue(v *string) Value {
   417  	return value.NullableDyNumberValue(v)
   418  }
   419  
   420  func Nullable(t Type, v interface{}) Value {
   421  	return value.Nullable(t, v)
   422  }