cosmosdb

package
v4.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldPartitionKeys = "partition_keys_map"
)

Variables

View Source
var BatchingDocs = `` /* 210-byte string literal not displayed */

BatchingDocs batching docs

View Source
var CRUDLintRules = `
let hasItemID = this.item_id.or("") != ""
let hasPatchOperations = this.patch_operations.length().or(0) > 0
let hasPatchCondition = this.patch_condition.or("") != ""

root."-" = if !$hasItemID && (this.operation == "Replace" || this.operation == "Delete" || this.operation == "Read" || this.operation == "Patch") {
  "The ` + "`item_id`" + ` field must be set for Replace, Delete, Read and Patch operations."
}

root."-" = if this.operation == "Patch" && !$hasPatchOperations {
  "At least one ` + "`patch_operations`" + ` must be set when ` + "`operation: Patch`" + `."
}

root."-" = if $hasPatchCondition && (!$hasPatchOperations || this.operation != "Patch") {
  "The ` + "`patch_condition` " + ` field only applies to ` + "`Patch`" + ` operations and it requires one or more ` + "`patch_operations`" + `."
}

root."-" = if this.operation == "Patch" && this.patch_operations.any(o -> o.operation != "Remove" && o.value_map.or("") == "") {
  "The ` + "`patch_operations` " + "`value_map`" + ` field must be set when ` + "`operation`" + ` is not ` + "`Remove`" + `."
}

root."-" = if this.operation == "Patch" && this.patch_operations.any(o -> o.operation == "Remove" && o.value_map.or("") != "") {
  "The ` + "`patch_operations` " + "`value_map`" + ` field must not be set when ` + "`operation`" + ` is ` + "`Remove`" + `."
}
`

CRUDLintRules contains the lint rules for CRUD fields

View Source
var CommonLintRules = `
let hasEndpoint = this.endpoint.or("") != ""
let hasConnectionString = this.connection_string.or("") != ""

root."-" = if !$hasEndpoint && !$hasConnectionString {
  "Either ` + "`endpoint`" + ` or ` + "`connection_string`" + ` must be set."
}
`

CommonLintRules contains the lint rules for common fields

View Source
var CredentialsDocs = `

## Credentials

You can use one of the following authentication mechanisms:

- Set the ` + "`endpoint`" + ` field and the ` + "`account_key`" + ` field
- Set only the ` + "`endpoint`" + ` field to use [DefaultAzureCredential](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#DefaultAzureCredential)
- Set the ` + "`connection_string`" + ` field
`

CredentialsDocs credentials docs

View Source
var EmulatorDocs = `

## CosmosDB Emulator

If you wish to run the CosmosDB emulator that is referenced in the documentation [here](https://learn.microsoft.com/en-us/azure/cosmos-db/linux-emulator), the following Docker command should do the trick:

` + "```shell" + `
> docker run --rm -it -p 8081:8081 --name=cosmosdb -e AZURE_COSMOS_EMULATOR_PARTITION_COUNT=10 -e AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE=false mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
` + "```" + `

Note: ` + "`AZURE_COSMOS_EMULATOR_PARTITION_COUNT`" + ` controls the number of partitions that will be supported by the emulator. The bigger the value, the longer it takes for the container to start up.

Additionally, instead of installing the container self-signed certificate which is exposed via ` + "`https://localhost:8081/_explorer/emulator.pem`" + `, you can run [mitmproxy](https://mitmproxy.org/) like so:

` + "```shell" + `
> mitmproxy -k --mode "reverse:https://localhost:8081"
` + "```" + `

Then you can access the CosmosDB UI via ` + "`http://localhost:8080/_explorer/index.html`" + ` and use ` + "`http://localhost:8080`" + ` as the CosmosDB endpoint.
`

EmulatorDocs emulator docs

View Source
var MetadataDocs = `

## Metadata

This component adds the following metadata fields to each message:
` + "```" + `
- activity_id
- request_charge
` + "```" + `

You can access these metadata fields using [function interpolation](/docs/configuration/interpolation#bloblang-queries).
`

MetadataDocs metadata docs

Functions

func CRUDFields

func CRUDFields(hasReadOperation bool) []*service.ConfigField

CRUDFields returns the CRUD field definitions

func ContainerClientConfigFields

func ContainerClientConfigFields() []*service.ConfigField

ContainerClientConfigFields returns the container client config fields

func ContainerClientFromParsed

func ContainerClientFromParsed(conf *service.ParsedConfig) (*azcosmos.ContainerClient, error)

ContainerClientFromParsed creates the container client from a parsed config

func ExecMessageBatch

func ExecMessageBatch(ctx context.Context, batch service.MessageBatch, client *azcosmos.ContainerClient,
	config CRUDConfig, enableContentResponseOnWrite bool,
) (azcosmos.TransactionalBatchResponse, error)

ExecMessageBatch creates a CosmosDB TransactionalBatch from the provided message batch and executes it

func GetTypedPartitionKeyValue

func GetTypedPartitionKeyValue(pkValue any) (azcosmos.PartitionKey, error)

GetTypedPartitionKeyValue returns a typed partition key value

func PartitionKeysField

func PartitionKeysField(isInputField bool) *service.ConfigField

PartitionKeysField returns the partition keys field definition

Types

type CRUDConfig

type CRUDConfig struct {
	PartitionKeys   *bloblang.Executor
	Operation       OperationType
	AutoID          bool
	ItemID          *service.InterpolatedString
	PatchCondition  *service.InterpolatedString
	PatchOperations []patchOperation
}

CRUDConfig contains the configuration fields required for CRUD operations

func CRUDConfigFromParsed

func CRUDConfigFromParsed(conf *service.ParsedConfig) (CRUDConfig, error)

CRUDConfigFromParsed extracts the CRUD config from the parsed config

type OperationType

type OperationType string

OperationType operation type

const (
	// OperationCreate Create operation
	OperationCreate OperationType = "Create"
	// OperationDelete Delete operation
	OperationDelete OperationType = "Delete"
	// OperationReplace Replace operation
	OperationReplace OperationType = "Replace"
	// OperationUpsert Upsert operation
	OperationUpsert OperationType = "Upsert"
	// OperationRead Read operation
	OperationRead OperationType = "Read"
	// OperationPatch Patch operation
	OperationPatch OperationType = "Patch"
)

Jump to

Keyboard shortcuts

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