Skip to content

Commit

Permalink
renamed internal/xsql to internal.connector
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Nov 5, 2024
1 parent 6538a32 commit 4f2ed1a
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 77 deletions.
4 changes: 2 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/discovery"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/connector"
internalCoordination "github.com/ydb-platform/ydb-go-sdk/v3/internal/coordination"
coordinationConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/coordination/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/credentials"
Expand All @@ -36,7 +37,6 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/internal/topic/topicclientinternal"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
"github.com/ydb-platform/ydb-go-sdk/v3/log"
"github.com/ydb-platform/ydb-go-sdk/v3/operation"
Expand Down Expand Up @@ -93,7 +93,7 @@ type (
topic *xsync.Once[*topicclientinternal.Client]
topicOptions []topicoptions.TopicOption

databaseSQLOptions []xsql.Option
databaseSQLOptions []connector.Option

pool *conn.Pool

Expand Down
18 changes: 9 additions & 9 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
"github.com/ydb-platform/ydb-go-sdk/v3/credentials"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/connector"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/dsn"
tableSql "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
)

const tablePathPrefixTransformer = "table_path_prefix"
Expand Down Expand Up @@ -64,41 +64,41 @@ func parseConnectionString(dataSourceName string) (opts []Option, _ error) {
if mode == tableSql.UnknownQueryMode {
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
}
opts = append(opts, withConnectorOptions(xsql.WithDefaultQueryMode(mode)))
opts = append(opts, withConnectorOptions(connector.WithDefaultQueryMode(mode)))
} else if queryMode := info.Params.Get("query_mode"); queryMode != "" {
mode := tableSql.QueryModeFromString(queryMode)
if mode == tableSql.UnknownQueryMode {
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
}
opts = append(opts, withConnectorOptions(xsql.WithDefaultQueryMode(mode)))
opts = append(opts, withConnectorOptions(connector.WithDefaultQueryMode(mode)))
}
if fakeTx := info.Params.Get("go_fake_tx"); fakeTx != "" {
for _, queryMode := range strings.Split(fakeTx, ",") {
mode := tableSql.QueryModeFromString(queryMode)
if mode == tableSql.UnknownQueryMode {
return nil, xerrors.WithStackTrace(fmt.Errorf("unknown query mode: %s", queryMode))
}
opts = append(opts, withConnectorOptions(xsql.WithFakeTx(mode)))
opts = append(opts, withConnectorOptions(connector.WithFakeTx(mode)))
}
}
if info.Params.Has("go_query_bind") {
var binders []xsql.Option
var binders []connector.Option
queryTransformers := strings.Split(info.Params.Get("go_query_bind"), ",")
for _, transformer := range queryTransformers {
switch transformer {
case "declare":
binders = append(binders, xsql.WithQueryBind(bind.AutoDeclare{}))
binders = append(binders, connector.WithQueryBind(bind.AutoDeclare{}))
case "positional":
binders = append(binders, xsql.WithQueryBind(bind.PositionalArgs{}))
binders = append(binders, connector.WithQueryBind(bind.PositionalArgs{}))
case "numeric":
binders = append(binders, xsql.WithQueryBind(bind.NumericArgs{}))
binders = append(binders, connector.WithQueryBind(bind.NumericArgs{}))
default:
if strings.HasPrefix(transformer, tablePathPrefixTransformer) {
prefix, err := extractTablePathPrefixFromBinderName(transformer)
if err != nil {
return nil, xerrors.WithStackTrace(err)
}
binders = append(binders, xsql.WithQueryBind(bind.TablePathPrefix(prefix)))
binders = append(binders, connector.WithQueryBind(bind.TablePathPrefix(prefix)))
} else {
return nil, xerrors.WithStackTrace(
fmt.Errorf("unknown query rewriter: %s", transformer),
Expand Down
64 changes: 32 additions & 32 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (

"github.com/ydb-platform/ydb-go-sdk/v3/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/bind"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/connector"
querySql "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/conn"
tableSql "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/conn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
)

func TestParse(t *testing.T) {
newConnector := func(opts ...xsql.Option) *xsql.Connector {
c := &xsql.Connector{}
newConnector := func(opts ...connector.Option) *connector.Connector {
c := &connector.Connector{}
for _, opt := range opts {
if opt != nil {
if err := opt.Apply(c); err != nil {
Expand All @@ -40,7 +40,7 @@ func TestParse(t *testing.T) {
for _, tt := range []struct {
dsn string
opts []config.Option
connectorOpts []xsql.Option
connectorOpts []connector.Option
err error
}{
{
Expand Down Expand Up @@ -70,8 +70,8 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
},
err: nil,
},
Expand All @@ -82,9 +82,9 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
},
err: nil,
},
Expand All @@ -95,10 +95,10 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
xsql.WithQueryBind(bind.NumericArgs{}),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connector.WithQueryBind(bind.NumericArgs{}),
},
err: nil,
},
Expand All @@ -109,10 +109,10 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
xsql.WithQueryBind(bind.PositionalArgs{}),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connector.WithQueryBind(bind.PositionalArgs{}),
},
err: nil,
},
Expand All @@ -123,10 +123,10 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
xsql.WithQueryBind(bind.AutoDeclare{}),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connector.WithQueryBind(bind.AutoDeclare{}),
},
err: nil,
},
Expand All @@ -137,9 +137,9 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
},
err: nil,
},
Expand All @@ -150,11 +150,11 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
xsql.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
xsql.WithQueryBind(bind.PositionalArgs{}),
xsql.WithQueryBind(bind.AutoDeclare{}),
connectorOpts: []connector.Option{
connector.WithDefaultQueryMode(tableSql.ScriptingQueryMode),
connector.WithQueryBind(bind.TablePathPrefix("path/to/tables")),
connector.WithQueryBind(bind.PositionalArgs{}),
connector.WithQueryBind(bind.AutoDeclare{}),
},
err: nil,
},
Expand All @@ -165,9 +165,9 @@ func TestParse(t *testing.T) {
config.WithEndpoint("localhost:2135"),
config.WithDatabase("/local"),
},
connectorOpts: []xsql.Option{
xsql.WithFakeTx(tableSql.ScriptingQueryMode),
xsql.WithFakeTx(tableSql.SchemeQueryMode),
connectorOpts: []connector.Option{
connector.WithFakeTx(tableSql.ScriptingQueryMode),
connector.WithFakeTx(tableSql.SchemeQueryMode),
},
err: nil,
},
Expand Down
4 changes: 2 additions & 2 deletions internal/xsql/conn.go → internal/connector/conn.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import (
"context"
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *connWrapper) IsColumnExists(ctx context.Context, tableName, columnName
func (c *connWrapper) IsTableExists(ctx context.Context, tableName string) (tableExists bool, finalErr error) {
tableName = c.normalizePath(tableName)
onDone := trace.DatabaseSQLOnConnIsTableExists(c.connector.trace, &ctx,
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql.(*connWrapper).IsTableExists"),
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/v3/internal/connector.(*connWrapper).IsTableExists"),
tableName,
)
defer func() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import "context"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion internal/xsql/errors.go → internal/connector/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import (
"database/sql/driver"
Expand Down
2 changes: 1 addition & 1 deletion internal/xsql/options.go → internal/connector/options.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion internal/xsql/unwrap.go → internal/connector/unwrap.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xsql
package connector

import (
"database/sql"
Expand Down
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
balancerConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/certificates"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/conn"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/connector"
coordinationConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/coordination/config"
discoveryConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/discovery/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/dsn"
Expand All @@ -23,7 +24,6 @@ import (
scriptingConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/scripting/config"
tableConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/table/config"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql"
"github.com/ydb-platform/ydb-go-sdk/v3/log"
"github.com/ydb-platform/ydb-go-sdk/v3/retry/budget"
"github.com/ydb-platform/ydb-go-sdk/v3/topic/topicoptions"
Expand Down Expand Up @@ -521,7 +521,7 @@ func WithSessionPoolIdleThreshold(idleThreshold time.Duration) Option {
return func(ctx context.Context, d *Driver) error {
d.tableOptions = append(d.tableOptions, tableConfig.WithIdleThreshold(idleThreshold))
d.databaseSQLOptions = append(d.databaseSQLOptions,
xsql.WithIdleThreshold(idleThreshold),
connector.WithIdleThreshold(idleThreshold),
)

return nil
Expand Down Expand Up @@ -772,7 +772,7 @@ func WithTraceTopic(t trace.Topic, opts ...trace.TopicComposeOption) Option { //
func WithTraceDatabaseSQL(t trace.DatabaseSQL, opts ...trace.DatabaseSQLComposeOption) Option { //nolint:gocritic
return func(ctx context.Context, d *Driver) error {
d.databaseSQLOptions = append(d.databaseSQLOptions,
xsql.WithTrace(
connector.WithTrace(
&t,
append(
[]trace.DatabaseSQLComposeOption{
Expand Down
Loading

0 comments on commit 4f2ed1a

Please sign in to comment.