@@ -503,7 +503,7 @@ func (q *Query) toRunQueryRequest(req *pb.RunQueryRequest) error {
503
503
return err
504
504
}
505
505
506
- req .ReadOptions , err = parseReadOptions (q )
506
+ req .ReadOptions , err = parseReadOptions (q . eventual , q . trans )
507
507
if err != nil {
508
508
return err
509
509
}
@@ -730,6 +730,8 @@ func (c *Client) Run(ctx context.Context, q *Query) *Iterator {
730
730
ProjectId : c .dataset ,
731
731
DatabaseId : c .databaseID ,
732
732
},
733
+ trans : q .trans ,
734
+ eventual : q .eventual ,
733
735
}
734
736
735
737
if q .namespace != "" {
@@ -786,7 +788,7 @@ func (c *Client) RunAggregationQuery(ctx context.Context, aq *AggregationQuery)
786
788
}
787
789
788
790
// Parse the read options.
789
- req .ReadOptions , err = parseReadOptions (aq .query )
791
+ req .ReadOptions , err = parseReadOptions (aq .query . eventual , aq . query . trans )
790
792
if err != nil {
791
793
return nil , err
792
794
}
@@ -808,21 +810,33 @@ func (c *Client) RunAggregationQuery(ctx context.Context, aq *AggregationQuery)
808
810
return ar , nil
809
811
}
810
812
813
+ func validateReadOptions (eventual bool , t * Transaction ) error {
814
+ if t == nil {
815
+ return nil
816
+ }
817
+ if t .id == nil {
818
+ return errExpiredTransaction
819
+ }
820
+ if eventual {
821
+ return errors .New ("datastore: cannot use EventualConsistency query in a transaction" )
822
+ }
823
+ return nil
824
+ }
825
+
811
826
// parseReadOptions translates Query read options into protobuf format.
812
- func parseReadOptions (q * Query ) (* pb.ReadOptions , error ) {
813
- if t := q .trans ; t != nil {
814
- if t .id == nil {
815
- return nil , errExpiredTransaction
816
- }
817
- if q .eventual {
818
- return nil , errors .New ("datastore: cannot use EventualConsistency query in a transaction" )
819
- }
827
+ func parseReadOptions (eventual bool , t * Transaction ) (* pb.ReadOptions , error ) {
828
+ err := validateReadOptions (eventual , t )
829
+ if err != nil {
830
+ return nil , err
831
+ }
832
+
833
+ if t != nil {
820
834
return & pb.ReadOptions {
821
835
ConsistencyType : & pb.ReadOptions_Transaction {Transaction : t .id },
822
836
}, nil
823
837
}
824
838
825
- if q . eventual {
839
+ if eventual {
826
840
return & pb.ReadOptions {ConsistencyType : & pb.ReadOptions_ReadConsistency_ {ReadConsistency : pb .ReadOptions_EVENTUAL }}, nil
827
841
}
828
842
@@ -858,6 +872,14 @@ type Iterator struct {
858
872
pageCursor []byte
859
873
// entityCursor is the compiled cursor of the next result.
860
874
entityCursor []byte
875
+
876
+ // trans records the transaction in which the query was run
877
+ // Currently, this value is set but unused
878
+ trans * Transaction
879
+
880
+ // eventual records whether the query was eventual
881
+ // Currently, this value is set but unused
882
+ eventual bool
861
883
}
862
884
863
885
// Next returns the key of the next result. When there are no more results,
0 commit comments