Skip to content

Commit 0144f86

Browse files
committed
renamed UUIDTyped to Uuid and add Uuid to values
1 parent a7f32cf commit 0144f86

23 files changed

+564
-17
lines changed

internal/bind/params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func toValue(v interface{}) (_ types.Value, err error) {
128128

129129
return types.NullableUUIDValueWithIssue1501(&val), nil
130130
case uuid.UUID:
131-
return types.UUIDTypedValue(x), nil
131+
return types.UuidValue(x), nil
132132
case *uuid.UUID:
133133
return types.NullableUUIDTypedValue(x), nil
134134
case time.Time:

internal/params/dict.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

@@ -201,6 +203,10 @@ func (d *dictPair) YSON(v []byte) *dictValue {
201203
}
202204
}
203205

206+
// UUID has data corruption bug and will be removed in next version.
207+
//
208+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
209+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
204210
func (d *dictPair) UUID(v [16]byte) *dictValue {
205211
d.keyValue = value.UUIDWithIssue1501Value(v)
206212

@@ -209,6 +215,22 @@ func (d *dictPair) UUID(v [16]byte) *dictValue {
209215
}
210216
}
211217

218+
func (d *dictPair) Uuid(v uuid.UUID) *dictValue { //nolint:revive,stylecheck
219+
d.keyValue = value.Uuid(v)
220+
221+
return &dictValue{
222+
pair: d,
223+
}
224+
}
225+
226+
func (d *dictPair) UUIDWithIssue1501Value(v [16]byte) *dictValue {
227+
d.keyValue = value.UUIDWithIssue1501Value(v)
228+
229+
return &dictValue{
230+
pair: d,
231+
}
232+
}
233+
212234
func (d *dictPair) TzDate(v time.Time) *dictValue {
213235
d.keyValue = value.TzDateValueFromTime(v)
214236

@@ -422,6 +444,10 @@ func (d *dictValue) YSON(v []byte) *dict {
422444
return d.pair.parent
423445
}
424446

447+
// UUID has data corruption bug and will be removed in next version.
448+
//
449+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
450+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
425451
func (d *dictValue) UUID(v [16]byte) *dict {
426452
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
427453
K: d.pair.keyValue,
@@ -431,6 +457,24 @@ func (d *dictValue) UUID(v [16]byte) *dict {
431457
return d.pair.parent
432458
}
433459

460+
func (d *dictValue) Uuid(v uuid.UUID) *dict { //nolint:revive,stylecheck
461+
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
462+
K: d.pair.keyValue,
463+
V: value.Uuid(v),
464+
})
465+
466+
return d.pair.parent
467+
}
468+
469+
func (d *dictValue) UUIDWithIssue1501Value(v [16]byte) *dict {
470+
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
471+
K: d.pair.keyValue,
472+
V: value.UUIDWithIssue1501Value(v),
473+
})
474+
475+
return d.pair.parent
476+
}
477+
434478
func (d *dictValue) TzDate(v time.Time) *dict {
435479
d.pair.parent.values = append(d.pair.parent.values, value.DictValueField{
436480
K: d.pair.keyValue,

internal/params/dict_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/google/uuid"
89
"github.com/stretchr/testify/require"
910
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
1011

@@ -362,6 +363,38 @@ func TestDict(t *testing.T) {
362363
},
363364
},
364365
},
366+
{
367+
method: "Uuid",
368+
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
369+
370+
expected: expected{
371+
Type: &Ydb.Type{
372+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
373+
},
374+
Value: &Ydb.Value{
375+
Value: &Ydb.Value_Low_128{
376+
Low_128: 506660481424032516,
377+
},
378+
High_128: 1157159078456920585,
379+
},
380+
},
381+
},
382+
{
383+
method: "UUIDWithIssue1501Value",
384+
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
385+
386+
expected: expected{
387+
Type: &Ydb.Type{
388+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
389+
},
390+
Value: &Ydb.Value{
391+
Value: &Ydb.Value_Low_128{
392+
Low_128: 651345242494996240,
393+
},
394+
High_128: 72623859790382856,
395+
},
396+
},
397+
},
365398
{
366399
method: "TzDatetime",
367400
args: []any{time.Unix(123456789, 456).UTC()},

internal/params/list.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

@@ -165,12 +167,28 @@ func (l *listItem) YSON(v []byte) *list {
165167
return l.parent
166168
}
167169

170+
// UUID has data corruption bug and will be removed in next version.
171+
//
172+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
173+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
168174
func (l *listItem) UUID(v [16]byte) *list {
169175
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))
170176

171177
return l.parent
172178
}
173179

180+
func (l *listItem) Uuid(v uuid.UUID) *list { //nolint:revive,stylecheck
181+
l.parent.values = append(l.parent.values, value.Uuid(v))
182+
183+
return l.parent
184+
}
185+
186+
func (l *listItem) UUIDWithIssue1501Value(v [16]byte) *list {
187+
l.parent.values = append(l.parent.values, value.UUIDWithIssue1501Value(v))
188+
189+
return l.parent
190+
}
191+
174192
func (l *listItem) TzDate(v time.Time) *list {
175193
l.parent.values = append(l.parent.values, value.TzDateValueFromTime(v))
176194

internal/params/list_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
910

@@ -361,6 +362,38 @@ func TestList(t *testing.T) {
361362
},
362363
},
363364
},
365+
{
366+
method: "Uuid",
367+
args: []any{uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
368+
369+
expected: expected{
370+
Type: &Ydb.Type{
371+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
372+
},
373+
Value: &Ydb.Value{
374+
Value: &Ydb.Value_Low_128{
375+
Low_128: 506660481424032516,
376+
},
377+
High_128: 1157159078456920585,
378+
},
379+
},
380+
},
381+
{
382+
method: "UUIDWithIssue1501Value",
383+
args: []any{[...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}},
384+
385+
expected: expected{
386+
Type: &Ydb.Type{
387+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
388+
},
389+
Value: &Ydb.Value{
390+
Value: &Ydb.Value_Low_128{
391+
Low_128: 651345242494996240,
392+
},
393+
High_128: 72623859790382856,
394+
},
395+
},
396+
},
364397
{
365398
method: "TzDatetime",
366399
args: []any{time.Unix(123456789, 456).UTC()},

internal/params/optional.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

@@ -153,12 +155,28 @@ func (p *optional) YSON(v *[]byte) *optionalBuilder {
153155
return &optionalBuilder{opt: p}
154156
}
155157

158+
// UUID has data corruption bug and will be removed in next version.
159+
//
160+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
161+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
156162
func (p *optional) UUID(v *[16]byte) *optionalBuilder {
157163
p.value = value.NullableUUIDValue(v)
158164

159165
return &optionalBuilder{opt: p}
160166
}
161167

168+
func (p *optional) Uuid(v *uuid.UUID) *optionalBuilder { //nolint:revive,stylecheck
169+
p.value = value.NullableUuidValue(v)
170+
171+
return &optionalBuilder{opt: p}
172+
}
173+
174+
func (p *optional) UUIDWithIssue1501Value(v *[16]byte) *optionalBuilder {
175+
p.value = value.NullableUUIDValue(v)
176+
177+
return &optionalBuilder{opt: p}
178+
}
179+
162180
func (p *optional) TzDate(v *time.Time) *optionalBuilder {
163181
p.value = value.NullableTzDateValueFromTime(v)
164182

internal/params/optional_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
910

@@ -580,6 +581,58 @@ func TestOptional(t *testing.T) {
580581
},
581582
},
582583
},
584+
{
585+
method: "Uuid",
586+
args: []any{p(uuid.UUID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},
587+
588+
expected: expected{
589+
Type: &Ydb.Type{
590+
Type: &Ydb.Type_OptionalType{
591+
OptionalType: &Ydb.OptionalType{
592+
Item: &Ydb.Type{
593+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
594+
},
595+
},
596+
},
597+
},
598+
Value: &Ydb.Value{
599+
Value: &Ydb.Value_NestedValue{
600+
NestedValue: &Ydb.Value{
601+
Value: &Ydb.Value_Low_128{
602+
Low_128: 506660481424032516,
603+
},
604+
High_128: 1157159078456920585,
605+
},
606+
},
607+
},
608+
},
609+
},
610+
{
611+
method: "UUIDWithIssue1501Value",
612+
args: []any{p([...]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})},
613+
614+
expected: expected{
615+
Type: &Ydb.Type{
616+
Type: &Ydb.Type_OptionalType{
617+
OptionalType: &Ydb.OptionalType{
618+
Item: &Ydb.Type{
619+
Type: &Ydb.Type_TypeId{TypeId: Ydb.Type_UUID},
620+
},
621+
},
622+
},
623+
},
624+
Value: &Ydb.Value{
625+
Value: &Ydb.Value_NestedValue{
626+
NestedValue: &Ydb.Value{
627+
Value: &Ydb.Value_Low_128{
628+
Low_128: 651345242494996240,
629+
},
630+
High_128: 72623859790382856,
631+
},
632+
},
633+
},
634+
},
635+
},
583636
{
584637
method: "TzDatetime",
585638
args: []any{p(time.Unix(123456789, 456).UTC())},

internal/params/parameters.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,14 @@ func (p *Parameter) YSON(v []byte) Builder {
299299

300300
// UUID has data corruption bug and will be removed in next version.
301301
//
302-
// Deprecated: Use UUIDTyped (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
302+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
303303
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
304304
func (p *Parameter) UUID(v [16]byte) Builder {
305305
return p.UUIDWithIssue1501Value(v)
306306
}
307307

308308
// UUIDWithIssue1501Value is field serializer for save data with format bug.
309-
// For any new code use UUIDTyped
309+
// For any new code use Uuid
310310
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
311311
func (p *Parameter) UUIDWithIssue1501Value(v [16]byte) Builder {
312312
p.value = value.UUIDWithIssue1501Value(v)
@@ -315,8 +315,8 @@ func (p *Parameter) UUIDWithIssue1501Value(v [16]byte) Builder {
315315
return p.parent
316316
}
317317

318-
func (p *Parameter) UUIDTyped(val uuid.UUID) Builder {
319-
p.value = value.UUIDTyped(val)
318+
func (p *Parameter) Uuid(val uuid.UUID) Builder { //nolint:revive,stylecheck
319+
p.value = value.Uuid(val)
320320
p.parent.params = append(p.parent.params, p)
321321

322322
return p.parent

internal/params/set.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package params
33
import (
44
"time"
55

6+
"github.com/google/uuid"
7+
68
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
79
)
810

@@ -166,12 +168,28 @@ func (s *setItem) YSON(v []byte) *set {
166168
return s.parent
167169
}
168170

171+
// UUID has data corruption bug and will be removed in next version.
172+
//
173+
// Deprecated: Use Uuid (prefer) or UUIDWithIssue1501Value (for save old behavior) instead.
174+
// https://github.com/ydb-platform/ydb-go-sdk/issues/1501
169175
func (s *setItem) UUID(v [16]byte) *set {
170176
s.parent.values = append(s.parent.values, value.UUIDWithIssue1501Value(v))
171177

172178
return s.parent
173179
}
174180

181+
func (s *setItem) Uuid(v uuid.UUID) *set { //nolint:revive,stylecheck
182+
s.parent.values = append(s.parent.values, value.Uuid(v))
183+
184+
return s.parent
185+
}
186+
187+
func (s *setItem) UUIDWithIssue1501Value(v [16]byte) *set {
188+
s.parent.values = append(s.parent.values, value.UUIDWithIssue1501Value(v))
189+
190+
return s.parent
191+
}
192+
175193
func (s *setItem) TzDate(v time.Time) *set {
176194
s.parent.values = append(s.parent.values, value.TzDateValueFromTime(v))
177195

0 commit comments

Comments
 (0)