|
7 | 7 |
|
8 | 8 | "github.com/stretchr/testify/require" |
9 | 9 | "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" |
| 10 | + "github.com/ydb-platform/ydb-go-sdk/v3/internal/value" |
10 | 11 |
|
11 | 12 | "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" |
12 | 13 | "github.com/ydb-platform/ydb-go-sdk/v3/internal/xtest" |
@@ -403,3 +404,71 @@ func TestDict(t *testing.T) { |
403 | 404 | } |
404 | 405 | } |
405 | 406 | } |
| 407 | + |
| 408 | +func TestDict_AddPairs(t *testing.T) { |
| 409 | + a := allocator.New() |
| 410 | + defer a.Free() |
| 411 | + |
| 412 | + pairs := []value.DictValueField{ |
| 413 | + { |
| 414 | + K: value.Int64Value(123), |
| 415 | + V: value.BoolValue(true), |
| 416 | + }, |
| 417 | + { |
| 418 | + K: value.Int64Value(321), |
| 419 | + V: value.BoolValue(false), |
| 420 | + }, |
| 421 | + } |
| 422 | + |
| 423 | + params := Builder{}.Param("$x").Dict().AddPairs(pairs...).Build().Build().ToYDB(a) |
| 424 | + |
| 425 | + require.Equal(t, paramsToJSON( |
| 426 | + map[string]*Ydb.TypedValue{ |
| 427 | + "$x": { |
| 428 | + Type: &Ydb.Type{ |
| 429 | + Type: &Ydb.Type_DictType{ |
| 430 | + DictType: &Ydb.DictType{ |
| 431 | + Key: &Ydb.Type{ |
| 432 | + Type: &Ydb.Type_TypeId{ |
| 433 | + TypeId: Ydb.Type_INT64, |
| 434 | + }, |
| 435 | + }, |
| 436 | + Payload: &Ydb.Type{ |
| 437 | + Type: &Ydb.Type_TypeId{ |
| 438 | + TypeId: Ydb.Type_BOOL, |
| 439 | + }, |
| 440 | + }, |
| 441 | + }, |
| 442 | + }, |
| 443 | + }, |
| 444 | + Value: &Ydb.Value{ |
| 445 | + Pairs: []*Ydb.ValuePair{ |
| 446 | + { |
| 447 | + Key: &Ydb.Value{ |
| 448 | + Value: &Ydb.Value_Int64Value{ |
| 449 | + Int64Value: 123, |
| 450 | + }, |
| 451 | + }, |
| 452 | + Payload: &Ydb.Value{ |
| 453 | + Value: &Ydb.Value_BoolValue{ |
| 454 | + BoolValue: true, |
| 455 | + }, |
| 456 | + }, |
| 457 | + }, |
| 458 | + { |
| 459 | + Key: &Ydb.Value{ |
| 460 | + Value: &Ydb.Value_Int64Value{ |
| 461 | + Int64Value: 321, |
| 462 | + }, |
| 463 | + }, |
| 464 | + Payload: &Ydb.Value{ |
| 465 | + Value: &Ydb.Value_BoolValue{ |
| 466 | + BoolValue: false, |
| 467 | + }, |
| 468 | + }, |
| 469 | + }, |
| 470 | + }, |
| 471 | + }, |
| 472 | + }, |
| 473 | + }), paramsToJSON(params)) |
| 474 | +} |
0 commit comments