Skip to content

Commit 3f5638b

Browse files
committed
refactoring
1 parent 92aeba7 commit 3f5638b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+245
-354
lines changed

Diff for: dsn.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/ydb-platform/ydb-go-sdk/v3/internal/dsn"
1313
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1414
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
15-
tableSql "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/table/conn"
15+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/table"
1616
)
1717

1818
const tablePathPrefixTransformer = "table_path_prefix"
@@ -60,22 +60,22 @@ func parseConnectionString(dataSourceName string) (opts []Option, _ error) {
6060
opts = append(opts, WithBalancer(balancers.FromConfig(balancer)))
6161
}
6262
if queryMode := info.Params.Get("go_query_mode"); queryMode != "" {
63-
mode := tableSql.QueryModeFromString(queryMode)
64-
if mode == tableSql.UnknownQueryMode {
63+
mode := table.QueryModeFromString(queryMode)
64+
if mode == table.UnknownQueryMode {
6565
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
6666
}
6767
opts = append(opts, withConnectorOptions(xsql.WithDefaultQueryMode(mode)))
6868
} else if queryMode := info.Params.Get("query_mode"); queryMode != "" {
69-
mode := tableSql.QueryModeFromString(queryMode)
70-
if mode == tableSql.UnknownQueryMode {
69+
mode := table.QueryModeFromString(queryMode)
70+
if mode == table.UnknownQueryMode {
7171
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
7272
}
7373
opts = append(opts, withConnectorOptions(xsql.WithDefaultQueryMode(mode)))
7474
}
7575
if fakeTx := info.Params.Get("go_fake_tx"); fakeTx != "" {
7676
for _, queryMode := range strings.Split(fakeTx, ",") {
77-
mode := tableSql.QueryModeFromString(queryMode)
78-
if mode == tableSql.UnknownQueryMode {
77+
mode := table.QueryModeFromString(queryMode)
78+
if mode == table.UnknownQueryMode {
7979
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
8080
}
8181
opts = append(opts, withConnectorOptions(xsql.WithFakeTx(mode)))

Diff for: dsn_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/ydb-platform/ydb-go-sdk/v3/config"
1010
"github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
1111
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
12-
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/query/conn"
13-
conn3 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/table/conn"
12+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/query"
13+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql/conn/table"
1414
)
1515

1616
func TestParse(t *testing.T) {
@@ -26,11 +26,11 @@ func TestParse(t *testing.T) {
2626

2727
return c
2828
}
29-
newTableConn := func(opts ...conn3.Option) *conn3.Conn {
30-
return conn3.New(context.Background(), nil, nil, opts...)
29+
newTableConn := func(opts ...table.Option) *table.Conn {
30+
return table.New(context.Background(), nil, nil, opts...)
3131
}
32-
newQueryConn := func(opts ...conn.Option) *conn.Conn {
33-
return conn.New(context.Background(), nil, nil, opts...)
32+
newQueryConn := func(opts ...query.Option) *query.Conn {
33+
return query.New(context.Background(), nil, nil, opts...)
3434
}
3535
compareConfigs := func(t *testing.T, lhs, rhs *config.Config) {
3636
require.Equal(t, lhs.Secure(), rhs.Secure())
@@ -71,7 +71,7 @@ func TestParse(t *testing.T) {
7171
config.WithDatabase("/local"),
7272
},
7373
connectorOpts: []xsql.Option{
74-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
74+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
7575
},
7676
err: nil,
7777
},
@@ -83,7 +83,7 @@ func TestParse(t *testing.T) {
8383
config.WithDatabase("/local"),
8484
},
8585
connectorOpts: []xsql.Option{
86-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
86+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
8787
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
8888
},
8989
err: nil,
@@ -96,7 +96,7 @@ func TestParse(t *testing.T) {
9696
config.WithDatabase("/local"),
9797
},
9898
connectorOpts: []xsql.Option{
99-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
99+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
100100
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
101101
xsql.WithQueryBind(bind.NumericArgs{}),
102102
},
@@ -110,7 +110,7 @@ func TestParse(t *testing.T) {
110110
config.WithDatabase("/local"),
111111
},
112112
connectorOpts: []xsql.Option{
113-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
113+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
114114
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
115115
xsql.WithQueryBind(bind.PositionalArgs{}),
116116
},
@@ -124,7 +124,7 @@ func TestParse(t *testing.T) {
124124
config.WithDatabase("/local"),
125125
},
126126
connectorOpts: []xsql.Option{
127-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
127+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
128128
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
129129
xsql.WithQueryBind(bind.AutoDeclare{}),
130130
},
@@ -138,7 +138,7 @@ func TestParse(t *testing.T) {
138138
config.WithDatabase("/local"),
139139
},
140140
connectorOpts: []xsql.Option{
141-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
141+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
142142
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
143143
},
144144
err: nil,
@@ -151,7 +151,7 @@ func TestParse(t *testing.T) {
151151
config.WithDatabase("/local"),
152152
},
153153
connectorOpts: []xsql.Option{
154-
xsql.WithDefaultQueryMode(conn3.ScriptingQueryMode),
154+
xsql.WithDefaultQueryMode(table.ScriptingQueryMode),
155155
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
156156
xsql.WithQueryBind(bind.PositionalArgs{}),
157157
xsql.WithQueryBind(bind.AutoDeclare{}),
@@ -166,8 +166,8 @@ func TestParse(t *testing.T) {
166166
config.WithDatabase("/local"),
167167
},
168168
connectorOpts: []xsql.Option{
169-
xsql.WithFakeTx(conn3.ScriptingQueryMode),
170-
xsql.WithFakeTx(conn3.SchemeQueryMode),
169+
xsql.WithFakeTx(table.ScriptingQueryMode),
170+
xsql.WithFakeTx(table.SchemeQueryMode),
171171
},
172172
err: nil,
173173
},

Diff for: examples/ddl/ddl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ ALTER TABLE small_table3 SET (TTL = Interval("PT3H") ON d);
6767
`
6868
)
6969

70-
func executeQuery(ctx context.Context, c table.Client, prefix, query string) (err error) {
70+
func executeQuery(ctx context.Context, c table.Client, prefix, sql string) (err error) {
7171
err = c.Do(ctx,
7272
func(ctx context.Context, s table.Session) error {
73-
err = s.ExecuteSchemeQuery(ctx, fmt.Sprintf(query, prefix))
73+
err = s.ExecuteSchemeQuery(ctx, fmt.Sprintf(sql, prefix))
7474

7575
return err
7676
},

Diff for: internal/bind/auto_declare.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (m AutoDeclare) blockID() blockID {
1313
return blockDeclare
1414
}
1515

16-
func (m AutoDeclare) RewriteQuery(query string, args ...interface{}) (
16+
func (m AutoDeclare) ToYdb(sql string, args ...interface{}) (
1717
yql string, newArgs []interface{}, err error,
1818
) {
1919
params, err := Params(args...)
@@ -22,7 +22,7 @@ func (m AutoDeclare) RewriteQuery(query string, args ...interface{}) (
2222
}
2323

2424
if len(params) == 0 {
25-
return query, args, nil
25+
return sql, args, nil
2626
}
2727

2828
var (
@@ -46,7 +46,7 @@ func (m AutoDeclare) RewriteQuery(query string, args ...interface{}) (
4646

4747
buffer.WriteByte('\n')
4848

49-
buffer.WriteString(query)
49+
buffer.WriteString(sql)
5050

5151
for _, param := range params {
5252
newArgs = append(newArgs, param)

Diff for: internal/bind/bind.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const (
1717
)
1818

1919
type Bind interface {
20-
RewriteQuery(sql string, args ...interface{}) (
20+
ToYdb(sql string, args ...interface{}) (
2121
yql string, newArgs []interface{}, _ error,
2222
)
2323

@@ -26,35 +26,35 @@ type Bind interface {
2626

2727
type Bindings []Bind
2828

29-
func (bindings Bindings) RewriteQuery(query string, args ...interface{}) (
30-
yql string, parameters []*params.Parameter, err error,
29+
func (bindings Bindings) ToYdb(sql string, args ...interface{}) (
30+
yql string, params params.Params, err error,
3131
) {
3232
if len(bindings) == 0 {
33-
parameters, err = Params(args...)
33+
params, err = Params(args...)
3434
if err != nil {
3535
return "", nil, xerrors.WithStackTrace(err)
3636
}
3737

38-
return query, parameters, nil
38+
return sql, params, nil
3939
}
4040

4141
buffer := xstring.Buffer()
4242
defer buffer.Free()
4343

4444
for i := range bindings {
4545
var e error
46-
query, args, e = bindings[len(bindings)-1-i].RewriteQuery(query, args...)
46+
sql, args, e = bindings[len(bindings)-1-i].ToYdb(sql, args...)
4747
if e != nil {
4848
return "", nil, xerrors.WithStackTrace(e)
4949
}
5050
}
5151

52-
parameters, err = Params(args...)
52+
params, err = Params(args...)
5353
if err != nil {
5454
return "", nil, xerrors.WithStackTrace(err)
5555
}
5656

57-
return query, parameters, nil
57+
return sql, params, nil
5858
}
5959

6060
func Sort(bindings []Bind) []Bind {

Diff for: internal/bind/numeric_args.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (m NumericArgs) blockID() blockID {
1717
return blockYQL
1818
}
1919

20-
func (m NumericArgs) RewriteQuery(sql string, args ...interface{}) (yql string, newArgs []interface{}, err error) {
20+
func (m NumericArgs) ToYdb(sql string, args ...interface{}) (yql string, newArgs []interface{}, err error) {
2121
l := &sqlLexer{
2222
src: sql,
2323
stateFn: numericArgsStateFn,

Diff for: internal/bind/numeric_args_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ SELECT $p0, $p1`,
314314
},
315315
} {
316316
t.Run("", func(t *testing.T) {
317-
yql, params, err := b.RewriteQuery(tt.sql, tt.args...)
317+
yql, params, err := b.ToYdb(tt.sql, tt.args...)
318318
if tt.err != nil {
319319
require.Error(t, err)
320320
require.ErrorIs(t, err, tt.err)

Diff for: internal/bind/positional_args.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (m PositionalArgs) blockID() blockID {
1616
return blockYQL
1717
}
1818

19-
func (m PositionalArgs) RewriteQuery(sql string, args ...interface{}) (
19+
func (m PositionalArgs) ToYdb(sql string, args ...interface{}) (
2020
yql string, newArgs []interface{}, err error,
2121
) {
2222
l := &sqlLexer{

Diff for: internal/bind/positional_args_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ SELECT $p0, $p1`,
238238
},
239239
} {
240240
t.Run("", func(t *testing.T) {
241-
yql, params, err := b.RewriteQuery(tt.sql, tt.args...)
241+
yql, params, err := b.ToYdb(tt.sql, tt.args...)
242242
if tt.err != nil {
243243
require.Error(t, err)
244244
require.ErrorIs(t, err, tt.err)

Diff for: internal/bind/table_path_prefix.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (tablePathPrefix TablePathPrefix) NormalizePath(folderOrTable string) strin
2424
}
2525
}
2626

27-
func (tablePathPrefix TablePathPrefix) RewriteQuery(query string, args ...interface{}) (
27+
func (tablePathPrefix TablePathPrefix) ToYdb(sql string, args ...interface{}) (
2828
yql string, newArgs []interface{}, err error,
2929
) {
3030
buffer := xstring.Buffer()
@@ -34,7 +34,7 @@ func (tablePathPrefix TablePathPrefix) RewriteQuery(query string, args ...interf
3434
buffer.WriteString("PRAGMA TablePathPrefix(\"")
3535
buffer.WriteString(string(tablePathPrefix))
3636
buffer.WriteString("\");\n\n")
37-
buffer.WriteString(query)
37+
buffer.WriteString(sql)
3838

3939
return buffer.String(), args, nil
4040
}

0 commit comments

Comments
 (0)