Skip to content

Commit f7cfd08

Browse files
committed
* Removed public query.Identifier interface for discard any external implementations for use with YDB
1 parent bbb2201 commit f7cfd08

File tree

7 files changed

+28
-19
lines changed

7 files changed

+28
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Removed public `query.Identifier` interface for exclude any external implementations for use with YDB
2+
13
## v3.74.0
24
* Added experimental range functions to the `query.Result` and `query.ResultSet` types, available as for-range loops starting with Go version 1.22. These features can be enabled by setting the environment variable `GOEXPERIMENT=rangefunc`.
35
* Added public types for `tx.Option`, `options.DoOption` and `options.DoTxOption`

internal/query/execute_query_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestExecute(t *testing.T) {
359359
tx, r, err := execute(ctx, newTestSession("123"), client, "", options.ExecuteSettings())
360360
require.NoError(t, err)
361361
defer r.Close(ctx)
362-
require.EqualValues(t, "456", tx.id)
362+
require.EqualValues(t, "456", tx.ID())
363363
require.EqualValues(t, "123", tx.s.id)
364364
require.EqualValues(t, -1, r.resultSetIndex)
365365
{
@@ -576,7 +576,7 @@ func TestExecute(t *testing.T) {
576576
tx, r, err := execute(ctx, newTestSession("123"), client, "", options.ExecuteSettings())
577577
require.NoError(t, err)
578578
defer r.Close(ctx)
579-
require.EqualValues(t, "456", tx.id)
579+
require.EqualValues(t, "456", tx.ID())
580580
require.EqualValues(t, "123", tx.s.id)
581581
require.EqualValues(t, -1, r.resultSetIndex)
582582
{
@@ -716,7 +716,7 @@ func TestExecute(t *testing.T) {
716716
tx, r, err := execute(ctx, newTestSession("123"), client, "", options.ExecuteSettings())
717717
require.NoError(t, err)
718718
defer r.Close(ctx)
719-
require.EqualValues(t, "456", tx.id)
719+
require.EqualValues(t, "456", tx.ID())
720720
require.EqualValues(t, "123", tx.s.id)
721721
require.EqualValues(t, -1, r.resultSetIndex)
722722
{

internal/query/session_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestBegin(t *testing.T) {
2929
t.Log("begin")
3030
tx, err := begin(ctx, service, &Session{id: "123"}, query.TxSettings())
3131
require.NoError(t, err)
32-
require.Equal(t, "123", tx.id)
32+
require.Equal(t, "123", tx.ID())
3333
})
3434
t.Run("TransportError", func(t *testing.T) {
3535
ctx := xtest.Context(t)

internal/query/transaction.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"
88

99
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
10+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/query/tx"
1011
"github.com/ydb-platform/ydb-go-sdk/v3/internal/stack"
1112
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1213
"github.com/ydb-platform/ydb-go-sdk/v3/query"
@@ -16,8 +17,9 @@ import (
1617
var _ query.Transaction = (*transaction)(nil)
1718

1819
type transaction struct {
19-
id string
20-
s *Session
20+
tx.Parent
21+
22+
s *Session
2123
}
2224

2325
func (tx transaction) ReadRow(ctx context.Context, q string, opts ...options.TxExecuteOption) (row query.Row, _ error) {
@@ -62,15 +64,11 @@ func (tx transaction) ReadResultSet(ctx context.Context, q string, opts ...optio
6264

6365
func newTransaction(id string, s *Session) *transaction {
6466
return &transaction{
65-
id: id,
66-
s: s,
67+
Parent: tx.Parent(id),
68+
s: s,
6769
}
6870
}
6971

70-
func (tx transaction) ID() string {
71-
return tx.id
72-
}
73-
7472
func (tx transaction) Execute(ctx context.Context, q string, opts ...options.TxExecuteOption) (
7573
r query.Result, finalErr error,
7674
) {
@@ -80,7 +78,7 @@ func (tx transaction) Execute(ctx context.Context, q string, opts ...options.TxE
8078
onDone(finalErr)
8179
}()
8280

83-
_, res, err := execute(ctx, tx.s, tx.s.grpcClient, q, options.TxExecuteSettings(tx.id, opts...).ExecuteSettings)
81+
_, res, err := execute(ctx, tx.s, tx.s.grpcClient, q, options.TxExecuteSettings(tx.ID(), opts...).ExecuteSettings)
8482
if err != nil {
8583
return nil, xerrors.WithStackTrace(err)
8684
}
@@ -101,7 +99,7 @@ func commitTx(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
10199
}
102100

103101
func (tx transaction) CommitTx(ctx context.Context) (err error) {
104-
return commitTx(ctx, tx.s.grpcClient, tx.s.id, tx.id)
102+
return commitTx(ctx, tx.s.grpcClient, tx.s.id, tx.ID())
105103
}
106104

107105
func rollback(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessionID, txID string) error {
@@ -117,5 +115,5 @@ func rollback(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
117115
}
118116

119117
func (tx transaction) Rollback(ctx context.Context) (err error) {
120-
return rollback(ctx, tx.s.grpcClient, tx.s.id, tx.id)
118+
return rollback(ctx, tx.s.grpcClient, tx.s.id, tx.ID())
121119
}

internal/query/tx/control.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type (
2626
}
2727
Identifier interface {
2828
ID() string
29+
isYdbTx()
2930
}
3031
)
3132

internal/query/tx/id.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tx
2+
3+
var _ Identifier = (*Parent)(nil)
4+
5+
type Parent string
6+
7+
func (id Parent) ID() string {
8+
return string(id)
9+
}
10+
11+
func (id Parent) isYdbTx() {}

query/transaction.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ import (
88
)
99

1010
type (
11-
TxIdentifier interface {
12-
ID() string
13-
}
1411
TxActor interface {
15-
TxIdentifier
12+
tx.Identifier
1613

1714
// Execute executes query.
1815
//

0 commit comments

Comments
 (0)