Skip to content

Commit de30ffb

Browse files
committed
yson query builder
1 parent 58b7419 commit de30ffb

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

internal/params/builder_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,25 @@ func TestBuilder(t *testing.T) {
409409
},
410410
},
411411
},
412+
{
413+
name: xtest.CurrentFileLine(),
414+
builder: Builder{}.
415+
Param("$x").Yson([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(),
416+
params: map[string]*Ydb.TypedValue{
417+
"$x": {
418+
Type: &Ydb.Type{
419+
Type: &Ydb.Type_TypeId{
420+
TypeId: Ydb.Type_YSON,
421+
},
422+
},
423+
Value: &Ydb.Value{
424+
Value: &Ydb.Value_BytesValue{
425+
BytesValue: []byte(`[ 1; 2; 3; 4; 5 ]`),
426+
},
427+
},
428+
},
429+
},
430+
},
412431
} {
413432
t.Run(tt.name, func(t *testing.T) {
414433
a := allocator.New()

internal/params/optional.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ func (p *optional) JsonDocument(v string) *optionalBuilder {
146146

147147
return &optionalBuilder{opt: p}
148148
}
149+
150+
func (p *optional) Yson(v []byte) *optionalBuilder {
151+
p.value = value.YSONValue(v)
152+
153+
return &optionalBuilder{opt: p}
154+
}

internal/params/optional_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,30 @@ func TestOptional(t *testing.T) {
501501
},
502502
},
503503
},
504+
{
505+
name: xtest.CurrentFileLine(),
506+
builder: Builder{}.Param("$x").Optional().Yson([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(),
507+
params: map[string]*Ydb.TypedValue{
508+
"$x": {
509+
Type: &Ydb.Type{
510+
Type: &Ydb.Type_OptionalType{
511+
OptionalType: &Ydb.OptionalType{
512+
Item: &Ydb.Type{
513+
Type: &Ydb.Type_TypeId{
514+
TypeId: Ydb.Type_YSON,
515+
},
516+
},
517+
},
518+
},
519+
},
520+
Value: &Ydb.Value{
521+
Value: &Ydb.Value_BytesValue{
522+
BytesValue: []byte(`[ 1; 2; 3; 4; 5 ]`),
523+
},
524+
},
525+
},
526+
},
527+
},
504528
} {
505529
t.Run(tt.name, func(t *testing.T) {
506530
a := allocator.New()

internal/params/parameters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ func (p *Parameter) JsonDocument(v string) Builder {
256256
return p.parent
257257
}
258258

259+
func (p *Parameter) Yson(v []byte) Builder {
260+
p.value = value.YSONValue(v)
261+
p.parent.params = append(p.parent.params, p)
262+
263+
return p.parent
264+
}
265+
259266
func Declare(p *Parameter) string {
260267
return fmt.Sprintf(
261268
"DECLARE %s AS %s",

0 commit comments

Comments
 (0)