cosmosdb

package
v0.0.0-...-88298ca Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrETagRequired = fmt.Errorf("ETag is required")

ErrETagRequired is the error returned if the ETag field is not populate on a PUT or DELETE operation

View Source
var ErrNotImplemented = fmt.Errorf("not implemented")

ErrNotImplemented is the error returned if a fake function is not implemented

Functions

func IsErrorStatusCode

func IsErrorStatusCode(err error, statusCode int) bool

IsErrorStatusCode returns true if err is of type Error and its StatusCode matches statusCode

func RetryOnPreconditionFailed

func RetryOnPreconditionFailed(f func() error) (err error)

RetryOnPreconditionFailed retries a function if it fails due to PreconditionFailed

Types

type Authorizer

type Authorizer interface {
	Authorize(*http.Request, string, string)
}

func NewMasterKeyAuthorizer

func NewMasterKeyAuthorizer(masterKey string) (Authorizer, error)

func NewTokenAuthorizer

func NewTokenAuthorizer(token string) Authorizer

type Collection

type Collection struct {
	ID                       string                    `json:"id,omitempty"`
	ResourceID               string                    `json:"_rid,omitempty"`
	Timestamp                int                       `json:"_ts,omitempty"`
	Self                     string                    `json:"_self,omitempty"`
	ETag                     string                    `json:"_etag,omitempty"`
	Documents                string                    `json:"_docs,omitempty"`
	StoredProcedures         string                    `json:"_sprocs,omitempty"`
	Triggers                 string                    `json:"_triggers,omitempty"`
	UserDefinedFunctions     string                    `json:"_udfs,omitempty"`
	Conflicts                string                    `json:"_conflicts,omitempty"`
	IndexingPolicy           *IndexingPolicy           `json:"indexingPolicy,omitempty"`
	PartitionKey             *PartitionKey             `json:"partitionKey,omitempty"`
	UniqueKeyPolicy          *UniqueKeyPolicy          `json:"uniqueKeyPolicy,omitempty"`
	ConflictResolutionPolicy *ConflictResolutionPolicy `json:"conflictResolutionPolicy,omitempty"`
	AllowMaterializedViews   bool                      `json:"allowMaterializedViews,omitempty"`
	GeospatialConfig         *GeospatialConfig         `json:"geospatialConfig,omitempty"`
}

Collection represents a collection

type CollectionClient

type CollectionClient interface {
	Create(context.Context, *Collection) (*Collection, error)
	List() CollectionIterator
	ListAll(context.Context) (*Collections, error)
	Get(context.Context, string) (*Collection, error)
	Delete(context.Context, *Collection) error
	Replace(context.Context, *Collection) (*Collection, error)
	PartitionKeyRanges(context.Context, string) (*PartitionKeyRanges, error)
}

CollectionClient is a collection client

func NewCollectionClient

func NewCollectionClient(c DatabaseClient, dbid string) CollectionClient

NewCollectionClient returns a new collection client

type CollectionIterator

type CollectionIterator interface {
	Next(context.Context) (*Collections, error)
}

CollectionIterator is a collection iterator

type Collections

type Collections struct {
	Count       int           `json:"_count,omitempty"`
	ResourceID  string        `json:"_rid,omitempty"`
	Collections []*Collection `json:"DocumentCollections,omitempty"`
}

Collections represents collections

type CompositeIndex

type CompositeIndex []struct {
	Path  string `json:"path,omitempty"`
	Order Order  `json:"order,omitempty"`
}

CompositeIndex represents a composite index

type ConflictResolutionPolicy

type ConflictResolutionPolicy struct {
	Mode                        ConflictResolutionPolicyMode `json:"mode,omitempty"`
	ConflictResolutionPath      string                       `json:"conflictResolutionPath,omitempty"`
	ConflictResolutionProcedure string                       `json:"conflictResolutionProcedure,omitempty"`
}

ConflictResolutionPolicy represents a conflict resolution policy

type ConflictResolutionPolicyMode

type ConflictResolutionPolicyMode string

ConflictResolutionPolicyMode represents a conflict resolution policy mode

const (
	ConflictResolutionPolicyModeLastWriterWins ConflictResolutionPolicyMode = "LastWriterWins"
	ConflictResolutionPolicyModeCustom         ConflictResolutionPolicyMode = "Custom"
)

ConflictResolutionPolicyMode constants

type Database

type Database struct {
	ID          string `json:"id,omitempty"`
	ResourceID  string `json:"_rid,omitempty"`
	Timestamp   int    `json:"_ts,omitempty"`
	Self        string `json:"_self,omitempty"`
	ETag        string `json:"_etag,omitempty"`
	Collections string `json:"_colls,omitempty"`
	Users       string `json:"_users,omitempty"`
}

Database represents a database

type DatabaseClient

type DatabaseClient interface {
	SetAuthorizer(Authorizer)
	Create(context.Context, *Database) (*Database, error)
	List() DatabaseIterator
	ListAll(context.Context) (*Databases, error)
	Get(context.Context, string) (*Database, error)
	Delete(context.Context, *Database) error
}

DatabaseClient is a database client

func NewDatabaseClient

func NewDatabaseClient(log *logrus.Entry, hc *http.Client, jsonHandle *codec.JsonHandle, databaseHostname string, authorizer Authorizer) DatabaseClient

NewDatabaseClient returns a new database client

type DatabaseIterator

type DatabaseIterator interface {
	Next(context.Context) (*Databases, error)
}

DatabaseIterator is a database iterator

type Databases

type Databases struct {
	Count      int         `json:"_count,omitempty"`
	ResourceID string      `json:"_rid,omitempty"`
	Databases  []*Database `json:"Databases,omitempty"`
}

Databases represents databases

type Error

type Error struct {
	StatusCode int
	Code       string `json:"code"`
	Message    string `json:"message"`
}

Error represents an error

func (*Error) Error

func (e *Error) Error() string

type ExcludedPath

type ExcludedPath struct {
	Path string `json:"path,omitempty"`
}

ExcludedPath represents an excluded path

type FakeTemplateClient

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

FakeTemplateClient is a FakeTemplateClient

func NewFakeTemplateClient

func NewFakeTemplateClient(h *codec.JsonHandle) *FakeTemplateClient

NewFakeTemplateClient returns a FakeTemplateClient

func (*FakeTemplateClient) ChangeFeed

ChangeFeed is unimplemented

func (*FakeTemplateClient) Create

func (c *FakeTemplateClient) Create(ctx context.Context, partitionkey string, template *pkg.Template, options *Options) (*pkg.Template, error)

Create creates a Template in the database

func (*FakeTemplateClient) Delete

func (c *FakeTemplateClient) Delete(ctx context.Context, partitionKey string, template *pkg.Template, options *Options) error

Delete deletes a Template from the database

func (*FakeTemplateClient) Get

func (c *FakeTemplateClient) Get(ctx context.Context, partitionkey string, id string, options *Options) (*pkg.Template, error)

Get gets a Template from the database

func (*FakeTemplateClient) List

List returns a TemplateIterator to list all Templates in the database

func (*FakeTemplateClient) ListAll

func (c *FakeTemplateClient) ListAll(ctx context.Context, options *Options) (*pkg.Templates, error)

ListAll lists all Templates in the database

func (*FakeTemplateClient) Query

func (c *FakeTemplateClient) Query(name string, query *Query, options *Options) TemplateRawIterator

Query calls a query handler to implement database querying

func (*FakeTemplateClient) QueryAll

func (c *FakeTemplateClient) QueryAll(ctx context.Context, partitionkey string, query *Query, options *Options) (*pkg.Templates, error)

QueryAll calls a query handler to implement database querying

func (*FakeTemplateClient) Replace

func (c *FakeTemplateClient) Replace(ctx context.Context, partitionkey string, template *pkg.Template, options *Options) (*pkg.Template, error)

Replace replaces a Template in the database

func (*FakeTemplateClient) SetConflictChecker

func (c *FakeTemplateClient) SetConflictChecker(conflictChecker func(*pkg.Template, *pkg.Template) bool)

SetConflictChecker sets or unsets a function which can be used to validate additional unique keys in a Template

func (*FakeTemplateClient) SetError

func (c *FakeTemplateClient) SetError(err error)

SetError sets or unsets an error that will be returned on any FakeTemplateClient method invocation

func (*FakeTemplateClient) SetQueryHandler

func (c *FakeTemplateClient) SetQueryHandler(queryName string, query fakeTemplateQueryHandler)

SetQueryHandler sets or unsets a query handler

func (*FakeTemplateClient) SetSorter

func (c *FakeTemplateClient) SetSorter(sorter func([]*pkg.Template))

SetSorter sets or unsets a sorter function which will be used to sort values returned by List() for test stability

func (*FakeTemplateClient) SetTriggerHandler

func (c *FakeTemplateClient) SetTriggerHandler(triggerName string, trigger fakeTemplateTriggerHandler)

SetTriggerHandler sets or unsets a trigger handler

type GeospatialConfig

type GeospatialConfig struct {
	Type GeospatialConfigType `json:"type,omitempty"`
}

GeospatialConfig represents a geospatial config

type GeospatialConfigType

type GeospatialConfigType string

GeospatialConfigType represents geospatial config types

const (
	GeospatialConfigTypeGeography GeospatialConfigType = "Geography"
)

GeospatialConfigType constants

type IncludedPath

type IncludedPath struct {
	Path    string  `json:"path,omitempty"`
	Indexes []Index `json:"indexes,omitempty"`
}

IncludedPath represents an included path

type Index

type Index struct {
	DataType  IndexDataType `json:"dataType,omitempty"`
	Kind      IndexKind     `json:"kind,omitempty"`
	Precision int           `json:"precision,omitempty"`
}

Index represents an index

type IndexDataType

type IndexDataType string

IndexDataType represents an index data type

const (
	IndexDataTypeString     IndexDataType = "String"
	IndexDataTypeNumber     IndexDataType = "Number"
	IndexDataTypePoint      IndexDataType = "Point"
	IndexDataTypePolygon    IndexDataType = "Polygon"
	IndexDataTypeLineString IndexDataType = "LineString"
)

IndexDataType constants

type IndexKind

type IndexKind string

IndexKind represents an index kind

const (
	IndexKindHash    IndexKind = "Hash"
	IndexKindRange   IndexKind = "Range"
	IndexKindSpatial IndexKind = "Spatial"
)

IndexKind constants

type IndexingPolicy

type IndexingPolicy struct {
	Automatic        bool               `json:"automatic,omitempty"`
	IndexingMode     IndexingPolicyMode `json:"indexingMode,omitempty"`
	IncludedPaths    []IncludedPath     `json:"includedPaths,omitempty"`
	ExcludedPaths    []IncludedPath     `json:"excludedPaths,omitempty"`
	CompositeIndexes []CompositeIndex   `json:"compositeIndexes,omitempty"`
}

IndexingPolicy represents an indexing policy

type IndexingPolicyMode

type IndexingPolicyMode string

IndexingPolicyMode represents an indexing policy mode

const (
	IndexingPolicyModeConsistent IndexingPolicyMode = "Consistent"
	IndexingPolicyModeLazy       IndexingPolicyMode = "Lazy"
)

IndexingPolicyMode constants

type MissingFields

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

MissingFields retains values that do not map to struct fields during JSON marshalling/unmarshalling. MissingFields implements github.com/ugorji/go/codec.MissingFielder.

func (*MissingFields) CodecMissingField

func (mf *MissingFields) CodecMissingField(field []byte, value interface{}) bool

CodecMissingField is called to set a missing field and value pair

func (*MissingFields) CodecMissingFields

func (mf *MissingFields) CodecMissingFields() map[string]interface{}

CodecMissingFields returns the set of fields which are not struct fields

type Options

type Options struct {
	NoETag              bool
	PreTriggers         []string
	PostTriggers        []string
	PartitionKeyRangeID string
	Continuation        string
}

Options represents API options

type Order

type Order string

Order represents an order

const (
	OrderAscending  Order = "ascending"
	OrderDescending Order = "descending"
)

Order constants

type Parameter

type Parameter struct {
	Name  string `json:"name,omitempty"`
	Value string `json:"value,omitempty"`
}

Parameter represents a parameter

type PartitionKey

type PartitionKey struct {
	Paths   []string         `json:"paths,omitempty"`
	Kind    PartitionKeyKind `json:"kind,omitempty"`
	Version int              `json:"version,omitempty"`
}

PartitionKey represents a partition key

type PartitionKeyKind

type PartitionKeyKind string

PartitionKeyKind represents a partition key kind

const (
	PartitionKeyKindHash PartitionKeyKind = "Hash"
)

PartitionKeyKind constants

type PartitionKeyRange

type PartitionKeyRange struct {
	MissingFields

	ID                 string                  `json:"id,omitempty"`
	ResourceID         string                  `json:"_rid,omitempty"`
	Timestamp          int                     `json:"_ts,omitempty"`
	Self               string                  `json:"_self,omitempty"`
	ETag               string                  `json:"_etag,omitempty"`
	MaxExclusive       string                  `json:"maxExclusive,omitempty"`
	MinInclusive       string                  `json:"minInclusive,omitempty"`
	ResourceIDPrefix   int                     `json:"ridPrefix,omitempty"`
	ThroughputFraction float64                 `json:"throughputFraction,omitempty"`
	Status             PartitionKeyRangeStatus `json:"status,omitempty"`
	Parents            []string                `json:"parents,omitempty"`
	LSN                int                     `json:"lsn,omitempty"`
}

PartitionKeyRange represents a partition key range

type PartitionKeyRangeStatus

type PartitionKeyRangeStatus string

PartitionKeyRangeStatus represents a partition key range status

const (
	PartitionKeyRangeStatusOnline PartitionKeyRangeStatus = "online"
)

PartitionKeyRangeStatus constants

type PartitionKeyRanges

type PartitionKeyRanges struct {
	Count              int                 `json:"_count,omitempty"`
	ResourceID         string              `json:"_rid,omitempty"`
	PartitionKeyRanges []PartitionKeyRange `json:"PartitionKeyRanges,omitempty"`
}

PartitionKeyRanges represents partition key ranges

type Permission

type Permission struct {
	ID             string         `json:"id,omitempty"`
	ResourceID     string         `json:"_rid,omitempty"`
	Timestamp      int            `json:"_ts,omitempty"`
	Self           string         `json:"_self,omitempty"`
	ETag           string         `json:"_etag,omitempty"`
	Token          string         `json:"_token,omitempty"`
	PermissionMode PermissionMode `json:"permissionMode,omitempty"`
	Resource       string         `json:"resource,omitempty"`
}

Permission represents a permission

type PermissionClient

type PermissionClient interface {
	Create(context.Context, *Permission) (*Permission, error)
	List() PermissionIterator
	ListAll(context.Context) (*Permissions, error)
	Get(context.Context, string) (*Permission, error)
	Delete(context.Context, *Permission) error
	Replace(context.Context, *Permission) (*Permission, error)
}

PermissionClient is a permission client

func NewPermissionClient

func NewPermissionClient(userc UserClient, userid string) PermissionClient

NewPermissionClient returns a new permission client

type PermissionIterator

type PermissionIterator interface {
	Next(context.Context) (*Permissions, error)
}

PermissionIterator is a permission iterator

type PermissionMode

type PermissionMode string

PermissionMode represents a permission mode

const (
	PermissionModeAll  PermissionMode = "All"
	PermissionModeRead PermissionMode = "Read"
)

PermissionMode constants

type Permissions

type Permissions struct {
	Count       int           `json:"_count,omitempty"`
	ResourceID  string        `json:"_rid,omitempty"`
	Permissions []*Permission `json:"Permissions,omitempty"`
}

Permissions represents permissions

type Query

type Query struct {
	Query      string      `json:"query,omitempty"`
	Parameters []Parameter `json:"parameters,omitempty"`
}

Query represents a query

type TemplateClient

TemplateClient is a template client

func NewTemplateClient

func NewTemplateClient(collc CollectionClient, collid string) TemplateClient

NewTemplateClient returns a new template client

type TemplateIterator

type TemplateIterator interface {
	Next(context.Context, int) (*pkg.Templates, error)
	Continuation() string
}

TemplateIterator is a template iterator

type TemplateRawIterator

type TemplateRawIterator interface {
	TemplateIterator
	NextRaw(context.Context, int, interface{}) error
}

TemplateRawIterator is a template raw iterator

func NewFakeTemplateErroringRawIterator

func NewFakeTemplateErroringRawIterator(err error) TemplateRawIterator

NewFakeTemplateErroringRawIterator returns a TemplateRawIterator which whose methods return the given error

func NewFakeTemplateIterator

func NewFakeTemplateIterator(templates []*pkg.Template, continuation int) TemplateRawIterator

type Trigger

type Trigger struct {
	ID               string           `json:"id,omitempty"`
	ResourceID       string           `json:"_rid,omitempty"`
	Timestamp        int              `json:"_ts,omitempty"`
	Self             string           `json:"_self,omitempty"`
	ETag             string           `json:"_etag,omitempty"`
	Body             string           `json:"body,omitempty"`
	TriggerOperation TriggerOperation `json:"triggerOperation,omitempty"`
	TriggerType      TriggerType      `json:"triggerType,omitempty"`
}

Trigger represents a trigger

type TriggerClient

type TriggerClient interface {
	Create(context.Context, *Trigger) (*Trigger, error)
	List() TriggerIterator
	ListAll(context.Context) (*Triggers, error)
	Get(context.Context, string) (*Trigger, error)
	Delete(context.Context, *Trigger) error
	Replace(context.Context, *Trigger) (*Trigger, error)
}

TriggerClient is a trigger client

func NewTriggerClient

func NewTriggerClient(collc CollectionClient, collid string) TriggerClient

NewTriggerClient returns a new trigger client

type TriggerIterator

type TriggerIterator interface {
	Next(context.Context) (*Triggers, error)
}

TriggerIterator is a trigger iterator

type TriggerOperation

type TriggerOperation string

TriggerOperation represents a trigger operation

const (
	TriggerOperationAll     TriggerOperation = "All"
	TriggerOperationCreate  TriggerOperation = "Create"
	TriggerOperationReplace TriggerOperation = "Replace"
	TriggerOperationDelete  TriggerOperation = "Delete"
)

TriggerOperation constants

type TriggerType

type TriggerType string

TriggerType represents a trigger type

const (
	TriggerTypePre  TriggerType = "Pre"
	TriggerTypePost TriggerType = "Post"
)

TriggerType constants

type Triggers

type Triggers struct {
	Count      int        `json:"_count,omitempty"`
	ResourceID string     `json:"_rid,omitempty"`
	Triggers   []*Trigger `json:"Triggers,omitempty"`
}

Triggers represents triggers

type UniqueKey

type UniqueKey struct {
	Paths []string `json:"paths,omitempty"`
}

UniqueKey represents a unique key

type UniqueKeyPolicy

type UniqueKeyPolicy struct {
	UniqueKeys []UniqueKey `json:"uniqueKeys,omitempty"`
}

UniqueKeyPolicy represents a unique key policy

type User

type User struct {
	ID          string `json:"id,omitempty"`
	ResourceID  string `json:"_rid,omitempty"`
	Timestamp   int    `json:"_ts,omitempty"`
	Self        string `json:"_self,omitempty"`
	ETag        string `json:"_etag,omitempty"`
	Permissions string `json:"_permissions,omitempty"`
}

User represents a user

type UserClient

type UserClient interface {
	Create(context.Context, *User) (*User, error)
	List() UserIterator
	ListAll(context.Context) (*Users, error)
	Get(context.Context, string) (*User, error)
	Delete(context.Context, *User) error
	Replace(context.Context, *User) (*User, error)
}

UserClient is a user client

func NewUserClient

func NewUserClient(c DatabaseClient, dbid string) UserClient

NewUserClient returns a new user client

type UserIterator

type UserIterator interface {
	Next(context.Context) (*Users, error)
}

UserIterator is a user iterator

type Users

type Users struct {
	Count      int     `json:"_count,omitempty"`
	ResourceID string  `json:"_rid,omitempty"`
	Users      []*User `json:"Users,omitempty"`
}

Users represents users

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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