Skip to content

Commit 09313b6

Browse files
committed
* Changed ydb.WithWideTimeTypes(bool) for allow boolean argument
1 parent cd6ab3f commit 09313b6

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* Added bindings options into `ydb.ParamsFromMap` for bind wide time types
2+
* Changed `ydb.WithWideTimeTypes(bool)` for allow boolean argument
23

34
## v3.104.1
45
* Added export of advanced metric information for QueryService calls

dsn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func parseConnectionString(dataSourceName string) (opts []Option, _ error) {
115115
case "numeric":
116116
binders = append(binders, xsql.WithQueryBind(bind.NumericArgs{}))
117117
case "wide_time_types":
118-
binders = append(binders, xsql.WithQueryBind(bind.WideTimeTypes{}))
118+
binders = append(binders, xsql.WithQueryBind(bind.WideTimeTypes(true)))
119119
default:
120120
if strings.HasPrefix(transformer, tablePathPrefixTransformer) {
121121
prefix, err := extractTablePathPrefixFromBinderName(transformer)

dsn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func TestParse(t *testing.T) {
182182
xsql.WithDefaultQueryMode(xtable.ScriptingQueryMode),
183183
xsql.WithQueryBind(bind.PositionalArgs{}),
184184
xsql.WithQueryBind(bind.AutoDeclare{}),
185-
xsql.WithQueryBind(bind.WideTimeTypes{}),
185+
xsql.WithQueryBind(bind.WideTimeTypes(true)),
186186
},
187187
err: nil,
188188
},

internal/bind/wide_time_types.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import (
77
"github.com/ydb-platform/ydb-go-sdk/v3/internal/value"
88
)
99

10-
type WideTimeTypes struct{}
10+
type WideTimeTypes bool
11+
12+
func (b WideTimeTypes) ToYdb(sql string, args ...any) (yql string, newArgs []any, _ error) {
13+
if !b {
14+
return sql, args, nil
15+
}
1116

12-
func (m WideTimeTypes) ToYdb(sql string, args ...any) (yql string, newArgs []any, _ error) {
1317
newArgs = make([]any, 0, len(args))
1418
for _, arg := range args {
1519
switch t := arg.(type) {
@@ -42,6 +46,6 @@ func (m WideTimeTypes) ToYdb(sql string, args ...any) (yql string, newArgs []any
4246
return sql, newArgs, nil
4347
}
4448

45-
func (m WideTimeTypes) blockID() blockID {
49+
func (b WideTimeTypes) blockID() blockID {
4650
return blockCastArgs
4751
}

internal/bind/wide_time_types_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestWideTimeTypesBind(t *testing.T) {
5858
},
5959
},
6060
{
61-
bind: WideTimeTypes{},
61+
bind: WideTimeTypes(true),
6262
sql: `SELECT ?, ?`,
6363
args: []any{
6464
100,
@@ -71,7 +71,7 @@ func TestWideTimeTypesBind(t *testing.T) {
7171
},
7272
},
7373
{
74-
bind: WideTimeTypes{},
74+
bind: WideTimeTypes(true),
7575
sql: `SELECT ?, ?`,
7676
args: []any{
7777
time.Unix(123, 456),
@@ -84,7 +84,7 @@ func TestWideTimeTypesBind(t *testing.T) {
8484
},
8585
},
8686
{
87-
bind: WideTimeTypes{},
87+
bind: WideTimeTypes(true),
8888
sql: `SELECT ?, ?`,
8989
args: []any{
9090
time.Duration(123) * time.Millisecond,

params_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestParamsFromMap(t *testing.T) {
260260
params := ydb.ParamsFromMap(map[string]any{
261261
"a": time.Date(1900, 1, 1, 0, 0, 0, 123456, time.UTC),
262262
"b": time.Duration(123) * time.Nanosecond,
263-
}, ydb.WithWideTimeTypes())
263+
}, ydb.WithWideTimeTypes(true))
264264
pp, err := params.ToYDB(&allocator.Allocator{})
265265
require.NoError(t, err)
266266
require.EqualValues(t, map[string]*Ydb.TypedValue{

query_bind_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ SELECT $p0;`,
583583
b: testutil.QueryBind(
584584
ydb.WithAutoDeclare(),
585585
ydb.WithPositionalArgs(),
586-
ydb.WithWideTimeTypes(),
586+
ydb.WithWideTimeTypes(true),
587587
),
588588
sql: `SELECT ?;`,
589589
args: []interface{}{time.Unix(123, 456)},

sql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ func WithPositionalArgs() QueryBindConnectorOption {
189189
return xsql.WithQueryBind(bind.PositionalArgs{})
190190
}
191191

192-
func WithWideTimeTypes() QueryBindConnectorOption {
193-
return xsql.WithQueryBind(bind.WideTimeTypes{})
192+
func WithWideTimeTypes(b bool) QueryBindConnectorOption {
193+
return xsql.WithQueryBind(bind.WideTimeTypes(b))
194194
}
195195

196196
func WithNumericArgs() QueryBindConnectorOption {

0 commit comments

Comments
 (0)