features

package
v0.10.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const BatchSize int = 10000

BatchSize is the default number of document to pull in a single request.

View Source
const LongpollTimeout time.Duration = minClientTimeout - 3*time.Second

LongpollTimeout is set to give the changes request a chance to be answered before the client timeout it is set to 3 seconds less.

Variables

View Source
var ErrKeySet = errors.New(`the option "Key" is invalid when using pagination`)
View Source
var ErrNoMoreResults = errors.New("no more results available")
View Source
var ErrNotImplemented = errors.New("not yet implemented")

Functions

This section is empty.

Types

type AllDocsPagerOptions added in v0.10.4

type AllDocsPagerOptions interface {
	*cloudantv1.PostAllDocsOptions | *cloudantv1.PostPartitionAllDocsOptions
}

AllDocsPagerOptions defines options for paginating through all documents or partitioned all documents in a Cloudant database.

type ChangesFollower

type ChangesFollower struct {
	// contains filtered or unexported fields
}

ChangesFollower is a helper for using the changes feed.

There are two modes of operation:

StartOneOff() to fetch the changes from the supplied since sequence
until there are no further pending changes.
Start() to fetch the changes from the supplied since sequence
and then continuing to listen indefinitely for further new changes.

The starting sequence ID can be changed for either mode by using "Since". By default when using:

StartOneOff() the feed will start from the beginning.
Start() the feed will start from "now".

In either mode the response stream can be terminated early by calling Stop(). By default ChangesFollower will suppress transient errors indefinitely and endeavour to run to completion or listen forever. For applications where that behaviour is not desirable an alternate option is available where a duration may be specified to limit the time since the last successful response that transient errors will be suppressed. It should be noted that some errors considered terminal, for example, the database not existing or invalid credentials are never suppressed and will return an Error immediately. The named attributes for "PostChangesOptions" are used to configure the behaviour of the ChangesFollower. However, a subset of the attributes are invalid as they are configured internally by the implementation and will cause an Error to be returned if supplied. These invalid options are:

  • Descending
  • Feed
  • Heartbeat
  • LastEventID
  • Timeout

Only the value of "_selector" is permitted for the PostChangesOptions's "Filter" option. Selector based filters perform better than JS based filters and using one of the alternative JS based filter types will cause ChangesFollower to return an Error. It should also be noted that the "Limit" parameter will truncate the response at the given number of changes in either operating mode. The ChangesFollower requires the Cloudant client to have HTTP timeout of at least 1 minute. The default client configuration has a sufficiently long timeout.

func NewChangesFollower

NewChangesFollower returns a new ChangesFollower or an error if provided configuration is invalid.

func NewChangesFollowerWithContext

func NewChangesFollowerWithContext(ctx context.Context, c *cloudantv1.CloudantV1, o *cloudantv1.PostChangesOptions) (*ChangesFollower, error)

NewChangesFollowerWithContext returns a new ChangesFollower initiated with a given context or an error if provided configuration is invalid.

func (*ChangesFollower) SetErrorTolerance

func (cf *ChangesFollower) SetErrorTolerance(d time.Duration) error

SetErrorTolerance sets the duration to suppress errors, measured from the previous successful request.

func (*ChangesFollower) Start

func (cf *ChangesFollower) Start() (<-chan ChangesItem, error)

Start returns a channel that will stream all available changes and keep listening for new changes until reaching an end condition.

The end conditions are:

  • a terminal error (e.g. unauthorized client).
  • transient errors occur for longer than the error suppression duration.
  • the number of changes received reaches the limit specified in the "PostChangesOptions" args used to instantiate this ChangesFollower.
  • ChangesFollower's Stop() is called.

The same change may be received more than once.

Returns a channel of ChangesItem structs or an error if ChangesFollower's Start() or StartOneOff() was already called or terminal error is recevied from the service during setup.

func (*ChangesFollower) StartOneOff

func (cf *ChangesFollower) StartOneOff() (<-chan ChangesItem, error)

StartOneOff returns a channel that will stream all available changes until there are no further changes pending or reaching an end condition.

The end conditions are:

  • a terminal error (e.g. unauthorized client).
  • transient errors occur for longer than the error suppression duration.
  • the number of changes received reaches the limit specified in the "PostChangesOptions" used to instantiate this ChangesFollower.
  • ChangesFollower's Stop() is called.

The same change may be received more than once.

Returns a channel of ChangesItem structs or an error if ChangesFollower's Start() or StartOneOff() was already called or terminal error is recevied from the service during setup.

func (*ChangesFollower) Stop

func (cf *ChangesFollower) Stop()

Stop this ChangesFollower.

type ChangesItem

type ChangesItem struct {
	// contains filtered or unexported fields
}

ChangesItem is a wrapper structure around cloudantv1.ChangesResultItem with addtitional attribute Error for errors received during the run.

func (ChangesItem) Item

Item is a ChangesItem's getter for cloudantv1.ChangesResultItem that either returns an acquired item or an error received during its fetch.

type DesignDocsPagerOptions added in v0.10.4

type DesignDocsPagerOptions interface {
	*cloudantv1.PostDesignDocsOptions
}

DesignDocsPagerOptions defines options for paginating through design documents in a Cloudant database.

type FindPagerOptions added in v0.10.4

type FindPagerOptions interface {
	*cloudantv1.PostFindOptions | *cloudantv1.PostPartitionFindOptions
}

FindPagerOptions defines options for paginating through queries or partitioned queries in a Cloudant database.

type Mode

type Mode int

Mode are enums for changes follower's operation mode.

const (
	// Finite mode is an alias for StartOneOff()
	Finite Mode = iota
	// Listen mode is an alias for Start()
	Listen
)

type Pager added in v0.10.4

type Pager[T PaginatedRow] interface {
	// HasNext returns false if there are no more pages.
	HasNext() bool

	// GetNext retrieves the next page of results.
	GetNext() ([]T, error)

	// GetNextWithContext retrieves the next page of results with user provided context.
	GetNextWithContext(context.Context) ([]T, error)

	// GetAll retrieves all elements from the pager.
	GetAll() ([]T, error)

	// GetAllWithContext retrieves all the elements from the pager with user provided context.
	GetAllWithContext(context.Context) ([]T, error)
}

Pager is an interface for pagination of Cloudant query operations.

type PaginatedRow added in v0.10.4

PaginatedRow defines a response object for Pager operations

type Pagination added in v0.10.4

type Pagination[T PaginatedRow] interface {
	// Pager returns new Pager.
	Pager() (Pager[T], error)

	// Pages returns an iterator for all pages from the pager.
	Pages() iter.Seq2[[]T, error]

	// PagesWithContext returns an iterator for all pages from the pager queried with user provided context.
	PagesWithContext(context.Context) iter.Seq2[[]T, error]

	// Rows returns an iterator for all elements from the pager.
	Rows() iter.Seq2[T, error]

	// RowsWithContext returns an iterator for all elements from the pager queried with user provided context.
	RowsWithContext(context.Context) iter.Seq2[T, error]
}

func NewAllDocsPagination added in v0.10.4

NewAllDocsPagination creates a new pagination for all documents operations.

func NewDesignDocsPagination added in v0.10.4

NewDesignDocsPagination creates a new pagination for design documents operations.

func NewFindPagination added in v0.10.4

func NewFindPagination[O FindPagerOptions](c *cloudantv1.CloudantV1, o O) Pagination[cloudantv1.Document]

NewFindPagination creates a new pagination for queries operations.

func NewSearchPagination added in v0.10.4

NewSearchPagination creates a new pagination for searches operations.

func NewViewPagination added in v0.10.4

NewViewPagination creates a new pagination for views operations.

type SearchPagerOptions added in v0.10.4

type SearchPagerOptions interface {
	*cloudantv1.PostSearchOptions | *cloudantv1.PostPartitionSearchOptions
}

SearchPagerOptions defines options for paginating through searches or partitioned searches in a Cloudant database.

type TransientErrorSuppression

type TransientErrorSuppression int

TransientErrorSuppression are enums for changes follower's transient errors suppression mode.

const (
	// Always suppress transient errors
	Always TransientErrorSuppression = iota
	// Never suppress transient errors
	Never
	// Timer specifies a time duration for suppressing transient errors
	Timer
)

type ViewPagerOptions added in v0.10.4

type ViewPagerOptions interface {
	*cloudantv1.PostViewOptions | *cloudantv1.PostPartitionViewOptions
}

ViewPagerOptions defines options for paginating through views or partitioned views in a Cloudant database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL