diff --git a/example_test.go b/example_test.go index 3b06248e6..399411e68 100644 --- a/example_test.go +++ b/example_test.go @@ -3,6 +3,7 @@ package ydb_test import ( "context" "database/sql" + "errors" "fmt" "io" "log" @@ -14,6 +15,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3" "github.com/ydb-platform/ydb-go-sdk/v3/balancers" "github.com/ydb-platform/ydb-go-sdk/v3/config" + "github.com/ydb-platform/ydb-go-sdk/v3/query" "github.com/ydb-platform/ydb-go-sdk/v3/retry" "github.com/ydb-platform/ydb-go-sdk/v3/table" "github.com/ydb-platform/ydb-go-sdk/v3/table/result/named" @@ -21,6 +23,69 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions" ) +//nolint:testableexamples, nonamedreturns +func Example_query() { + ctx := context.TODO() + db, err := ydb.Open(ctx, "grpc://localhost:2136/local") + if err != nil { + log.Fatal(err) + } + defer db.Close(ctx) // cleanup resources + + err = db.Query().Do( // Do retry operation on errors with best effort + ctx, // context manage exiting from Do + func(ctx context.Context, s query.Session) (err error) { // retry operation + _, res, err := s.Execute(ctx, + `SELECT $id as myId, $str as myStr`, + query.WithParameters( + ydb.ParamsBuilder(). + Param("$id").Uint64(42). + Param("$str").Text("my string"). + Build(), + ), + ) + if err != nil { + return err // for auto-retry with driver + } + defer func() { _ = res.Close(ctx) }() // cleanup resources + for { // iterate over result sets + rs, err := res.NextResultSet(ctx) + if err != nil { + if errors.Is(err, io.EOF) { + break + } + + return err + } + for { // iterate over rows + row, err := rs.NextRow(ctx) + if err != nil { + if errors.Is(err, io.EOF) { + break + } + + return err + } + type myStruct struct { + id uint64 `sql:"id"` + str string `sql:"myStr"` + } + var s myStruct + if err = row.ScanStruct(&s); err != nil { + return err // generally scan error not retryable, return it for driver check error + } + } + } + + return res.Err() // return finally result error for auto-retry with driver + }, + query.WithIdempotent(), + ) + if err != nil { + log.Printf("unexpected error: %v", err) + } +} + //nolint:testableexamples, nonamedreturns func Example_table() { ctx := context.TODO() diff --git a/internal/params/builder_test.go b/internal/params/builder_test.go index 07ca572c1..801f96432 100644 --- a/internal/params/builder_test.go +++ b/internal/params/builder_test.go @@ -361,7 +361,7 @@ func TestBuilder(t *testing.T) { { name: xtest.CurrentFileLine(), builder: Builder{}. - Param("$x").List().Build(). + Param("$x").BeginList().EndList(). Build(), params: map[string]*Ydb.TypedValue{ "$x": { diff --git a/internal/params/dict.go b/internal/params/dict.go index 3632f5c1f..ace220e17 100644 --- a/internal/params/dict.go +++ b/internal/params/dict.go @@ -21,7 +21,7 @@ type ( } ) -func (d *dict) Pair() *dictPair { +func (d *dict) Add() *dictPair { return &dictPair{ parent: d, } @@ -407,7 +407,7 @@ func (d *dictValue) UUID(v [16]byte) *dict { return d.pair.parent } -func (d *dict) Build() Builder { +func (d *dict) EndDict() Builder { d.parent.params = append(d.parent.params, &Parameter{ parent: d.parent, name: d.name, diff --git a/internal/params/dict_test.go b/internal/params/dict_test.go index 835816698..2e090076d 100644 --- a/internal/params/dict_test.go +++ b/internal/params/dict_test.go @@ -370,7 +370,7 @@ func TestDict(t *testing.T) { a := allocator.New() defer a.Free() - item := Builder{}.Param("$x").Dict().Pair() + item := Builder{}.Param("$x").BeginDict().Add() addedKey, ok := xtest.CallMethod(item, key.method, key.args...)[0].(*dictValue) require.True(t, ok) @@ -378,7 +378,7 @@ func TestDict(t *testing.T) { d, ok := xtest.CallMethod(addedKey, val.method, val.args...)[0].(*dict) require.True(t, ok) - params := d.Build().Build().ToYDB(a) + params := d.EndDict().Build().ToYDB(a) require.Equal(t, paramsToJSON( map[string]*Ydb.TypedValue{ "$x": { @@ -420,7 +420,7 @@ func TestDict_AddPairs(t *testing.T) { }, } - params := Builder{}.Param("$x").Dict().AddPairs(pairs...).Build().Build().ToYDB(a) + params := Builder{}.Param("$x").BeginDict().AddPairs(pairs...).EndDict().Build().ToYDB(a) require.Equal(t, paramsToJSON( map[string]*Ydb.TypedValue{ diff --git a/internal/params/list.go b/internal/params/list.go index dbbec8319..c577c824d 100644 --- a/internal/params/list.go +++ b/internal/params/list.go @@ -17,7 +17,7 @@ type ( } ) -func (l *list) AddItem() *listItem { +func (l *list) Add() *listItem { return &listItem{ parent: l, } @@ -29,7 +29,7 @@ func (l *list) AddItems(items ...value.Value) *list { return l } -func (l *list) Build() Builder { +func (l *list) EndList() Builder { l.parent.params = append(l.parent.params, &Parameter{ parent: l.parent, name: l.name, diff --git a/internal/params/list_test.go b/internal/params/list_test.go index 681395ba4..3941a80c4 100644 --- a/internal/params/list_test.go +++ b/internal/params/list_test.go @@ -20,7 +20,7 @@ func TestList(t *testing.T) { }{ { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Uint64(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Uint64(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -48,7 +48,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Int64(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Int64(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -76,7 +76,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Uint32(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Uint32(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -104,7 +104,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Int32(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Int32(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -132,7 +132,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Uint16(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Uint16(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -160,7 +160,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Int16(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Int16(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -188,7 +188,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Uint8(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Uint8(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -216,7 +216,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Int8(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Int8(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -244,7 +244,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Bool(true).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Bool(true).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -272,7 +272,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Text("test").Build(), + builder: Builder{}.Param("$x").BeginList().Add().Text("test").EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -300,7 +300,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Bytes([]byte("test")).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Bytes([]byte("test")).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -328,7 +328,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Float(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Float(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -356,7 +356,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Double(123).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Double(123).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -384,7 +384,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Interval(time.Second).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Interval(time.Second).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -412,7 +412,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Datetime(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Datetime(time.Unix(123456789, 456)).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -440,7 +440,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Date(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Date(time.Unix(123456789, 456)).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -468,7 +468,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Timestamp(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginList().Add().Timestamp(time.Unix(123456789, 456)).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -496,7 +496,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).Build(), //nolint:lll + builder: Builder{}.Param("$x").BeginList().Add().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).EndList(), //nolint:lll params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -528,7 +528,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginList().Add().JSON(`{"a": 1,"b": "B"}`).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -556,7 +556,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginList().Add().JSONDocument(`{"a": 1,"b": "B"}`).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -584,7 +584,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(), + builder: Builder{}.Param("$x").BeginList().Add().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -612,8 +612,8 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItem(). - UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}).Build(), + builder: Builder{}.Param("$x").BeginList().Add(). + UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -642,7 +642,7 @@ func TestList(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").List().AddItems(value.Uint64Value(123), value.Uint64Value(321)).Build(), + builder: Builder{}.Param("$x").BeginList().AddItems(value.Uint64Value(123), value.Uint64Value(321)).EndList(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ diff --git a/internal/params/optional.go b/internal/params/optional.go index 46cc2d399..316c1a6a2 100644 --- a/internal/params/optional.go +++ b/internal/params/optional.go @@ -17,7 +17,7 @@ type ( } ) -func (b *optionalBuilder) Build() Builder { +func (b *optionalBuilder) EndOptional() Builder { b.opt.parent.params = append(b.opt.parent.params, &Parameter{ parent: b.opt.parent, name: b.opt.name, diff --git a/internal/params/optional_test.go b/internal/params/optional_test.go index fa2d4011f..f3b7cdf13 100644 --- a/internal/params/optional_test.go +++ b/internal/params/optional_test.go @@ -19,7 +19,7 @@ func TestOptional(t *testing.T) { }{ { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Uint64(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Uint64(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -43,7 +43,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Int64(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Int64(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -67,7 +67,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Uint32(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Uint32(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -91,7 +91,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Int32(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Int32(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -115,7 +115,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Uint16(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Uint16(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -139,7 +139,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Int16(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Int16(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -163,7 +163,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Uint8(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Uint8(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -187,7 +187,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Int8(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Int8(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -211,7 +211,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Bool(true).Build(), + builder: Builder{}.Param("$x").BeginOptional().Bool(true).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -235,7 +235,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Text("test").Build(), + builder: Builder{}.Param("$x").BeginOptional().Text("test").EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -259,7 +259,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Bytes([]byte("test")).Build(), + builder: Builder{}.Param("$x").BeginOptional().Bytes([]byte("test")).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -283,7 +283,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Float(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Float(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -307,7 +307,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Double(123).Build(), + builder: Builder{}.Param("$x").BeginOptional().Double(123).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -331,7 +331,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Interval(time.Second).Build(), + builder: Builder{}.Param("$x").BeginOptional().Interval(time.Second).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -355,7 +355,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Datetime(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginOptional().Datetime(time.Unix(123456789, 456)).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -379,7 +379,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Date(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginOptional().Date(time.Unix(123456789, 456)).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -403,7 +403,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Timestamp(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginOptional().Timestamp(time.Unix(123456789, 456)).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -427,7 +427,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).Build(), //nolint:lll + builder: Builder{}.Param("$x").BeginOptional().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).EndOptional(), //nolint:lll params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -455,7 +455,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().JSON(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginOptional().JSON(`{"a": 1,"b": "B"}`).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -479,7 +479,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().JSONDocument(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginOptional().JSONDocument(`{"a": 1,"b": "B"}`).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -503,7 +503,7 @@ func TestOptional(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Optional().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(), + builder: Builder{}.Param("$x").BeginOptional().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -528,9 +528,9 @@ func TestOptional(t *testing.T) { { name: xtest.CurrentFileLine(), builder: Builder{}.Param("$x"). - Optional(). + BeginOptional(). UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}). - Build(), + EndOptional(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ diff --git a/internal/params/parameters.go b/internal/params/parameters.go index a342f7cc1..c96506048 100644 --- a/internal/params/parameters.go +++ b/internal/params/parameters.go @@ -95,14 +95,14 @@ func (p *Parameters) Add(params ...NamedValue) { } } -func (p *Parameter) Optional() *optional { +func (p *Parameter) BeginOptional() *optional { return &optional{ parent: p.parent, name: p.name, } } -func (p *Parameter) List() *list { +func (p *Parameter) BeginList() *list { return &list{ parent: p.parent, name: p.name, @@ -113,14 +113,14 @@ func (p *Parameter) Pg() pgParam { return pgParam{p} } -func (p *Parameter) Set() *set { +func (p *Parameter) BeginSet() *set { return &set{ parent: p.parent, name: p.name, } } -func (p *Parameter) Dict() *dict { +func (p *Parameter) BeginDict() *dict { return &dict{ parent: p.parent, name: p.name, diff --git a/internal/params/set.go b/internal/params/set.go index 31a9e2597..bb087afdf 100644 --- a/internal/params/set.go +++ b/internal/params/set.go @@ -18,7 +18,7 @@ type ( } ) -func (s *set) AddItem() *setItem { +func (s *set) Add() *setItem { return &setItem{ parent: s, } @@ -30,7 +30,7 @@ func (s *set) AddItems(items ...value.Value) *set { return s } -func (s *set) Build() Builder { +func (s *set) EndSet() Builder { s.parent.params = append(s.parent.params, &Parameter{ parent: s.parent, name: s.name, diff --git a/internal/params/set_test.go b/internal/params/set_test.go index 8cd7a6ac4..06e760833 100644 --- a/internal/params/set_test.go +++ b/internal/params/set_test.go @@ -20,7 +20,7 @@ func TestSet(t *testing.T) { }{ { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Uint64(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Uint64(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -56,7 +56,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Int64(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Int64(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -92,7 +92,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Uint32(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Uint32(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -128,7 +128,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Int32(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Int32(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -164,7 +164,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Uint16(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Uint16(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -200,7 +200,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Int16(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Int16(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -236,7 +236,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Uint8(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Uint8(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -272,7 +272,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Int8(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Int8(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -308,7 +308,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Bool(true).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Bool(true).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -344,7 +344,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Text("test").Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Text("test").EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -380,7 +380,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Bytes([]byte("test")).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Bytes([]byte("test")).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -416,7 +416,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Float(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Float(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -452,7 +452,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Double(123).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Double(123).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -488,7 +488,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Interval(time.Second).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Interval(time.Second).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -524,7 +524,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Datetime(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Datetime(time.Unix(123456789, 456)).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -560,7 +560,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Date(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Date(time.Unix(123456789, 456)).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -596,7 +596,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Timestamp(time.Unix(123456789, 456)).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().Timestamp(time.Unix(123456789, 456)).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -632,7 +632,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).Build(), //nolint:lll + builder: Builder{}.Param("$x").BeginSet().Add().Decimal([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6}, 22, 9).EndSet(), //nolint:lll params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -672,7 +672,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().JSON(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().JSON(`{"a": 1,"b": "B"}`).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -708,7 +708,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().JSONDocument(`{"a": 1,"b": "B"}`).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().JSONDocument(`{"a": 1,"b": "B"}`).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -744,7 +744,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).Build(), + builder: Builder{}.Param("$x").BeginSet().Add().YSON([]byte(`[ 1; 2; 3; 4; 5 ]`)).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -780,9 +780,9 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItem(). + builder: Builder{}.Param("$x").BeginSet().Add(). UUID([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}). - Build(), + EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ @@ -819,7 +819,7 @@ func TestSet(t *testing.T) { }, { name: xtest.CurrentFileLine(), - builder: Builder{}.Param("$x").Set().AddItems(value.Uint64Value(123), value.Uint64Value(321)).Build(), + builder: Builder{}.Param("$x").BeginSet().AddItems(value.Uint64Value(123), value.Uint64Value(321)).EndSet(), params: map[string]*Ydb.TypedValue{ "$x": { Type: &Ydb.Type{ diff --git a/query/example_test.go b/query/example_test.go index 0a9722358..c0dec4c30 100644 --- a/query/example_test.go +++ b/query/example_test.go @@ -60,7 +60,7 @@ func Example_selectWithoutParameters() { return res.Err() // return finally result error for auto-retry with driver }, - options.WithIdempotent(), + query.WithIdempotent(), ) if err != nil { fmt.Printf("unexpected error: %v", err)