@@ -16,6 +16,7 @@ import (
1616 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config"
1717 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
1818 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
19+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/session"
1920 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/tx"
2021 "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
2122 "github.com/ydb-platform/ydb-go-sdk/v3/internal/types"
4142 With (ctx context.Context , f func (ctx context.Context , s * Session ) error , opts ... retry.Option ) error
4243 }
4344 Client struct {
44- config * config.Config
45- queryServiceClient Ydb_Query_V1.QueryServiceClient
46- pool sessionPool
45+ config * config.Config
46+ client Ydb_Query_V1.QueryServiceClient
47+ pool sessionPool
4748
4849 done chan struct {}
4950 }
@@ -100,7 +101,7 @@ func (c *Client) FetchScriptResults(ctx context.Context,
100101 opID string , opts ... options.FetchScriptOption ,
101102) (* options.FetchScriptResult , error ) {
102103 r , err := retry .RetryWithResult (ctx , func (ctx context.Context ) (* options.FetchScriptResult , error ) {
103- r , err := fetchScriptResults (ctx , c .queryServiceClient , opID ,
104+ r , err := fetchScriptResults (ctx , c .client , opID ,
104105 append (opts , func (request * options.FetchScriptResultsRequest ) {
105106 request .Trace = c .config .Trace ()
106107 })... ,
@@ -175,7 +176,7 @@ func (c *Client) ExecuteScript(
175176
176177 request , grpcOpts := executeQueryScriptRequest (a , q , settings )
177178
178- op , err = executeScript (ctx , c .queryServiceClient , request , grpcOpts ... )
179+ op , err = executeScript (ctx , c .client , request , grpcOpts ... )
179180 if err != nil {
180181 return op , xerrors .WithStackTrace (err )
181182 }
@@ -200,18 +201,18 @@ func do(
200201 opts ... retry.Option ,
201202) (finalErr error ) {
202203 err := pool .With (ctx , func (ctx context.Context , s * Session ) error {
203- s .setStatus ( statusInUse )
204+ s .SetStatus ( session . StatusInUse )
204205
205206 err := op (ctx , s )
206207 if err != nil {
207208 if xerrors .IsOperationError (err ) {
208- s .setStatus ( statusClosed )
209+ s .SetStatus ( session . StatusClosed )
209210 }
210211
211212 return xerrors .WithStackTrace (err )
212213 }
213214
214- s .setStatus ( statusIdle )
215+ s .SetStatus ( session . StatusIdle )
215216
216217 return nil
217218 }, opts ... )
@@ -337,7 +338,7 @@ func (c *Client) QueryRow(ctx context.Context, q string, opts ...options.Execute
337338func clientExec (ctx context.Context , pool sessionPool , q string , opts ... options.Execute ) (finalErr error ) {
338339 settings := options .ExecuteSettings (opts ... )
339340 err := do (ctx , pool , func (ctx context.Context , s * Session ) (err error ) {
340- _ , r , err := execute (ctx , s .id , s .queryServiceClient , q , settings , withTrace (s .cfg . Trace () ))
341+ _ , r , err := execute (ctx , s .ID () , s .client , q , settings , withTrace (s .trace ))
341342 if err != nil {
342343 return xerrors .WithStackTrace (err )
343344 }
@@ -381,8 +382,8 @@ func clientQuery(ctx context.Context, pool sessionPool, q string, opts ...option
381382) {
382383 settings := options .ExecuteSettings (opts ... )
383384 err = do (ctx , pool , func (ctx context.Context , s * Session ) (err error ) {
384- _ , streamResult , err := execute (ctx , s .id , s .queryServiceClient , q ,
385- options .ExecuteSettings (opts ... ), withTrace (s .cfg . Trace () ),
385+ _ , streamResult , err := execute (ctx , s .ID () , s .client , q ,
386+ options .ExecuteSettings (opts ... ), withTrace (s .trace ),
386387 )
387388 if err != nil {
388389 return xerrors .WithStackTrace (err )
@@ -433,7 +434,7 @@ func clientQueryResultSet(
433434 ctx context.Context , pool sessionPool , q string , settings executeSettings , resultOpts ... resultOption ,
434435) (rs result.ClosableResultSet , finalErr error ) {
435436 err := do (ctx , pool , func (ctx context.Context , s * Session ) error {
436- _ , r , err := execute (ctx , s .id , s .queryServiceClient , q , settings , resultOpts ... )
437+ _ , r , err := execute (ctx , s .ID () , s .client , q , settings , resultOpts ... )
437438 if err != nil {
438439 return xerrors .WithStackTrace (err )
439440 }
@@ -512,18 +513,18 @@ func (c *Client) DoTx(ctx context.Context, op query.TxOperation, opts ...options
512513 return nil
513514}
514515
515- func New (ctx context.Context , balancer grpc.ClientConnInterface , cfg * config.Config ) * Client {
516+ func New (ctx context.Context , cc grpc.ClientConnInterface , cfg * config.Config ) * Client {
516517 onDone := trace .QueryOnNew (cfg .Trace (), & ctx ,
517518 stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/query.New" ),
518519 )
519520 defer onDone ()
520521
521- grpcClient := Ydb_Query_V1 .NewQueryServiceClient (balancer )
522+ client := Ydb_Query_V1 .NewQueryServiceClient (cc )
522523
523- client := & Client {
524- config : cfg ,
525- queryServiceClient : grpcClient ,
526- done : make (chan struct {}),
524+ return & Client {
525+ config : cfg ,
526+ client : client ,
527+ done : make (chan struct {}),
527528 pool : pool .New (ctx ,
528529 pool.WithLimit [* Session , Session ](cfg .PoolLimit ()),
529530 pool.WithTrace [* Session , Session ](poolTrace (cfg .Trace ())),
@@ -541,7 +542,11 @@ func New(ctx context.Context, balancer grpc.ClientConnInterface, cfg *config.Con
541542 }
542543 defer cancelCreate ()
543544
544- s , err := createSession (createCtx , grpcClient , cfg )
545+ s , err := createSession (createCtx , client ,
546+ session .WithConn (cc ),
547+ session .WithDeleteTimeout (cfg .SessionDeleteTimeout ()),
548+ session .WithTrace (cfg .Trace ()),
549+ )
545550 if err != nil {
546551 return nil , xerrors .WithStackTrace (err )
547552 }
@@ -550,8 +555,6 @@ func New(ctx context.Context, balancer grpc.ClientConnInterface, cfg *config.Con
550555 }),
551556 ),
552557 }
553-
554- return client
555558}
556559
557560func poolTrace (t * trace.Query ) * pool.Trace {
0 commit comments