Skip to content

Commit

Permalink
Added Tuple support for ydb.ParamsBuilder()
Browse files Browse the repository at this point in the history
  • Loading branch information
NovruzovE committed Mar 18, 2024
1 parent 4315955 commit c83797b
Show file tree
Hide file tree
Showing 4 changed files with 915 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Added `internal/xsync.{OnceFunc,OnceValue}`
* Updated `google.golang.org/protobuf` from `v1.31.0` to `v.33.0`
* Added `ydb.ParamsBuilder().Pg().{Value,Int4,Int8,Unknown}` for postgres arguments
* Added `Tuple` support for `ydb.ParamsBuilder()`

## v3.57.4
* Added client pid to each gRPC requests to YDB over header `x-ydb-client-pid`
Expand Down
7 changes: 7 additions & 0 deletions internal/params/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ func (p *Parameter) BeginDict() *dict {
}
}

func (p *Parameter) BeginTuple() *tuple {
return &tuple{
parent: p.parent,
name: p.name,
}
}

func (p *Parameter) Text(v string) Builder {
p.value = value.TextValue(v)
p.parent.params = append(p.parent.params, p)
Expand Down
172 changes: 172 additions & 0 deletions internal/params/tuple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package params

import (
"time"

"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
)

type (
tuple struct {
parent Builder
name string
values []value.Value
}
tupleItem struct {
parent *tuple
}
)

func (t *tuple) Add() *tupleItem {
return &tupleItem{
parent: t,
}
}

func (t *tuple) AddItems(items ...value.Value) *tuple {
t.values = append(t.values, items...)

return t
}

func (t *tuple) EndTuple() Builder {
t.parent.params = append(t.parent.params, &Parameter{
parent: t.parent,
name: t.name,
value: value.TupleValue(t.values...),
})

return t.parent
}

func (t *tupleItem) Text(v string) *tuple {
t.parent.values = append(t.parent.values, value.TextValue(v))

return t.parent
}

func (t *tupleItem) Bytes(v []byte) *tuple {
t.parent.values = append(t.parent.values, value.BytesValue(v))

return t.parent
}

func (t *tupleItem) Bool(v bool) *tuple {
t.parent.values = append(t.parent.values, value.BoolValue(v))

return t.parent
}

func (t *tupleItem) Uint64(v uint64) *tuple {
t.parent.values = append(t.parent.values, value.Uint64Value(v))

return t.parent
}

func (t *tupleItem) Int64(v int64) *tuple {
t.parent.values = append(t.parent.values, value.Int64Value(v))

return t.parent
}

func (t *tupleItem) Uint32(v uint32) *tuple {
t.parent.values = append(t.parent.values, value.Uint32Value(v))

return t.parent
}

func (t *tupleItem) Int32(v int32) *tuple {
t.parent.values = append(t.parent.values, value.Int32Value(v))

return t.parent
}

func (t *tupleItem) Uint16(v uint16) *tuple {
t.parent.values = append(t.parent.values, value.Uint16Value(v))

return t.parent
}

func (t *tupleItem) Int16(v int16) *tuple {
t.parent.values = append(t.parent.values, value.Int16Value(v))

return t.parent
}

func (t *tupleItem) Uint8(v uint8) *tuple {
t.parent.values = append(t.parent.values, value.Uint8Value(v))

return t.parent
}

func (t *tupleItem) Int8(v int8) *tuple {
t.parent.values = append(t.parent.values, value.Int8Value(v))

return t.parent
}

func (t *tupleItem) Float(v float32) *tuple {
t.parent.values = append(t.parent.values, value.FloatValue(v))

return t.parent
}

func (t *tupleItem) Double(v float64) *tuple {
t.parent.values = append(t.parent.values, value.DoubleValue(v))

return t.parent
}

func (t *tupleItem) Decimal(v [16]byte, precision, scale uint32) *tuple {
t.parent.values = append(t.parent.values, value.DecimalValue(v, precision, scale))

return t.parent
}

func (t *tupleItem) Timestamp(v time.Time) *tuple {
t.parent.values = append(t.parent.values, value.TimestampValueFromTime(v))

return t.parent
}

func (t *tupleItem) Date(v time.Time) *tuple {
t.parent.values = append(t.parent.values, value.DateValueFromTime(v))

return t.parent
}

func (t *tupleItem) Datetime(v time.Time) *tuple {
t.parent.values = append(t.parent.values, value.DatetimeValueFromTime(v))

return t.parent
}

func (t *tupleItem) Interval(v time.Duration) *tuple {
t.parent.values = append(t.parent.values, value.IntervalValueFromDuration(v))

return t.parent
}

func (t *tupleItem) JSON(v string) *tuple {
t.parent.values = append(t.parent.values, value.JSONValue(v))

return t.parent
}

func (t *tupleItem) JSONDocument(v string) *tuple {
t.parent.values = append(t.parent.values, value.JSONDocumentValue(v))

return t.parent
}

func (t *tupleItem) YSON(v []byte) *tuple {
t.parent.values = append(t.parent.values, value.YSONValue(v))

return t.parent
}

func (t *tupleItem) UUID(v [16]byte) *tuple {
t.parent.values = append(t.parent.values, value.UUIDValue(v))

return t.parent
}
Loading

0 comments on commit c83797b

Please sign in to comment.