Skip to content

Commit 220ddf5

Browse files
robot4el0ve4ek
robot
authored andcommitted
Release v3.99.5
1 parent dca11b0 commit 220ddf5

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Added support of custom types to row.ScanStruct using sql.Scanner interface
2+
3+
## v3.99.5
14
* Fixed error `Empty query text` using prepared statements and `ydb.WithExecuteDataQueryOverQueryClient(true)` option
25
* Prepared statements always send query text on Execute call from now (previous behaviour - send query ID)
36
* Prevented create decoder instance until start read a message from topics

internal/value/cast.go

+8
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@ func CastTo(v Value, dst interface{}) error {
1010
return nil
1111
}
1212

13+
if scanner, has := dst.(Scanner); has {
14+
return scanner.UnmarshalYDBValue(v)
15+
}
16+
1317
return v.castTo(dst)
1418
}
19+
20+
type Scanner interface {
21+
UnmarshalYDBValue(value Value) error
22+
}

internal/value/cast_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ func loadLocation(t *testing.T, name string) *time.Location {
3232
return loc
3333
}
3434

35+
type testStringValueScanner struct {
36+
field string
37+
}
38+
39+
func (s *testStringValueScanner) UnmarshalYDBValue(v Value) error {
40+
return CastTo(v, &s.field)
41+
}
42+
3543
func TestCastTo(t *testing.T) {
3644
testsCases := []struct {
3745
name string
@@ -428,6 +436,13 @@ func TestCastTo(t *testing.T) {
428436
exp: DateValueFromTime(time.Date(2024, 1, 2, 0, 0, 0, 0, time.UTC)),
429437
err: nil,
430438
},
439+
{
440+
name: xtest.CurrentFileLine(),
441+
value: TextValue("text-string"),
442+
dst: ptr[testStringValueScanner](),
443+
exp: testStringValueScanner{field: "text-string"},
444+
err: nil,
445+
},
431446
}
432447
for _, tt := range testsCases {
433448
t.Run(tt.name, func(t *testing.T) {

internal/version/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package version
33
const (
44
Major = "3"
55
Minor = "99"
6-
Patch = "4"
6+
Patch = "5"
77

88
Package = "ydb-go-sdk"
99
)

tests/integration/query_range_test.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ import (
1919
"github.com/ydb-platform/ydb-go-sdk/v3/query"
2020
)
2121

22+
type testStringScanner struct {
23+
field string
24+
}
25+
26+
func (v *testStringScanner) Scan(value any) error {
27+
vs, ok := value.(string)
28+
if !ok {
29+
return fmt.Errorf("unexpected type of value %v", value)
30+
}
31+
v.field = vs
32+
return nil
33+
}
34+
2235
func TestQueryRange(t *testing.T) {
2336
ctx, cancel := context.WithCancel(xtest.Context(t))
2437
defer cancel()
@@ -84,19 +97,22 @@ func TestQueryRange(t *testing.T) {
8497
p1 string
8598
p2 uint64
8699
p3 time.Duration
100+
p4 testStringScanner
87101
)
88102
err := db.Query().Do(ctx, func(ctx context.Context, s query.Session) error {
89103
r, err := s.Query(ctx, `
90104
DECLARE $p1 AS Text;
91105
DECLARE $p2 AS Uint64;
92106
DECLARE $p3 AS Interval;
93-
SELECT $p1, $p2, $p3;
107+
DECLARE $p4 AS Text;
108+
SELECT $p1, $p2, $p3, $p4;
94109
`,
95110
query.WithParameters(
96111
ydb.ParamsBuilder().
97112
Param("$p1").Text("test").
98113
Param("$p2").Uint64(100500000000).
99114
Param("$p3").Interval(time.Duration(100500000000)).
115+
Param("$p4").Text("test2").
100116
Build(),
101117
),
102118
query.WithSyntax(query.SyntaxYQL),
@@ -112,7 +128,7 @@ func TestQueryRange(t *testing.T) {
112128
if err != nil {
113129
return err
114130
}
115-
err = row.Scan(&p1, &p2, &p3)
131+
err = row.Scan(&p1, &p2, &p3, &p4)
116132
if err != nil {
117133
return err
118134
}
@@ -126,6 +142,9 @@ func TestQueryRange(t *testing.T) {
126142
if p3 != time.Duration(100500000000) {
127143
return fmt.Errorf("unexpected p3 value: %v", p3)
128144
}
145+
if p4.field != "test2" {
146+
return fmt.Errorf("unexpected p4 value: %v", p4)
147+
}
129148
}
130149
}
131150
return nil

0 commit comments

Comments
 (0)