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 ¶
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 ¶
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 ¶
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 ¶
func Wrap(c *azcosmos.ContainerClient) ContainerClient
Wrap adapts an *azcosmos.ContainerClient to the ContainerClient interface.