Skip to content

Commit d588f35

Browse files
committed
new types for list
1 parent daaf9ab commit d588f35

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

internal/params/list.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,27 @@ func (l *listItem) Interval(v time.Duration) *list {
140140

141141
return l.parent
142142
}
143+
144+
func (l *listItem) JSON(v string) *list {
145+
l.parent.values = append(l.parent.values, value.JSONValue(v))
146+
147+
return l.parent
148+
}
149+
150+
func (l *listItem) JSONDocument(v string) *list {
151+
l.parent.values = append(l.parent.values, value.JSONDocumentValue(v))
152+
153+
return l.parent
154+
}
155+
156+
func (l *listItem) YSON(v []byte) *list {
157+
l.parent.values = append(l.parent.values, value.YSONValue(v))
158+
159+
return l.parent
160+
}
161+
162+
func (l *listItem) UUID(v [16]byte) *list {
163+
l.parent.values = append(l.parent.values, value.UUIDValue(v))
164+
165+
return l.parent
166+
}

internal/params/list_test.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,120 @@ func TestList(t *testing.T) {
525525
},
526526
},
527527
},
528+
{
529+
name: xtest.CurrentFileLine(),
530+
builder: Builder{}.Param("$x").List().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(), //nolint:lll
531+
params: map[string]*Ydb.TypedValue{
532+
"$x": {
533+
Type: &Ydb.Type{
534+
Type: &Ydb.Type_ListType{
535+
ListType: &Ydb.ListType{
536+
Item: &Ydb.Type{
537+
Type: &Ydb.Type_TypeId{
538+
TypeId: Ydb.Type_JSON,
539+
},
540+
},
541+
},
542+
},
543+
},
544+
Value: &Ydb.Value{
545+
Items: []*Ydb.Value{
546+
{
547+
Value: &Ydb.Value_TextValue{
548+
TextValue: `{"a": 1,"b": "B"}`,
549+
},
550+
},
551+
},
552+
},
553+
},
554+
},
555+
},
556+
{
557+
name: xtest.CurrentFileLine(),
558+
builder: Builder{}.Param("$x").List().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(), //nolint:lll
559+
params: map[string]*Ydb.TypedValue{
560+
"$x": {
561+
Type: &Ydb.Type{
562+
Type: &Ydb.Type_ListType{
563+
ListType: &Ydb.ListType{
564+
Item: &Ydb.Type{
565+
Type: &Ydb.Type_TypeId{
566+
TypeId: Ydb.Type_JSON_DOCUMENT,
567+
},
568+
},
569+
},
570+
},
571+
},
572+
Value: &Ydb.Value{
573+
Items: []*Ydb.Value{
574+
{
575+
Value: &Ydb.Value_TextValue{
576+
TextValue: `{"a": 1,"b": "B"}`,
577+
},
578+
},
579+
},
580+
},
581+
},
582+
},
583+
},
584+
{
585+
name: xtest.CurrentFileLine(),
586+
builder: Builder{}.Param("$x").List().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(), //nolint:lll
587+
params: map[string]*Ydb.TypedValue{
588+
"$x": {
589+
Type: &Ydb.Type{
590+
Type: &Ydb.Type_ListType{
591+
ListType: &Ydb.ListType{
592+
Item: &Ydb.Type{
593+
Type: &Ydb.Type_TypeId{
594+
TypeId: Ydb.Type_YSON,
595+
},
596+
},
597+
},
598+
},
599+
},
600+
Value: &Ydb.Value{
601+
Items: []*Ydb.Value{
602+
{
603+
Value: &Ydb.Value_BytesValue{
604+
BytesValue: []byte(`[ 1; 2; 3; 4; 5 ]`),
605+
},
606+
},
607+
},
608+
},
609+
},
610+
},
611+
},
612+
{
613+
name: xtest.CurrentFileLine(),
614+
builder: Builder{}.Param("$x").List().AddItem().
615+
UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}).Build(),
616+
params: map[string]*Ydb.TypedValue{
617+
"$x": {
618+
Type: &Ydb.Type{
619+
Type: &Ydb.Type_ListType{
620+
ListType: &Ydb.ListType{
621+
Item: &Ydb.Type{
622+
Type: &Ydb.Type_TypeId{
623+
TypeId: Ydb.Type_UUID,
624+
},
625+
},
626+
},
627+
},
628+
},
629+
Value: &Ydb.Value{
630+
Items: []*Ydb.Value{
631+
{
632+
Value: &Ydb.Value_Low_128{
633+
Low_128: 651345242494996240,
634+
},
635+
High_128: 72623859790382856,
636+
},
637+
},
638+
},
639+
},
640+
},
641+
},
528642
} {
529643
t.Run(tt.name, func(t *testing.T) {
530644
a := allocator.New()

0 commit comments

Comments
 (0)