go-cosmosdb

module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT

README

go-cosmosdb Build Status

go sdk for Azure Cosmos DB

Usage

  • instantiate a config struct. Set the keys, url and some other parameters.

  • call the constructor New(cfg config)

  • cosmosdb follows the hierarchy of Cosmos DB. This means that you can operate on the resource the current type represents. The database struct can work with resources that belong to a cosmos database, the Collection type can work with resources that belong to a collection.

  • doc interface{} may seem weird in some contexts, e.g. DeleteDocument, why not use a signature like DeleteDocument(ctx context.Context, id string). The reason is that there are several ways to address the document. Either by self link, with or without _etag or by the id. All on collections with or without a partition key.

    • use _self if possible
    • if _etag is present, use it
    • otherwise use id
    • if neither exists -> error

Examples

Create Document

type Document struct {
    id string
}

newDoc, err := coll.CreateDocument(context.Background(), doc)

#FAQ

Directories

Path Synopsis
cmd
The cosmos package implements a higher-level opinionated interface to Cosmos.
The cosmos package implements a higher-level opinionated interface to Cosmos.
The cosmostest package contains utilities for writing tests with cosmos, using a real database or the emulator as a backend, and with the option of multiple tests running side by side in multiple namespaces in a single collection to save costs.
The cosmostest package contains utilities for writing tests with cosmos, using a real database or the emulator as a backend, and with the option of multiple tests running side by side in multiple namespaces in a single collection to save costs.
examples

Jump to

Keyboard shortcuts

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