Skip to content

Commit ea50f91

Browse files
committed
* Marked as deprecated ydb.MustParamsFromMap
* Changed result `ydb.ParamsFromMap` result from tuple <`params.Parameters`, `error`> to `params.Parameters` only
1 parent 761406e commit ea50f91

30 files changed

+189
-98
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Marked as deprecated `ydb.MustParamsFromMap`
2+
* Changed result `ydb.ParamsFromMap` result from tuple <`params.Parameters`, `error`> to `params.Parameters` only
3+
14
## v3.93.1
25
* Published `query.ExecuteOption` as alias to `internal/query/options.Execute`
36

internal/bind/params.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func Params(args ...interface{}) ([]*params.Parameter, error) {
204204
}
205205
newParam, err = toYdbParam(x.Name, x.Value)
206206
newParams = append(newParams, newParam)
207-
case *params.Parameters:
207+
case *params.Params:
208208
if len(args) > 1 {
209209
return nil, xerrors.WithStackTrace(errMultipleQueryParameters)
210210
}
@@ -230,7 +230,7 @@ func Params(args ...interface{}) ([]*params.Parameter, error) {
230230
func paramHandleNamedValue(arg driver.NamedValue, paramNumber, argsLen int) ([]*params.Parameter, error) {
231231
if arg.Name == "" {
232232
switch x := arg.Value.(type) {
233-
case *params.Parameters:
233+
case *params.Params:
234234
if argsLen > 1 {
235235
return nil, xerrors.WithStackTrace(errMultipleQueryParameters)
236236
}

internal/params/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package params
22

33
type (
44
Builder struct {
5-
params Parameters
5+
params Params
66
}
77
)
88

9-
func (b Builder) Build() *Parameters {
9+
func (b Builder) Build() *Params {
1010
return &b.params
1111
}
1212

internal/params/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func TestBuilder(t *testing.T) {
417417
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(Builder)
418418
require.True(t, ok)
419419

420-
params := result.Build().ToYDB(a)
420+
params := result.Build().toYDB(a)
421421

422422
require.Equal(t,
423423
xtest.ToJSON(

internal/params/dict_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func TestDict(t *testing.T) {
440440
d, ok := xtest.CallMethod(addedKey, val.method, val.args...)[0].(*dict)
441441
require.True(t, ok)
442442

443-
params := d.EndDict().Build().ToYDB(a)
443+
params := d.EndDict().Build().toYDB(a)
444444
require.Equal(t, xtest.ToJSON(
445445
map[string]*Ydb.TypedValue{
446446
"$x": {
@@ -482,7 +482,7 @@ func TestDict_AddPairs(t *testing.T) {
482482
},
483483
}
484484

485-
params := Builder{}.Param("$x").BeginDict().AddPairs(pairs...).EndDict().Build().ToYDB(a)
485+
params := Builder{}.Param("$x").BeginDict().AddPairs(pairs...).EndDict().Build().toYDB(a)
486486

487487
require.Equal(t, xtest.ToJSON(
488488
map[string]*Ydb.TypedValue{

internal/params/list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestList(t *testing.T) {
435435
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(*list)
436436
require.True(t, ok)
437437

438-
params := result.EndList().Build().ToYDB(a)
438+
params := result.EndList().Build().toYDB(a)
439439
require.Equal(t, xtest.ToJSON(
440440
map[string]*Ydb.TypedValue{
441441
"$x": {
@@ -462,7 +462,7 @@ func TestList_AddItems(t *testing.T) {
462462
defer a.Free()
463463
params := Builder{}.Param("$x").BeginList().
464464
AddItems(value.Uint64Value(123), value.Uint64Value(321)).
465-
EndList().Build().ToYDB(a)
465+
EndList().Build().toYDB(a)
466466
require.Equal(t, xtest.ToJSON(
467467
map[string]*Ydb.TypedValue{
468468
"$x": {

internal/params/optional_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func TestOptional(t *testing.T) {
435435
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(*optionalBuilder)
436436
require.True(t, ok)
437437

438-
params := result.EndOptional().Build().ToYDB(a)
438+
params := result.EndOptional().Build().toYDB(a)
439439
require.Equal(t, xtest.ToJSON(
440440
map[string]*Ydb.TypedValue{
441441
"$x": {

internal/params/parameters.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ type (
2323
name string
2424
value value.Value
2525
}
26-
Parameters []*Parameter
26+
Parameters interface {
27+
ToYDB(a *allocator.Allocator) (map[string]*Ydb.TypedValue, error)
28+
}
29+
Params []*Parameter
2730
)
2831

32+
var _ Parameters = (*Params)(nil)
33+
2934
func Named(name string, value value.Value) *Parameter {
3035
return &Parameter{
3136
name: name,
@@ -41,7 +46,7 @@ func (p *Parameter) Value() value.Value {
4146
return p.value
4247
}
4348

44-
func (p *Parameters) String() string {
49+
func (p *Params) String() string {
4550
buffer := xstring.Buffer()
4651
defer buffer.Free()
4752

@@ -62,7 +67,16 @@ func (p *Parameters) String() string {
6267
return buffer.String()
6368
}
6469

65-
func (p *Parameters) ToYDB(a *allocator.Allocator) map[string]*Ydb.TypedValue {
70+
func (p *Params) ToYDB(a *allocator.Allocator) (map[string]*Ydb.TypedValue, error) {
71+
parameters := make(map[string]*Ydb.TypedValue, len(*p))
72+
for _, param := range *p {
73+
parameters[param.name] = value.ToYDB(param.value, a)
74+
}
75+
76+
return parameters, nil
77+
}
78+
79+
func (p *Params) toYDB(a *allocator.Allocator) map[string]*Ydb.TypedValue {
6680
if p == nil {
6781
return nil
6882
}
@@ -74,7 +88,7 @@ func (p *Parameters) ToYDB(a *allocator.Allocator) map[string]*Ydb.TypedValue {
7488
return parameters
7589
}
7690

77-
func (p *Parameters) Each(it func(name string, v value.Value)) {
91+
func (p *Params) Each(it func(name string, v value.Value)) {
7892
if p == nil {
7993
return
8094
}
@@ -83,15 +97,15 @@ func (p *Parameters) Each(it func(name string, v value.Value)) {
8397
}
8498
}
8599

86-
func (p *Parameters) Count() int {
100+
func (p *Params) Count() int {
87101
if p == nil {
88102
return 0
89103
}
90104

91105
return len(*p)
92106
}
93107

94-
func (p *Parameters) Add(params ...NamedValue) {
108+
func (p *Params) Add(params ...NamedValue) {
95109
for _, param := range params {
96110
*p = append(*p, Named(param.Name(), param.Value()))
97111
}

internal/params/parameters_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func TestParameter(t *testing.T) {
1818
}
1919

2020
func TestParameters(t *testing.T) {
21-
p := &Parameters{}
21+
p := &Params{}
2222
p.Add(
2323
Named("x", value.TextValue("X")),
2424
Named("y", value.TextValue("Y")),
@@ -39,15 +39,15 @@ func TestParameters(t *testing.T) {
3939
func TestNil(t *testing.T) {
4040
for _, tt := range []struct {
4141
name string
42-
p *Parameters
42+
p *Params
4343
}{
4444
{
4545
name: xtest.CurrentFileLine(),
4646
p: nil,
4747
},
4848
{
4949
name: xtest.CurrentFileLine(),
50-
p: &Parameters{},
50+
p: &Params{},
5151
},
5252
{
5353
name: xtest.CurrentFileLine(),
@@ -64,7 +64,7 @@ func TestNil(t *testing.T) {
6464
require.Empty(t, visited)
6565
a := allocator.New()
6666
defer a.Free()
67-
require.Empty(t, tt.p.ToYDB(a))
67+
require.Empty(t, tt.p.toYDB(a))
6868
})
6969
}
7070
}

internal/params/pg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestPg(t *testing.T) {
8686
result, ok := xtest.CallMethod(item, tc.method, tc.args...)[0].(Builder)
8787
require.True(t, ok)
8888

89-
params := result.Build().ToYDB(a)
89+
params := result.Build().toYDB(a)
9090

9191
require.Equal(t, xtest.ToJSON(
9292
map[string]*Ydb.TypedValue{

0 commit comments

Comments
 (0)