Skip to content

Commit 58b7419

Browse files
committed
json document query builder
1 parent b95831e commit 58b7419

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
@@ -390,6 +390,25 @@ func TestBuilder(t *testing.T) {
390390
},
391391
},
392392
},
393+
{
394+
name: xtest.CurrentFileLine(),
395+
builder: Builder{}.
396+
Param("$x").JsonDocument(`{"a": 1,"b": "B"}`).Build(),
397+
params: map[string]*Ydb.TypedValue{
398+
"$x": {
399+
Type: &Ydb.Type{
400+
Type: &Ydb.Type_TypeId{
401+
TypeId: Ydb.Type_JSON_DOCUMENT,
402+
},
403+
},
404+
Value: &Ydb.Value{
405+
Value: &Ydb.Value_TextValue{
406+
TextValue: `{"a": 1,"b": "B"}`,
407+
},
408+
},
409+
},
410+
},
411+
},
393412
} {
394413
t.Run(tt.name, func(t *testing.T) {
395414
a := allocator.New()

internal/params/optional.go

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

141141
return &optionalBuilder{opt: p}
142142
}
143+
144+
func (p *optional) JsonDocument(v string) *optionalBuilder {
145+
p.value = value.JSONDocumentValue(v)
146+
147+
return &optionalBuilder{opt: p}
148+
}

internal/params/optional_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,30 @@ func TestOptional(t *testing.T) {
477477
},
478478
},
479479
},
480+
{
481+
name: xtest.CurrentFileLine(),
482+
builder: Builder{}.Param("$x").Optional().JsonDocument(`{"a": 1,"b": "B"}`).Build(),
483+
params: map[string]*Ydb.TypedValue{
484+
"$x": {
485+
Type: &Ydb.Type{
486+
Type: &Ydb.Type_OptionalType{
487+
OptionalType: &Ydb.OptionalType{
488+
Item: &Ydb.Type{
489+
Type: &Ydb.Type_TypeId{
490+
TypeId: Ydb.Type_JSON_DOCUMENT,
491+
},
492+
},
493+
},
494+
},
495+
},
496+
Value: &Ydb.Value{
497+
Value: &Ydb.Value_TextValue{
498+
TextValue: `{"a": 1,"b": "B"}`,
499+
},
500+
},
501+
},
502+
},
503+
},
480504
} {
481505
t.Run(tt.name, func(t *testing.T) {
482506
a := allocator.New()

internal/params/parameters.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ func (p *Parameter) Json(v string) Builder {
249249
return p.parent
250250
}
251251

252+
func (p *Parameter) JsonDocument(v string) Builder {
253+
p.value = value.JSONDocumentValue(v)
254+
p.parent.params = append(p.parent.params, p)
255+
256+
return p.parent
257+
}
258+
252259
func Declare(p *Parameter) string {
253260
return fmt.Sprintf(
254261
"DECLARE %s AS %s",

0 commit comments

Comments
 (0)