From 4f2ed1a411538005e514eb6462d025fac17dfb75 Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov Date: Tue, 5 Nov 2024 17:24:37 +0300 Subject: [PATCH] renamed internal/xsql to internal.connector --- driver.go | 4 +- dsn.go | 18 +++---- dsn_test.go | 64 +++++++++++------------ internal/{xsql => connector}/conn.go | 4 +- internal/{xsql => connector}/conn_test.go | 2 +- internal/{xsql => connector}/connector.go | 2 +- internal/{xsql => connector}/errors.go | 2 +- internal/{xsql => connector}/options.go | 2 +- internal/{xsql => connector}/unwrap.go | 2 +- options.go | 6 +-- sql.go | 44 ++++++++-------- sql_unwrap.go | 4 +- 12 files changed, 77 insertions(+), 77 deletions(-) rename internal/{xsql => connector}/conn.go (99%) rename internal/{xsql => connector}/conn_test.go (98%) rename internal/{xsql => connector}/connector.go (99%) rename internal/{xsql => connector}/errors.go (92%) rename internal/{xsql => connector}/options.go (99%) rename internal/{xsql => connector}/unwrap.go (98%) diff --git a/driver.go b/driver.go index 44f1ba3d4..46a682aca 100644 --- a/driver.go +++ b/driver.go @@ -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" @@ -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" @@ -93,7 +93,7 @@ type ( topic *xsync.Once[*topicclientinternal.Client] topicOptions []topicoptions.TopicOption - databaseSQLOptions []xsql.Option + databaseSQLOptions []connector.Option pool *conn.Pool diff --git a/dsn.go b/dsn.go index 3dc3f8638..054b84f71 100644 --- a/dsn.go +++ b/dsn.go @@ -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" @@ -64,13 +64,13 @@ 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, ",") { @@ -78,27 +78,27 @@ 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.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), diff --git a/dsn_test.go b/dsn_test.go index 671329907..cb241a9a5 100644 --- a/dsn_test.go +++ b/dsn_test.go @@ -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 { @@ -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 }{ { @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/internal/xsql/conn.go b/internal/connector/conn.go similarity index 99% rename from internal/xsql/conn.go rename to internal/connector/conn.go index dfef0d13d..432d64b6f 100644 --- a/internal/xsql/conn.go +++ b/internal/connector/conn.go @@ -1,4 +1,4 @@ -package xsql +package connector import ( "context" @@ -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() { diff --git a/internal/xsql/conn_test.go b/internal/connector/conn_test.go similarity index 98% rename from internal/xsql/conn_test.go rename to internal/connector/conn_test.go index 9d3e1d4d1..07dff50f3 100644 --- a/internal/xsql/conn_test.go +++ b/internal/connector/conn_test.go @@ -1,4 +1,4 @@ -package xsql +package connector import "context" diff --git a/internal/xsql/connector.go b/internal/connector/connector.go similarity index 99% rename from internal/xsql/connector.go rename to internal/connector/connector.go index 5df05f555..72c25a039 100644 --- a/internal/xsql/connector.go +++ b/internal/connector/connector.go @@ -1,4 +1,4 @@ -package xsql +package connector import ( "context" diff --git a/internal/xsql/errors.go b/internal/connector/errors.go similarity index 92% rename from internal/xsql/errors.go rename to internal/connector/errors.go index 7e1df34bd..33581f0a6 100644 --- a/internal/xsql/errors.go +++ b/internal/connector/errors.go @@ -1,4 +1,4 @@ -package xsql +package connector import ( "database/sql/driver" diff --git a/internal/xsql/options.go b/internal/connector/options.go similarity index 99% rename from internal/xsql/options.go rename to internal/connector/options.go index d1d17fd22..8efa24d1c 100644 --- a/internal/xsql/options.go +++ b/internal/connector/options.go @@ -1,4 +1,4 @@ -package xsql +package connector import ( "time" diff --git a/internal/xsql/unwrap.go b/internal/connector/unwrap.go similarity index 98% rename from internal/xsql/unwrap.go rename to internal/connector/unwrap.go index 574bc26c6..eedb2bf8f 100644 --- a/internal/xsql/unwrap.go +++ b/internal/connector/unwrap.go @@ -1,4 +1,4 @@ -package xsql +package connector import ( "database/sql" diff --git a/options.go b/options.go index 4b8d43fdc..ed1b02cfb 100644 --- a/options.go +++ b/options.go @@ -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" @@ -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" @@ -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 @@ -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{ diff --git a/sql.go b/sql.go index b5423de90..322f2fdc0 100644 --- a/sql.go +++ b/sql.go @@ -7,9 +7,9 @@ import ( "fmt" "github.com/ydb-platform/ydb-go-sdk/v3/internal/bind" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/connector" 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" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync" "github.com/ydb-platform/ydb-go-sdk/v3/table" "github.com/ydb-platform/ydb-go-sdk/v3/table/options" @@ -32,7 +32,7 @@ func withConnectorOptions(opts ...ConnectorOption) Option { } type sqlDriver struct { - connectors xsync.Map[*xsql.Connector, *Driver] + connectors xsync.Map[*connector.Connector, *Driver] } var ( @@ -42,7 +42,7 @@ var ( func (d *sqlDriver) Close() error { var errs []error - d.connectors.Range(func(c *xsql.Connector, _ *Driver) bool { + d.connectors.Range(func(c *connector.Connector, _ *Driver) bool { if err := c.Close(); err != nil { errs = append(errs, err) } @@ -58,7 +58,7 @@ func (d *sqlDriver) Close() error { // Open returns a new Driver to the ydb. func (d *sqlDriver) Open(string) (driver.Conn, error) { - return nil, xsql.ErrUnsupported + return nil, connector.ErrUnsupported } func (d *sqlDriver) OpenConnector(dataSourceName string) (driver.Connector, error) { @@ -70,11 +70,11 @@ func (d *sqlDriver) OpenConnector(dataSourceName string) (driver.Connector, erro return Connector(db, db.databaseSQLOptions...) } -func (d *sqlDriver) attach(c *xsql.Connector, parent *Driver) { +func (d *sqlDriver) attach(c *connector.Connector, parent *Driver) { d.connectors.Set(c, parent) } -func (d *sqlDriver) detach(c *xsql.Connector) { +func (d *sqlDriver) detach(c *connector.Connector) { d.connectors.Delete(c) } @@ -96,7 +96,7 @@ func WithTxControl(ctx context.Context, txc *table.TransactionControl) context.C return tableSql.WithTxControl(ctx, txc) } -type ConnectorOption = xsql.Option +type ConnectorOption = connector.Option type QueryBindConnectorOption interface { ConnectorOption @@ -104,50 +104,50 @@ type QueryBindConnectorOption interface { } func WithDefaultQueryMode(mode QueryMode) ConnectorOption { - return xsql.WithTableOptions(tableSql.WithDefaultQueryMode(mode)) + return connector.WithTableOptions(tableSql.WithDefaultQueryMode(mode)) } func WithFakeTx(mode QueryMode) ConnectorOption { - return xsql.WithTableOptions(tableSql.WithFakeTxModes(mode)) + return connector.WithTableOptions(tableSql.WithFakeTxModes(mode)) } func WithTablePathPrefix(tablePathPrefix string) QueryBindConnectorOption { - return xsql.WithTablePathPrefix(tablePathPrefix) + return connector.WithTablePathPrefix(tablePathPrefix) } func WithAutoDeclare() QueryBindConnectorOption { - return xsql.WithQueryBind(bind.AutoDeclare{}) + return connector.WithQueryBind(bind.AutoDeclare{}) } func WithPositionalArgs() QueryBindConnectorOption { - return xsql.WithQueryBind(bind.PositionalArgs{}) + return connector.WithQueryBind(bind.PositionalArgs{}) } func WithNumericArgs() QueryBindConnectorOption { - return xsql.WithQueryBind(bind.NumericArgs{}) + return connector.WithQueryBind(bind.NumericArgs{}) } func WithDefaultTxControl(txControl *table.TransactionControl) ConnectorOption { - return xsql.WithTableOptions(tableSql.WithDefaultTxControl(txControl)) + return connector.WithTableOptions(tableSql.WithDefaultTxControl(txControl)) } func WithDefaultDataQueryOptions(opts ...options.ExecuteDataQueryOption) ConnectorOption { - return xsql.WithTableOptions(tableSql.WithDataOpts(opts...)) + return connector.WithTableOptions(tableSql.WithDataOpts(opts...)) } func WithDefaultScanQueryOptions(opts ...options.ExecuteScanQueryOption) ConnectorOption { - return xsql.WithTableOptions(tableSql.WithScanOpts(opts...)) + return connector.WithTableOptions(tableSql.WithScanOpts(opts...)) } func WithDatabaseSQLTrace( t trace.DatabaseSQL, //nolint:gocritic opts ...trace.DatabaseSQLComposeOption, ) ConnectorOption { - return xsql.WithTrace(&t, opts...) + return connector.WithTrace(&t, opts...) } func WithDisableServerBalancer() ConnectorOption { - return xsql.WithDisableServerBalancer() + return connector.WithDisableServerBalancer() } type SQLConnector interface { @@ -157,15 +157,15 @@ type SQLConnector interface { } func Connector(parent *Driver, opts ...ConnectorOption) (SQLConnector, error) { - c, err := xsql.Open(parent, parent.metaBalancer, + c, err := connector.Open(parent, parent.metaBalancer, append( append( parent.databaseSQLOptions, opts..., ), - xsql.WithOnClose(d.detach), - xsql.WithTraceRetry(parent.config.TraceRetry()), - xsql.WithRetryBudget(parent.config.RetryBudget()), + connector.WithOnClose(d.detach), + connector.WithTraceRetry(parent.config.TraceRetry()), + connector.WithRetryBudget(parent.config.RetryBudget()), )..., ) if err != nil { diff --git a/sql_unwrap.go b/sql_unwrap.go index f183dcf28..9c1df829a 100644 --- a/sql_unwrap.go +++ b/sql_unwrap.go @@ -3,12 +3,12 @@ package ydb import ( "database/sql" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/connector" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/xsql" ) func Unwrap[T *sql.DB | *sql.Conn](v T) (*Driver, error) { - c, err := xsql.Unwrap(v) + c, err := connector.Unwrap(v) if err != nil { return nil, xerrors.WithStackTrace(err) }