Ver código fonte

expose page state

Chris Bannister 10 anos atrás
pai
commit
77cf2b54fa
2 arquivos alterados com 18 adições e 1 exclusões
  1. 1 1
      conn.go
  2. 17 0
      session.go

+ 1 - 1
conn.go

@@ -640,7 +640,7 @@ func (c *Conn) executeQuery(qry *Query) *Iter {
 			rows: x.rows,
 		}
 
-		if len(x.meta.pagingState) > 0 {
+		if len(x.meta.pagingState) > 0 && !qry.disableAutoPage {
 			iter.next = &nextIter{
 				qry: *qry,
 				pos: int((1 - qry.prefetch) * float64(len(iter.rows))),

+ 17 - 0
session.go

@@ -432,6 +432,8 @@ type Query struct {
 	totalLatency     int64
 	serialCons       SerialConsistency
 	defaultTimestamp bool
+
+	disableAutoPage bool
 }
 
 // String implements the stringer interface.
@@ -611,6 +613,15 @@ func (q *Query) SerialConsistency(cons SerialConsistency) *Query {
 	return q
 }
 
+// PageState sets the paging state for the query to resume paging from a specific
+// point in time. Setting this will disable to query paging for this query, and
+// must be used for all subsequent pages.
+func (q *Query) PageState(state []byte) *Query {
+	q.pageState = state
+	q.disableAutoPage = true
+	return q
+}
+
 // Exec executes the query without returning any rows.
 func (q *Query) Exec() error {
 	iter := q.Iter()
@@ -791,6 +802,12 @@ func (iter *Iter) checkErrAndNotFound() error {
 	return nil
 }
 
+// PageState return the current paging state for a query which can be used for
+// subsequent quries to resume paging this point.
+func (iter *Iter) PageState() []byte {
+	return iter.meta.pagingState
+}
+
 type nextIter struct {
 	qry  Query
 	pos  int