cosmos

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: BSD-2-Clause Imports: 6 Imported by: 7

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"

	"github.com/chiyoi/az/identity"
	"github.com/chiyoi/iter/res"
)

const (
	EndpointCosmos = "https://neko03cosmos.documents.azure.com:443/"
)

func main() {
	// Point CRUD example.
	cred, err := identity.DefaultCredential()
	client, err := res.R(cred, err, NewClient(EndpointCosmos, nil))
	if err != nil {
		panic(err)
	}
	c, err := client.NewContainer("neko0001", "point_test")
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	var neko, neko1 string

	exist, err := PointExist(ctx, "neko")(c)
	if err != nil {
		panic(err)
	}

	if exist {
		err = PointRead(ctx, "neko", &neko1)(c)
		if err != nil {
			panic(err)
		}

		err = PointUpsert(ctx, "neko", "nyan")(c)
		if err != nil {
			panic(err)
		}

		err = PointRead(ctx, "neko", &neko)(c)
		if err != nil {
			panic(err)
		}

		err = PointDelete(ctx, "neko")(c)
		if err != nil {
			panic(err)
		}
	} else {
		err = PointUpsert(ctx, "neko", "nyan")(c)
		if err != nil {
			panic(err)
		}

		err = PointRead(ctx, "neko", &neko)(c)
		if err != nil {
			panic(err)
		}

		err = PointUpsert(ctx, "neko", "nyan1")(c)
		if err != nil {
			panic(err)
		}

		err = PointRead(ctx, "neko", &neko1)(c)
		if err != nil {
			panic(err)
		}
	}

	fmt.Println(neko)
	fmt.Println(neko1)
}
Output:

nyan
nyan1

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoMoreItems = errors.New("no more items")

Functions

func CreateItem

func CreateItem(ctx context.Context, client *azcosmos.ContainerClient, partitionKey azcosmos.PartitionKey, item any) (err error)

func Exist added in v0.9.5

func Exist(ctx context.Context, client *azcosmos.ContainerClient, partitionKey azcosmos.PartitionKey, itemID string) (exist bool, err error)

func IsNoMoreItems

func IsNoMoreItems(err error) bool

func NewClient added in v0.9.4

func NewClient(endpoint string, o *azcosmos.ClientOptions) func(cred azcore.TokenCredential) (*azcosmos.Client, error)

func PointDelete

func PointDelete(ctx context.Context, key string) func(client *azcosmos.ContainerClient) (err error)

func PointExist added in v0.9.5

func PointExist(ctx context.Context, key string) func(client *azcosmos.ContainerClient) (exist bool, err error)

func PointRead

func PointRead(ctx context.Context, key string, value any) func(client *azcosmos.ContainerClient) (err error)

func PointUpsert added in v0.9.7

func PointUpsert(ctx context.Context, key string, value any) func(client *azcosmos.ContainerClient) (err error)

func Query

func Query(client *azcosmos.ContainerClient, partitionKey azcosmos.PartitionKey, query string) (next func(ctx context.Context, v any) (err error))

Types

type Schema added in v0.9.2

type Schema struct {
	PartitionKeyPath string
	TimeToLiveOn     bool
	TimeToLive       int32
}

Jump to

Keyboard shortcuts

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