diff --git a/examples/basic/native/query/series.go b/examples/basic/native/query/series.go index cb01d8106..6d2e711cf 100644 --- a/examples/basic/native/query/series.go +++ b/examples/basic/native/query/series.go @@ -16,15 +16,14 @@ import ( func read(ctx context.Context, c query.Client, prefix string) error { return c.Do(ctx, func(ctx context.Context, s query.Session) (err error) { - result, err := s.Query(ctx, fmt.Sprintf(` + result, err := s.Query(ctx, ` SELECT series_id, title, release_date FROM series - `, prefix), - query.WithTxControl(query.TxControl(query.BeginTx(query.WithOnlineReadOnly()))), + `, query.WithTxControl(query.TxControl(query.BeginTx(query.WithSnapshotReadOnly()))), ) if err != nil { return err diff --git a/internal/query/client.go b/internal/query/client.go index 26cdb8b9d..99b9055d9 100644 --- a/internal/query/client.go +++ b/internal/query/client.go @@ -2,7 +2,6 @@ package query import ( "context" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "time" "github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1" @@ -16,6 +15,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/pool" "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config" "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" diff --git a/internal/query/execute_query.go b/internal/query/execute_query.go index c931e3482..7b389f71e 100644 --- a/internal/query/execute_query.go +++ b/internal/query/execute_query.go @@ -144,10 +144,6 @@ func readAll(ctx context.Context, r *streamResult) error { } func readResultSet(ctx context.Context, r *streamResult) (_ *resultSetWithClose, finalErr error) { - defer func() { - _ = r.Close(ctx) - }() - rs, err := r.nextResultSet(ctx) if err != nil { return nil, xerrors.WithStackTrace(err) diff --git a/internal/query/range_experiment.go b/internal/query/range_experiment.go deleted file mode 100644 index df75de20b..000000000 --- a/internal/query/range_experiment.go +++ /dev/null @@ -1,44 +0,0 @@ -package query - -import ( - "context" - "io" - - "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter" -) - -func rangeResultSets(ctx context.Context, r result.Result) xiter.Seq2[result.Set, error] { - return func(yield func(result.Set, error) bool) { - for { - rs, err := r.NextResultSet(ctx) - if err != nil { - if xerrors.Is(err, io.EOF) { - return - } - } - cont := yield(rs, err) - if !cont || err != nil { - return - } - } - } -} - -func rangeRows(ctx context.Context, rs result.Set) xiter.Seq2[result.Set, error] { - return func(yield func(result.Row, error) bool) { - for { - rs, err := rs.NextRow(ctx) - if err != nil { - if xerrors.Is(err, io.EOF) { - return - } - } - cont := yield(rs, err) - if !cont || err != nil { - return - } - } - } -} diff --git a/internal/query/result.go b/internal/query/result.go index ca9e45f07..079d997f6 100644 --- a/internal/query/result.go +++ b/internal/query/result.go @@ -42,6 +42,23 @@ type ( resultOption func(s *streamResult) ) +func rangeResultSets(ctx context.Context, r result.Result) xiter.Seq2[result.Set, error] { + return func(yield func(result.Set, error) bool) { + for { + rs, err := r.NextResultSet(ctx) + if err != nil { + if xerrors.Is(err, io.EOF) { + return + } + } + cont := yield(rs, err) + if !cont || err != nil { + return + } + } + } +} + func (r *materializedResult) ResultSets(ctx context.Context) xiter.Seq2[result.Set, error] { return rangeResultSets(ctx, r) } diff --git a/internal/query/result_set.go b/internal/query/result_set.go index 8d2f2ea01..a3f4a810b 100644 --- a/internal/query/result_set.go +++ b/internal/query/result_set.go @@ -8,6 +8,7 @@ import ( "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "github.com/ydb-platform/ydb-go-sdk/v3/internal/types" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xiter" @@ -41,6 +42,23 @@ type ( } ) +func rangeRows(ctx context.Context, rs result.Set) xiter.Seq2[result.Row, error] { + return func(yield func(result.Row, error) bool) { + for { + rs, err := rs.NextRow(ctx) + if err != nil { + if xerrors.Is(err, io.EOF) { + return + } + } + cont := yield(rs, err) + if !cont || err != nil { + return + } + } + } +} + func (*materializedResultSet) Close(context.Context) error { return nil } @@ -49,11 +67,11 @@ func (rs *resultSetWithClose) Close(ctx context.Context) error { return rs.close(ctx) } -func (rs *materializedResultSet) Rows(ctx context.Context) xiter.Seq2[query.Row, error] { +func (rs *materializedResultSet) Rows(ctx context.Context) xiter.Seq2[result.Row, error] { return rangeRows(ctx, rs) } -func (rs *resultSet) Rows(ctx context.Context) xiter.Seq2[query.Row, error] { +func (rs *resultSet) Rows(ctx context.Context) xiter.Seq2[result.Row, error] { return rangeRows(ctx, rs) } diff --git a/internal/query/session.go b/internal/query/session.go index a7538d5a9..b0d41e837 100644 --- a/internal/query/session.go +++ b/internal/query/session.go @@ -2,7 +2,6 @@ package query import ( "context" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "sync/atomic" "github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1" @@ -10,6 +9,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/config" "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" "github.com/ydb-platform/ydb-go-sdk/v3/internal/tx" "github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext" diff --git a/internal/query/transaction.go b/internal/query/transaction.go index 176a7bbb8..abcf2af44 100644 --- a/internal/query/transaction.go +++ b/internal/query/transaction.go @@ -3,7 +3,6 @@ package query import ( "context" "fmt" - "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" "github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1" "github.com/ydb-platform/ydb-go-genproto/protos/Ydb" @@ -11,6 +10,7 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/internal/allocator" "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options" + "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result" queryTx "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/tx" "github.com/ydb-platform/ydb-go-sdk/v3/internal/stack" baseTx "github.com/ydb-platform/ydb-go-sdk/v3/internal/tx"