Skip to content

Commit e65319a

Browse files
committed
Added Tuple support for ydb.ParamsBuilder()
1 parent 4315955 commit e65319a

File tree

4 files changed

+915
-0
lines changed

4 files changed

+915
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Added `internal/xsync.{OnceFunc,OnceValue}`
2020
* Updated `google.golang.org/protobuf` from `v1.31.0` to `v.33.0`
2121
* Added `ydb.ParamsBuilder().Pg().{Value,Int4,Int8,Unknown}` for postgres arguments
22+
* Added `Tuple` support for `ydb.ParamsBuilder()`
2223

2324
## v3.57.4
2425
* Added client pid to each gRPC requests to YDB over header `x-ydb-client-pid`

internal/params/parameters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ func (p *Parameter) BeginDict() *dict {
127127
}
128128
}
129129

130+
func (p *Parameter) BeginTuple() *tuple {
131+
return &tuple{
132+
parent: p.parent,
133+
name: p.name,
134+
}
135+
}
136+
130137
func (p *Parameter) Text(v string) Builder {
131138
p.value = value.TextValue(v)
132139
p.parent.params = append(p.parent.params, p)

internal/params/tuple.go

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
package params
2+
3+
import (
4+
"time"
5+
6+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
7+
)
8+
9+
type (
10+
tuple struct {
11+
parent Builder
12+
name string
13+
values []value.Value
14+
}
15+
tupleItem struct {
16+
parent *tuple
17+
}
18+
)
19+
20+
func (t *tuple) Add() *tupleItem {
21+
return &tupleItem{
22+
parent: t,
23+
}
24+
}
25+
26+
func (t *tuple) AddItems(items ...value.Value) *tuple {
27+
t.values = append(t.values, items...)
28+
29+
return t
30+
}
31+
32+
func (t *tuple) EndTuple() Builder {
33+
t.parent.params = append(t.parent.params, &Parameter{
34+
parent: t.parent,
35+
name: t.name,
36+
value: value.TupleValue(t.values...),
37+
})
38+
39+
return t.parent
40+
}
41+
42+
func (t *tupleItem) Text(v string) *tuple {
43+
t.parent.values = append(t.parent.values, value.TextValue(v))
44+
45+
return t.parent
46+
}
47+
48+
func (t *tupleItem) Bytes(v []byte) *tuple {
49+
t.parent.values = append(t.parent.values, value.BytesValue(v))
50+
51+
return t.parent
52+
}
53+
54+
func (t *tupleItem) Bool(v bool) *tuple {
55+
t.parent.values = append(t.parent.values, value.BoolValue(v))
56+
57+
return t.parent
58+
}
59+
60+
func (t *tupleItem) Uint64(v uint64) *tuple {
61+
t.parent.values = append(t.parent.values, value.Uint64Value(v))
62+
63+
return t.parent
64+
}
65+
66+
func (t *tupleItem) Int64(v int64) *tuple {
67+
t.parent.values = append(t.parent.values, value.Int64Value(v))
68+
69+
return t.parent
70+
}
71+
72+
func (t *tupleItem) Uint32(v uint32) *tuple {
73+
t.parent.values = append(t.parent.values, value.Uint32Value(v))
74+
75+
return t.parent
76+
}
77+
78+
func (t *tupleItem) Int32(v int32) *tuple {
79+
t.parent.values = append(t.parent.values, value.Int32Value(v))
80+
81+
return t.parent
82+
}
83+
84+
func (t *tupleItem) Uint16(v uint16) *tuple {
85+
t.parent.values = append(t.parent.values, value.Uint16Value(v))
86+
87+
return t.parent
88+
}
89+
90+
func (t *tupleItem) Int16(v int16) *tuple {
91+
t.parent.values = append(t.parent.values, value.Int16Value(v))
92+
93+
return t.parent
94+
}
95+
96+
func (t *tupleItem) Uint8(v uint8) *tuple {
97+
t.parent.values = append(t.parent.values, value.Uint8Value(v))
98+
99+
return t.parent
100+
}
101+
102+
func (t *tupleItem) Int8(v int8) *tuple {
103+
t.parent.values = append(t.parent.values, value.Int8Value(v))
104+
105+
return t.parent
106+
}
107+
108+
func (t *tupleItem) Float(v float32) *tuple {
109+
t.parent.values = append(t.parent.values, value.FloatValue(v))
110+
111+
return t.parent
112+
}
113+
114+
func (t *tupleItem) Double(v float64) *tuple {
115+
t.parent.values = append(t.parent.values, value.DoubleValue(v))
116+
117+
return t.parent
118+
}
119+
120+
func (t *tupleItem) Decimal(v [16]byte, precision, scale uint32) *tuple {
121+
t.parent.values = append(t.parent.values, value.DecimalValue(v, precision, scale))
122+
123+
return t.parent
124+
}
125+
126+
func (t *tupleItem) Timestamp(v time.Time) *tuple {
127+
t.parent.values = append(t.parent.values, value.TimestampValueFromTime(v))
128+
129+
return t.parent
130+
}
131+
132+
func (t *tupleItem) Date(v time.Time) *tuple {
133+
t.parent.values = append(t.parent.values, value.DateValueFromTime(v))
134+
135+
return t.parent
136+
}
137+
138+
func (t *tupleItem) Datetime(v time.Time) *tuple {
139+
t.parent.values = append(t.parent.values, value.DatetimeValueFromTime(v))
140+
141+
return t.parent
142+
}
143+
144+
func (t *tupleItem) Interval(v time.Duration) *tuple {
145+
t.parent.values = append(t.parent.values, value.IntervalValueFromDuration(v))
146+
147+
return t.parent
148+
}
149+
150+
func (t *tupleItem) JSON(v string) *tuple {
151+
t.parent.values = append(t.parent.values, value.JSONValue(v))
152+
153+
return t.parent
154+
}
155+
156+
func (t *tupleItem) JSONDocument(v string) *tuple {
157+
t.parent.values = append(t.parent.values, value.JSONDocumentValue(v))
158+
159+
return t.parent
160+
}
161+
162+
func (t *tupleItem) YSON(v []byte) *tuple {
163+
t.parent.values = append(t.parent.values, value.YSONValue(v))
164+
165+
return t.parent
166+
}
167+
168+
func (t *tupleItem) UUID(v [16]byte) *tuple {
169+
t.parent.values = append(t.parent.values, value.UUIDValue(v))
170+
171+
return t.parent
172+
}

0 commit comments

Comments
 (0)