github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/batch_cursor.go (about)

     1  // Copyright (C) MongoDB, Inc. 2022-present.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"); you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
     6  
     7  package mongo
     8  
     9  import (
    10  	"context"
    11  
    12  	"go.mongodb.org/mongo-driver/x/bsonx/bsoncore"
    13  	"go.mongodb.org/mongo-driver/x/mongo/driver"
    14  )
    15  
    16  // batchCursor is the interface implemented by types that can provide batches of document results.
    17  // The Cursor type is built on top of this type.
    18  type batchCursor interface {
    19  	// ID returns the ID of the cursor.
    20  	ID() int64
    21  
    22  	// Next returns true if there is a batch available.
    23  	Next(context.Context) bool
    24  
    25  	// Batch will return a DocumentSequence for the current batch of documents. The returned
    26  	// DocumentSequence is only valid until the next call to Next or Close.
    27  	Batch() *bsoncore.DocumentSequence
    28  
    29  	// Server returns a pointer to the cursor's server.
    30  	Server() driver.Server
    31  
    32  	// Err returns the last error encountered.
    33  	Err() error
    34  
    35  	// Close closes the cursor.
    36  	Close(context.Context) error
    37  
    38  	// The SetBatchSize method is a modifier function used to adjust the
    39  	// batch size of the cursor that implements it.
    40  	SetBatchSize(int32)
    41  }
    42  
    43  // changeStreamCursor is the interface implemented by batch cursors that also provide the functionality for retrieving
    44  // a postBatchResumeToken from commands and allows for the cursor to be killed rather than closed
    45  type changeStreamCursor interface {
    46  	batchCursor
    47  	// PostBatchResumeToken returns the latest seen post batch resume token.
    48  	PostBatchResumeToken() bsoncore.Document
    49  
    50  	// KillCursor kills cursor on server without closing batch cursor
    51  	KillCursor(context.Context) error
    52  }