Skip to content

Commit 2a54081

Browse files
authored
Merge pull request #1576 from ydb-platform/pb-value
* Supported raw protobuf typed value using `ydb.ParamsBuilder()`
2 parents 12ee877 + a9f3d19 commit 2a54081

19 files changed

+385
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Supported raw protobuf typed value using `ydb.ParamsBuilder()`
2+
13
## v3.93.2
24
* Removed experimental helper `ydb.MustParamsFromMap`
35
* Changed result of experimental helper `ydb.ParamsFromMap` from tuple <`params.Parameters`, `error`> to `params.Parameters` only
@@ -19,7 +21,7 @@
1921
* Fixed connections pool leak on closing
2022

2123
## v3.92.3
22-
* Fixed error with incompleted data returen from transaction.ReadQueryResult method
24+
* Fixed error with incompleted data return from transaction.ReadQueryResult method
2325
* Added option `query/WithResponsePartLimitSizeBytes(...)` for queries with query service
2426

2527
## v3.92.2

internal/params/builder.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ type (
66
}
77
)
88

9-
func (b Builder) Build() *Params {
9+
func (b Builder) Build() Parameters {
10+
return &b.params
11+
}
12+
13+
func (b Builder) build() *Params {
1014
return &b.params
1115
}
1216

internal/params/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func TestBuilder(t *testing.T) {
417417
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(Builder)
418418
require.True(t, ok)
419419

420-
params := result.Build().toYDB(a)
420+
params := result.build().toYDB(a)
421421

422422
require.Equal(t,
423423
xtest.ToJSON(

internal/params/dict_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func TestDict(t *testing.T) {
440440
d, ok := xtest.CallMethod(addedKey, val.method, val.args...)[0].(*dict)
441441
require.True(t, ok)
442442

443-
params := d.EndDict().Build().toYDB(a)
443+
params := d.EndDict().build().toYDB(a)
444444
require.Equal(t, xtest.ToJSON(
445445
map[string]*Ydb.TypedValue{
446446
"$x": {
@@ -482,7 +482,7 @@ func TestDict_AddPairs(t *testing.T) {
482482
},
483483
}
484484

485-
params := Builder{}.Param("$x").BeginDict().AddPairs(pairs...).EndDict().Build().toYDB(a)
485+
params := Builder{}.Param("$x").BeginDict().AddPairs(pairs...).EndDict().build().toYDB(a)
486486

487487
require.Equal(t, xtest.ToJSON(
488488
map[string]*Ydb.TypedValue{

internal/params/list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestList(t *testing.T) {
435435
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(*list)
436436
require.True(t, ok)
437437

438-
params := result.EndList().Build().toYDB(a)
438+
params := result.EndList().build().toYDB(a)
439439
require.Equal(t, xtest.ToJSON(
440440
map[string]*Ydb.TypedValue{
441441
"$x": {
@@ -462,7 +462,7 @@ func TestList_AddItems(t *testing.T) {
462462
defer a.Free()
463463
params := Builder{}.Param("$x").BeginList().
464464
AddItems(value.Uint64Value(123), value.Uint64Value(321)).
465-
EndList().Build().toYDB(a)
465+
EndList().build().toYDB(a)
466466
require.Equal(t, xtest.ToJSON(
467467
map[string]*Ydb.TypedValue{
468468
"$x": {

internal/params/optional_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestOptional(t *testing.T) {
435435
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(*optionalBuilder)
436436
require.True(t, ok)
437437

438-
params := result.EndOptional().Build().toYDB(a)
438+
params := result.EndOptional().build().toYDB(a)
439439
require.Equal(t, xtest.ToJSON(
440440
map[string]*Ydb.TypedValue{
441441
"$x": {

internal/params/parameters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,13 @@ func (p *Parameter) TzDatetime(v time.Time) Builder {
365365
return p.parent
366366
}
367367

368+
func (p *Parameter) Raw(pb *Ydb.TypedValue) Builder {
369+
p.value = value.FromProtobuf(pb)
370+
p.parent.params = append(p.parent.params, p)
371+
372+
return p.parent
373+
}
374+
368375
func Declare(p *Parameter) string {
369376
return fmt.Sprintf(
370377
"DECLARE %s AS %s",

internal/params/parameters_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestNil(t *testing.T) {
5151
},
5252
{
5353
name: xtest.CurrentFileLine(),
54-
p: Builder{}.Build(),
54+
p: Builder{}.build(),
5555
},
5656
} {
5757
t.Run(tt.name, func(t *testing.T) {

internal/params/pg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestPg(t *testing.T) {
8686
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(Builder)
8787
require.True(t, ok)
8888

89-
params := result.Build().toYDB(a)
89+
params := result.build().toYDB(a)
9090

9191
require.Equal(t, xtest.ToJSON(
9292
map[string]*Ydb.TypedValue{

internal/params/set_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestSet(t *testing.T) {
435435
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(*set)
436436
require.True(t, ok)
437437

438-
params := result.EndSet().Build().toYDB(a)
438+
params := result.EndSet().build().toYDB(a)
439439
require.Equal(t, xtest.ToJSON(
440440
map[string]*Ydb.TypedValue{
441441
"$x": {
@@ -470,7 +470,7 @@ func TestSet_AddItems(t *testing.T) {
470470
defer a.Free()
471471
params := Builder{}.Param("$x").BeginSet().
472472
AddItems(value.Uint64Value(123), value.Uint64Value(321)).
473-
EndSet().Build().toYDB(a)
473+
EndSet().build().toYDB(a)
474474
require.Equal(t, xtest.ToJSON(
475475
map[string]*Ydb.TypedValue{
476476
"$x": {

0 commit comments

Comments
 (0)