cosmosclient

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cosmosclient defines a shared Azure Cosmos DB (NoSQL API) container client interface used across the protosource framework. It is the Azure-side counterpart of aws/dynamoclient — a thin abstraction that lets stores and the opaquedata layer share a mockable surface while the production binding is satisfied by *azcosmos.ContainerClient via the Wrap helper.

Index

Constants

View Source
const MaxBatchOperations = 100

MaxBatchOperations is the Cosmos transactional-batch ceiling. Callers must pre-batch larger writes themselves; ExecuteCreateBatch refuses to forward a request that would exceed this limit rather than letting the SDK fail with an opaque server-side error.

Variables

This section is empty.

Functions

func IsBatchConflict

func IsBatchConflict(err error) bool

IsBatchConflict reports whether err represents a duplicate-key conflict (HTTP 409) returned from a transactional batch. Stores use this to map version collisions to their domain error.

Types

type BatchError

type BatchError struct {
	StatusCode int32
	Message    string
}

BatchError describes a failed transactional batch. StatusCode is the first non-FailedDependency operation result — typically what callers care about. Use errors.As to inspect.

func (*BatchError) Error

func (e *BatchError) Error() string

type ContainerClient

type ContainerClient interface {
	CreateItem(ctx context.Context, pk azcosmos.PartitionKey, item []byte, o *azcosmos.ItemOptions) (azcosmos.ItemResponse, error)
	UpsertItem(ctx context.Context, pk azcosmos.PartitionKey, item []byte, o *azcosmos.ItemOptions) (azcosmos.ItemResponse, error)
	ReadItem(ctx context.Context, pk azcosmos.PartitionKey, itemID string, o *azcosmos.ItemOptions) (azcosmos.ItemResponse, error)
	DeleteItem(ctx context.Context, pk azcosmos.PartitionKey, itemID string, o *azcosmos.ItemOptions) (azcosmos.ItemResponse, error)
	QueryItems(ctx context.Context, query string, pk azcosmos.PartitionKey, o *azcosmos.QueryOptions) ([][]byte, error)
	NewQueryItemsPager(query string, pk azcosmos.PartitionKey, o *azcosmos.QueryOptions) Pager
	// ExecuteCreateBatch atomically creates all items inside a single
	// partition. Returns BatchError when the transaction did not commit
	// (e.g. status 409 when an event document with the same id — the version
	// number — already exists, the Cosmos analog of Dynamo's conditional
	// write failure).
	ExecuteCreateBatch(ctx context.Context, pk azcosmos.PartitionKey, items [][]byte) error
}

ContainerClient is the Cosmos container interface used by the protosource framework. It covers all per-item, query, and batch operations needed by both the event store and the opaque data store. Implementations target a single container; consumers that need both events and aggregates wire two clients.

QueryItems drains all pages internally so callers do not have to manage continuation tokens. NewQueryItemsPager exposes the underlying pager for callers that need early termination (LoadTail).

func Wrap

Wrap adapts an *azcosmos.ContainerClient to the ContainerClient interface.

type Pager

type Pager interface {
	More() bool
	NextPage(ctx context.Context) ([][]byte, error)
}

Pager is a minimal pager interface mirroring azcosmos's runtime.Pager. It allows store code to terminate iteration once a target item count has been collected without forcing the underlying SDK to drain every page.

Jump to

Keyboard shortcuts

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