Skip to content

Commit

Permalink
Queryの実行をBatchReadOnlyTransactionに変更した refs #9
Browse files Browse the repository at this point in the history
  • Loading branch information
sinmetal committed May 8, 2019
1 parent ceb9c87 commit 684b6b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion spanner/spanner_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/csv"
"io"
"time"

"cloud.google.com/go/spanner"
"github.com/gcpug/hake"
Expand All @@ -26,7 +27,11 @@ func (s *SpannerEntityService) QueryToWrite(ctx context.Context, sql string, hea
hw := hake.NewWriter(cw, header)

var count int
iter := s.sc.Single().Query(ctx, q)
tx, err := s.sc.BatchReadOnlyTransaction(ctx, spanner.ReadTimestamp(time.Now()))
if err != nil {
return errors.WithStack(err)
}
iter := tx.Query(ctx, q)
defer iter.Stop()
for {
row, err := iter.Next()
Expand Down

0 comments on commit 684b6b0

Please sign in to comment.