Skip to content

Commit 6af8383

Browse files
authored
Merge pull request #247 from ydb-platform/cast
ydb.GRPCConn(ydb.Connection)
2 parents 5e7f8b4 + bef0400 commit 6af8383

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Added `ydb.GRPCConn(ydb.Connection)` helper for connect to driver-unsupported YDB services
12
* Marked as deprecated `session.Prepare` callback
23
* Marked as deprecated `options.WithQueryCachePolicyKeepInCache` and `options.WithQueryCachePolicy` options
34
* Added `options.WithKeepInCache` option

connection.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ type connection struct {
115115
panicCallback func(e interface{})
116116
}
117117

118-
var _ grpc.ClientConnInterface = (*connection)(nil)
119-
120118
func (c *connection) Close(ctx context.Context) error {
121119
c.mtx.Lock()
122120
defer c.mtx.Unlock()
@@ -429,3 +427,14 @@ func open(ctx context.Context, opts ...Option) (_ Connection, err error) {
429427

430428
return c, nil
431429
}
430+
431+
// GRPCConn casts ydb.Connection to grpc.ClientConnInterface for executing
432+
// unary and streaming RPC over internal driver balancer.
433+
//
434+
// Warning: for connect to driver-unsupported YDB services
435+
func GRPCConn(conn Connection) grpc.ClientConnInterface {
436+
if cc, ok := conn.(*connection); ok {
437+
return cc
438+
}
439+
return nil
440+
}

connection_e2e_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func TestConnection(t *testing.T) {
123123
}()
124124
t.Run("discovery.WhoAmI", func(t *testing.T) {
125125
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
126-
discoveryClient := Ydb_Discovery_V1.NewDiscoveryServiceClient(db.(grpc.ClientConnInterface))
126+
discoveryClient := Ydb_Discovery_V1.NewDiscoveryServiceClient(ydb.GRPCConn(db))
127127
response, err := discoveryClient.WhoAmI(
128128
ctx,
129129
&Ydb_Discovery.WhoAmIRequest{IncludeGroups: true},
@@ -143,7 +143,7 @@ func TestConnection(t *testing.T) {
143143
})
144144
t.Run("scripting.ExecuteYql", func(t *testing.T) {
145145
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
146-
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(db.(grpc.ClientConnInterface))
146+
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(ydb.GRPCConn(db))
147147
response, err := scriptingClient.ExecuteYql(
148148
ctx,
149149
&Ydb_Scripting.ExecuteYqlRequest{Script: "SELECT 1+100 AS sum"},
@@ -194,7 +194,7 @@ func TestConnection(t *testing.T) {
194194
})
195195
t.Run("scripting.StreamExecuteYql", func(t *testing.T) {
196196
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
197-
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(db.(grpc.ClientConnInterface))
197+
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(ydb.GRPCConn(db))
198198
client, err := scriptingClient.StreamExecuteYql(
199199
ctx,
200200
&Ydb_Scripting.ExecuteYqlRequest{Script: "SELECT 1+100 AS sum"},
@@ -248,7 +248,7 @@ func TestConnection(t *testing.T) {
248248
_ = childDB.Close(ctx)
249249
}()
250250
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
251-
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(childDB.(grpc.ClientConnInterface))
251+
scriptingClient := Ydb_Scripting_V1.NewScriptingServiceClient(ydb.GRPCConn(childDB))
252252
client, err := scriptingClient.StreamExecuteYql(
253253
ctx,
254254
&Ydb_Scripting.ExecuteYqlRequest{Script: "SELECT 1+100 AS sum"},
@@ -291,7 +291,7 @@ func TestConnection(t *testing.T) {
291291
})
292292
t.Run("export.ExportToS3", func(t *testing.T) {
293293
if err = retry.Retry(ctx, func(ctx context.Context) (err error) {
294-
exportClient := Ydb_Export_V1.NewExportServiceClient(db.(grpc.ClientConnInterface))
294+
exportClient := Ydb_Export_V1.NewExportServiceClient(ydb.GRPCConn(db))
295295
response, err := exportClient.ExportToS3(
296296
ctx,
297297
&Ydb_Export.ExportToS3Request{

0 commit comments

Comments
 (0)