documentdb

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 17 Imported by: 7

README

DocumentDB Go Build status

Go driver for Microsoft Azure DocumentDB

Table of contents:

Get Started

Installation
$ go get github.com/a8m/documentdb
Add to your project
import (
	"github.com/a8m/documentdb"
)

func main() {
	config := documentdb.NewConfig(&documentdb.Key{
		Key: "master-key",
	})
	client := documentdb.New("connection-url", config)

	// Start using DocumentDB
	dbs, err := client.ReadDatabases()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(dbs)
}

Databases

ReadDatabase
func main() {
	// ...
	db, err := client.ReadDatabase("self_link")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(db.Self, db.Id)
}
QueryDatabases
func main() {
	// ...
	dbs, err := client.QueryDatabases("SELECT * FROM ROOT r")
	if err != nil {
		log.Fatal(err)
	}
	for _, db := range dbs {
		fmt.Println("DB Name:", db.Id)
	}
}
ReadDatabases
func main() {
	// ...
	dbs, err := client.ReadDatabases()
	if err != nil {
		log.Fatal(err)
	}
	for _, db := range dbs {
		fmt.Println("DB Name:", db.Id)
	}
}
CreateDatabase
func main() {
	// ...
	db, err := client.CreateDatabase(`{ "id": "test" }`)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(db)

	// or ...
	var db documentdb.Database
	db.Id = "test"
	db, err = client.CreateDatabase(&db)
}
ReplaceDatabase
func main() {
	// ...
	db, err := client.ReplaceDatabase("self_link", `{ "id": "test" }`)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(db)

	// or ...
	var db documentdb.Database
	db, err = client.ReplaceDatabase("self_link", &db)
}
DeleteDatabase
func main() {
	// ...
	err := client.DeleteDatabase("self_link")
	if err != nil {
		log.Fatal(err)
	}
}

Collections

ReadCollection
func main() {
	// ...
	coll, err := client.ReadCollection("self_link")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(coll.Self, coll.Id)
}
QueryCollections
func main() {
	// ...
	colls, err := client.QueryCollections("db_self_link", "SELECT * FROM ROOT r")
	if err != nil {
		log.Fatal(err)
	}
	for _, coll := range colls {
		fmt.Println("Collection Name:", coll.Id)
	}
}
ReadCollections
func main() {
	// ...
	colls, err := client.ReadCollections("db_self_link")
	if err != nil {
		log.Fatal(err)
	}
	for _, coll := range colls {
		fmt.Println("Collection Name:", coll.Id)
	}
}
CreateCollection
func main() {
	// ...
	coll, err := client.CreateCollection("db_self_link", `{"id": "my_test"}`)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Collection Name:", coll.Id)

	// or ...
	var coll documentdb.Collection
	coll.Id = "test"
	coll, err = client.CreateCollection("db_self_link", &coll)
}
DeleteCollection
func main() {
	// ...
	err := client.DeleteCollection("self_link")
	if err != nil {
		log.Fatal(err)
	}
}

Documents

ReadDocument
type Document struct {
	documentdb.Document
	// Your external fields
	Name    string `json:"name,omitempty"`
	Email   string `json:"email,omitempty"`
}

func main() {
	// ...
	var doc Document
	err = client.ReadDocument("self_link", &doc)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Document Name:", doc.Name)
}
QueryDocuments
type User struct {
	documentdb.Document
	// Your external fields
	Name    string `json:"name,omitempty"`
	Email   string `json:"email,omitempty"`
}

func main() {
	// ...
	var users []User
	_, err = client.QueryDocuments(
        "coll_self_link", 
        documentdb.NewQuery("SELECT * FROM ROOT r WHERE r.name=@name", documentdb.P{"@name", "john"}),
        &users,
    )
	if err != nil {
		log.Fatal(err)
	}
	for _, user := range users {
		fmt.Print("Name:", user.Name, "Email:", user.Email)
	}
}
QueryDocuments with partition key
type User struct {
	documentdb.Document
	// Your external fields
	Name    string `json:"name,omitempty"`
	Email   string `json:"email,omitempty"`
}

func main() {
	// ...
	var users []User
	_, err = client.QueryDocuments(
        "coll_self_link", 
		documentdb.NewQuery(
			"SELECT * FROM ROOT r WHERE r.name=@name AND r.company_id = @company_id", 
			documentdb.P{"@name", "john"}, 
			documentdb.P{"@company_id", "1234"},
		),
		&users,
		documentdb.PartitionKey("1234")
    )
	if err != nil {
		log.Fatal(err)
	}
	for _, user := range users {
		fmt.Print("Name:", user.Name, "Email:", user.Email)
	}
}
ReadDocuments
type User struct {
	documentdb.Document
	// Your external fields
	Name    string `json:"name,omitempty"`
	Email   string `json:"email,omitempty"`
}

func main() {
	// ...
	var users []User
	err = client.ReadDocuments("coll_self_link", &users)
	if err != nil {
		log.Fatal(err)
	}
	for _, user := range users {
		fmt.Print("Name:", user.Name, "Email:", user.Email)
	}
}
CreateDocument
type User struct {
	documentdb.Document
	// Your external fields
	Name    string `json:"name,omitempty"`
	Email   string `json:"email,omitempty"`
}

func main() {
	// ...
	var user User
	// Note: If the `id` is missing(or empty) in the payload it will generate
	// random document id(i.e: uuid4)
	user.Id = "uuid"
	user.Name = "Ariel"
	user.Email = "ariel@test.com"
	err := client.CreateDocument("coll_self_link", &doc)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print("Name:", user.Name, "Email:", user.Email)
}
ReplaceDocument
type User struct {
	documentdb.Document
	// Your external fields
	IsAdmin bool   `json:"isAdmin,omitempty"`
}

func main() {
	// ...
	var user User
	user.Id = "uuid"
	user.IsAdmin = false
	err := client.ReplaceDocument("doc_self_link", &user)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Print("Is Admin:", user.IsAdmin)
}
DeleteDocument
func main() {
	// ...
	err := client.DeleteDocument("doc_self_link")
	if err != nil {
		log.Fatal(err)
	}
}

ExecuteStoredProcedure
func main() {
	// ...
	var docs []Document
	err := client.ExecuteStoredProcedure("sporc_self", [...]interface{}{p1, p2}, &docs)
	if err != nil {
		log.Fatal(err)
	}
	// ...
}

Iterator

DocumentIterator
func main() {
	// ...
	var docs []Document

	iterator := documentdb.NewIterator(
		client, documentdb.NewDocumentIterator("coll_self_link", nil, &docs, documentdb.PartitionKey("1"), documentdb.Limit(1)),
	)

	for iterator.Next() {
		if err := iterator.Error(); err != nil {
			log.Fatal(err)
		}
		fmt.Println(len(docs))
	}    

	// ...
}

Authentication with Azure AD

You can authenticate with Cosmos DB using Azure AD and a service principal, including full RBAC support. To configure Cosmos DB to use Azure AD, take a look at the Cosmos DB documentation.

To use this library with a service principal:

import (
	"github.com/Azure/go-autorest/autorest/adal"
	"github.com/a8m/documentdb"
)

func main() {
	// Azure AD application (service principal) client credentials
	tenantId := "tenant-id"
	clientId := "client-id"
	clientSecret := "client-secret"

	// Azure AD endpoint may be different for sovereign clouds
	oauthConfig, err := adal.NewOAuthConfig("https://login.microsoftonline.com/", tenantId)
	if err != nil {
		log.Fatal(err)
	}
	spt, err := adal.NewServicePrincipalToken(*oauthConfig, clientId, clientSecret, "https://cosmos.azure.com") // Always "https://cosmos.azure.com"
	if err != nil {
		log.Fatal(err)
	}

	config := documentdb.NewConfigWithServicePrincipal(spt)
	client := documentdb.New("connection-url", config)
}

Examples

License

Distributed under the MIT license, which is available in the file LICENSE.

Documentation

Overview

This project start as a fork of `github.com/nerdylikeme/go-documentdb` version but changed, and may be changed later

Goal: add the full functionality of documentdb, align with the other sdks and make it more testable

Index

Constants

View Source
const (
	HeaderXDate               = "X-Ms-Date"
	HeaderAuth                = "Authorization"
	HeaderVersion             = "X-Ms-Version"
	HeaderContentType         = "Content-Type"
	HeaderContentLength       = "Content-Length"
	HeaderIsQuery             = "X-Ms-Documentdb-Isquery"
	HeaderUpsert              = "x-ms-documentdb-is-upsert"
	HeaderPartitionKey        = "x-ms-documentdb-partitionkey"
	HeaderMaxItemCount        = "x-ms-max-item-count"
	HeaderContinuation        = "x-ms-continuation"
	HeaderConsistency         = "x-ms-consistency-level"
	HeaderSessionToken        = "x-ms-session-token"
	HeaderCrossPartition      = "x-ms-documentdb-query-enablecrosspartition"
	HeaderIfMatch             = "If-Match"
	HeaderIfNonMatch          = "If-None-Match"
	HeaderIfModifiedSince     = "If-Modified-Since"
	HeaderActivityID          = "x-ms-activity-id"
	HeaderRequestCharge       = "x-ms-request-charge"
	HeaderAIM                 = "A-IM"
	HeaderPartitionKeyRangeID = "x-ms-documentdb-partitionkeyrangeid"

	SupportedVersion = "2017-02-22"
)

Variables

DefaultSerialization holds default stdlib json driver

View Source
var Serialization = DefaultSerialization

Serialization holds driver that is actually used

Functions

func DefaultIdentificationHydrator

func DefaultIdentificationHydrator(config *Config, doc interface{})

DefaultIdentificationHydrator fills Id

Types

type CallOption

type CallOption func(r *Request) error

CallOption function

func ChangeFeed

func ChangeFeed() CallOption

ChangeFeed indicates a change feed request

func ChangeFeedPartitionRangeID

func ChangeFeedPartitionRangeID(id string) CallOption

ChangeFeedPartitionRangeID used in change feed requests. The partition key range ID for reading data.

func ConsistencyLevel

func ConsistencyLevel(consistency Consistency) CallOption

ConsistencyLevel override for read options against documents and attachments. The valid values are: Strong, Bounded, Session, or Eventual (in order of strongest to weakest). The override must be the same or weaker than the account�s configured consistency level.

func Continuation

func Continuation(continuation string) CallOption

Continuation a string token returned for queries and read-feed operations if there are more results to be read. Clients can retrieve the next page of results by resubmitting the request with the x-ms-continuation request header set to this value.

func CrossPartition

func CrossPartition() CallOption

CrossPartition allows query to run on all partitions

func IfMatch

func IfMatch(etag string) CallOption

IfMatch used to make operation conditional for optimistic concurrency. The value should be the etag value of the resource. (applicable only on PUT and DELETE)

func IfModifiedSince

func IfModifiedSince(date string) CallOption

IfModifiedSince returns etag of resource modified after specified date in RFC 1123 format. Ignored when If-None-Match is specified Optional (applicable only on GET)

func IfNoneMatch

func IfNoneMatch(etag string) CallOption

IfNoneMatch makes operation conditional to only execute if the resource has changed. The value should be the etag of the resource. Optional (applicable only on GET)

func Limit

func Limit(limit int) CallOption

Limit set max item count for response

func PartitionKey

func PartitionKey(partitionKey interface{}) CallOption

PartitionKey specificy which partiotion will be used to satisfty the request

func SessionToken

func SessionToken(sessionToken string) CallOption

SessionToken a string token used with session level consistency. For more information, see

func Upsert

func Upsert() CallOption

Upsert if set to true, Cosmos DB creates the document with the ID (and partition key value if applicable) if it doesn’t exist, or update the document if it exists.

type Client

type Client struct {
	Url    string
	Config *Config
	http.Client
}

func (*Client) Create

func (c *Client) Create(link string, body, ret interface{}, opts ...CallOption) (*Response, error)

Create resource

func (*Client) Delete

func (c *Client) Delete(link string, opts ...CallOption) (*Response, error)

Delete resource by self link

func (*Client) Execute

func (c *Client) Execute(link string, body, ret interface{}, opts ...CallOption) (*Response, error)

Replace resource TODO: DRY, move to methods instead of actions(POST, PUT, ...)

func (*Client) Query

func (c *Client) Query(link string, query *Query, ret interface{}, opts ...CallOption) (*Response, error)

Query resource

func (*Client) Read

func (c *Client) Read(link string, ret interface{}, opts ...CallOption) (*Response, error)

Read resource by self link

func (*Client) Replace

func (c *Client) Replace(link string, body, ret interface{}, opts ...CallOption) (*Response, error)

Replace resource

func (*Client) Upsert

func (c *Client) Upsert(link string, body, ret interface{}, opts ...CallOption) (*Response, error)

Upsert resource

type Clienter

type Clienter interface {
	Read(link string, ret interface{}, opts ...CallOption) (*Response, error)
	Delete(link string, opts ...CallOption) (*Response, error)
	Query(link string, query *Query, ret interface{}, opts ...CallOption) (*Response, error)
	Create(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
	Upsert(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
	Replace(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
	Execute(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
}

type Collection

type Collection struct {
	Resource
	IndexingPolicy IndexingPolicy `json:"indexingPolicy,omitempty"`
	Docs           string         `json:"_docs,omitempty"`
	Udf            string         `json:"_udfs,omitempty"`
	Sporcs         string         `json:"_sporcs,omitempty"`
	Triggers       string         `json:"_triggers,omitempty"`
	Conflicts      string         `json:"_conflicts,omitempty"`
}

Collection

type Collections

type Collections []Collection

Collection slice of Collection elements

func (Collections) First

func (c Collections) First() *Collection

First returns first database in slice

type Config

type Config struct {
	MasterKey                  *Key
	ServicePrincipal           ServicePrincipalProvider
	Client                     http.Client
	IdentificationHydrator     IdentificationHydrator
	IdentificationPropertyName string
}

func NewConfig

func NewConfig(key *Key) *Config

func NewConfigWithServicePrincipal added in v1.3.0

func NewConfigWithServicePrincipal(servicePrincipal ServicePrincipalProvider) *Config

NewConfigWithServicePrincipal creates a new Config object that uses Azure AD (via a service principal) for authentication

func (*Config) WithClient

func (c *Config) WithClient(client http.Client) *Config

WithClient stores given http client for later use by documentdb client.

type Consistency

type Consistency string

Consistency type to define consistency levels

const (
	// Strong consistency level
	Strong Consistency = "Strong"

	// Bounded consistency level
	Bounded Consistency = "Bounded"

	// Session consistency level
	Session Consistency = "Session"

	// Eventual consistency level
	Eventual Consistency = "Eventual"
)

type Database

type Database struct {
	Resource
	Colls string `json:"_colls,omitempty"`
	Users string `json:"_users,omitempty"`
}

Database

type Databases

type Databases []Database

Databases slice of Database elements

func (Databases) First

func (d Databases) First() *Database

First returns first database in slice

type DecoderFactory

type DecoderFactory func(io.Reader) JSONDecoder

DecoderFactory describes function that creates json decoder

type Document

type Document struct {
	Resource
	// contains filtered or unexported fields
}

Document

type DocumentDB

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

func New

func New(url string, config *Config) *DocumentDB

New creates DocumentDBClient

func (*DocumentDB) CreateCollection

func (c *DocumentDB) CreateCollection(db string, body interface{}, opts ...CallOption) (coll *Collection, err error)

Create collection

func (*DocumentDB) CreateDatabase

func (c *DocumentDB) CreateDatabase(body interface{}, opts ...CallOption) (db *Database, err error)

Create database

func (*DocumentDB) CreateDocument

func (c *DocumentDB) CreateDocument(coll string, doc interface{}, opts ...CallOption) (*Response, error)

Create document

func (*DocumentDB) CreateStoredProcedure

func (c *DocumentDB) CreateStoredProcedure(coll string, body interface{}, opts ...CallOption) (sproc *Sproc, err error)

Create stored procedure

func (*DocumentDB) CreateUserDefinedFunction

func (c *DocumentDB) CreateUserDefinedFunction(coll string, body interface{}, opts ...CallOption) (udf *UDF, err error)

Create user defined function

func (*DocumentDB) DeleteCollection

func (c *DocumentDB) DeleteCollection(link string, opts ...CallOption) (*Response, error)

Delete collection

func (*DocumentDB) DeleteDatabase

func (c *DocumentDB) DeleteDatabase(link string, opts ...CallOption) (*Response, error)

TODO: DRY, but the sdk want that[mm.. maybe just client.Delete(self_link)] Delete database

func (*DocumentDB) DeleteDocument

func (c *DocumentDB) DeleteDocument(link string, opts ...CallOption) (*Response, error)

Delete document

func (*DocumentDB) DeleteStoredProcedure

func (c *DocumentDB) DeleteStoredProcedure(link string, opts ...CallOption) (*Response, error)

Delete stored procedure

func (*DocumentDB) DeleteUserDefinedFunction

func (c *DocumentDB) DeleteUserDefinedFunction(link string, opts ...CallOption) (*Response, error)

Delete user defined function

func (*DocumentDB) ExecuteStoredProcedure

func (c *DocumentDB) ExecuteStoredProcedure(link string, params, body interface{}, opts ...CallOption) (err error)

Execute stored procedure

func (*DocumentDB) QueryCollections

func (c *DocumentDB) QueryCollections(db string, query *Query, opts ...CallOption) (colls []Collection, err error)

Read all db-collection that satisfy a query

func (*DocumentDB) QueryDatabases

func (c *DocumentDB) QueryDatabases(query *Query, opts ...CallOption) (dbs Databases, err error)

Read all databases that satisfy a query

func (*DocumentDB) QueryDocuments

func (c *DocumentDB) QueryDocuments(coll string, query *Query, docs interface{}, opts ...CallOption) (response *Response, err error)

Read all documents in a collection that satisfy a query

func (*DocumentDB) QueryPartitionKeyRanges

func (c *DocumentDB) QueryPartitionKeyRanges(coll string, query *Query, opts ...CallOption) (ranges []PartitionKeyRange, err error)

Read collection's partition ranges

func (*DocumentDB) QueryStoredProcedures

func (c *DocumentDB) QueryStoredProcedures(coll string, query *Query, opts ...CallOption) (sprocs []Sproc, err error)

Read all collection `sprocs` that satisfy a query

func (*DocumentDB) QueryUserDefinedFunctions

func (c *DocumentDB) QueryUserDefinedFunctions(coll string, query *Query, opts ...CallOption) (udfs []UDF, err error)

Read all collection `udfs` that satisfy a query

func (*DocumentDB) ReadCollection

func (c *DocumentDB) ReadCollection(link string, opts ...CallOption) (coll *Collection, err error)

Read collection by self link

func (*DocumentDB) ReadCollections

func (c *DocumentDB) ReadCollections(db string, opts ...CallOption) (colls []Collection, err error)

Read all collections by db selflink

func (*DocumentDB) ReadDatabase

func (c *DocumentDB) ReadDatabase(link string, opts ...CallOption) (db *Database, err error)

TODO: Add `requestOptions` arguments Read database by self link

func (*DocumentDB) ReadDatabases

func (c *DocumentDB) ReadDatabases(opts ...CallOption) (dbs []Database, err error)

Read all databases

func (*DocumentDB) ReadDocument

func (c *DocumentDB) ReadDocument(link string, doc interface{}, opts ...CallOption) (err error)

Read document by self link

func (*DocumentDB) ReadDocuments

func (c *DocumentDB) ReadDocuments(coll string, docs interface{}, opts ...CallOption) (r *Response, err error)

Read all collection documents by self link TODO: use iterator for heavy transactions

func (*DocumentDB) ReadStoredProcedure

func (c *DocumentDB) ReadStoredProcedure(link string, opts ...CallOption) (sproc *Sproc, err error)

Read sporc by self link

func (*DocumentDB) ReadStoredProcedures

func (c *DocumentDB) ReadStoredProcedures(coll string, opts ...CallOption) (sprocs []Sproc, err error)

Read all sprocs by collection self link

func (*DocumentDB) ReadUserDefinedFunction

func (c *DocumentDB) ReadUserDefinedFunction(link string, opts ...CallOption) (udf *UDF, err error)

Read udf by self link

func (*DocumentDB) ReadUserDefinedFunctions

func (c *DocumentDB) ReadUserDefinedFunctions(coll string, opts ...CallOption) (udfs []UDF, err error)

Read pall udfs by collection self link

func (*DocumentDB) ReplaceDatabase

func (c *DocumentDB) ReplaceDatabase(link string, body interface{}, opts ...CallOption) (db *Database, err error)

Replace database

func (*DocumentDB) ReplaceDocument

func (c *DocumentDB) ReplaceDocument(link string, doc interface{}, opts ...CallOption) (*Response, error)

Replace document

func (*DocumentDB) ReplaceStoredProcedure

func (c *DocumentDB) ReplaceStoredProcedure(link string, body interface{}, opts ...CallOption) (sproc *Sproc, err error)

Replace stored procedure

func (*DocumentDB) ReplaceUserDefinedFunction

func (c *DocumentDB) ReplaceUserDefinedFunction(link string, body interface{}, opts ...CallOption) (udf *UDF, err error)

Replace stored procedure

func (*DocumentDB) UpsertDocument

func (c *DocumentDB) UpsertDocument(coll string, doc interface{}, opts ...CallOption) (*Response, error)

Upsert document

type EncoderFactory

type EncoderFactory func(*bytes.Buffer) JSONEncoder

EncoderFactory describes function that creates json encoder

type IdentificationHydrator

type IdentificationHydrator func(config *Config, doc interface{})

IdentificationHydrator defines interface for ID hydrators that can prepopulate struct with default values

type IndexingPolicy

type IndexingPolicy struct {
	IndexingMode string `json: "indexingMode,omitempty"`
	Automatic    bool   `json: "automatic,omitempty"`
}

Indexing policy TODO: Ex/IncludePaths

type Iterator

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

Iterator allows easily fetch multiple result sets when response max item limit is reacheds

func NewIterator

func NewIterator(db *DocumentDB, source IteratorFunc) *Iterator

NewIterator creates iterator instance

func (*Iterator) Error

func (di *Iterator) Error() error

Errror returns error from last call

func (*Iterator) Next

func (di *Iterator) Next() bool

Next will ask iterator source for results and checks whenever there some more pages left

func (*Iterator) Response

func (di *Iterator) Response() *Response

Response returns *Response object from last call

type IteratorFunc

type IteratorFunc func(db *DocumentDB, internalOpts ...CallOption) (*Response, error)

IteratorFunc is type that describes iterator source

func NewDocumentIterator

func NewDocumentIterator(coll string, query *Query, docs interface{}, opts ...CallOption) IteratorFunc

NewDocumentIterator creates iterator source for fetching documents

type JSONDecoder

type JSONDecoder interface {
	Decode(obj interface{}) error
}

JSONDecoder describes json decoder

type JSONEncoder

type JSONEncoder interface {
	Encode(val interface{}) error
}

JSONEncoder describes json encoder

type Key

type Key struct {
	Key string
	// contains filtered or unexported fields
}

func NewKey

func NewKey(key string) *Key

func (*Key) Salt

func (k *Key) Salt() ([]byte, error)

type Marshal

type Marshal func(v interface{}) ([]byte, error)

Marshal function type

type P

type P = Parameter

type Parameter

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

type PartitionKeyRange

type PartitionKeyRange struct {
	Resource
	PartitionKeyRangeID string `json:"id,omitempty"`
	MinInclusive        string `json:"minInclusive,omitempty"`
	MaxInclusive        string `json:"maxExclusive,omitempty"`
}

PartitionKeyRange partition key range model

type Query

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

func NewQuery

func NewQuery(query string, parameters ...Parameter) *Query

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

Resource Request

func ResourceRequest

func ResourceRequest(link string, req *http.Request) *Request

Return new resource request with type and id

func (*Request) DefaultHeaders

func (req *Request) DefaultHeaders(config *Config) (err error)

Add 3 default headers to *Request "x-ms-date", "x-ms-version", "authorization"

func (*Request) QueryHeaders

func (req *Request) QueryHeaders(len int)

Add headers for query request

type RequestError

type RequestError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

Request Error

func (RequestError) Error

func (e RequestError) Error() string

Implement Error function

type Resource

type Resource struct {
	Id   string `json:"id,omitempty"`
	Self string `json:"_self,omitempty"`
	Etag string `json:"_etag,omitempty"`
	Rid  string `json:"_rid,omitempty"`
	Ts   int    `json:"_ts,omitempty"`
}

Resource

type Response

type Response struct {
	Header http.Header
}

func (*Response) Continuation

func (r *Response) Continuation() string

Continuation returns continuation token for paged request. Pass this value to next request to get next page of documents.

type SerializationDriver

type SerializationDriver struct {
	EncoderFactory EncoderFactory
	DecoderFactory DecoderFactory
	Marshal        Marshal
	Unmarshal      Unmarshal
}

SerializationDriver struct holds serialization / deserilization providers

type ServicePrincipalProvider added in v1.3.0

type ServicePrincipalProvider interface {
	// EnsureFresh will refresh the token if it will expire within the refresh window. This method is safe for concurrent use.
	EnsureFresh() error
	// OAuthToken returns the current access token.
	OAuthToken() string
}

ServicePrincipalProvider is an interface for an object that provides an Azure service principal It's normally used with *adal.ServicePrincipalToken objects from github.com/Azure/go-autorest/autorest/adal

type Sproc

type Sproc struct {
	Resource
	Body string `json:"body,omitempty"`
}

Stored Procedure

type UDF

type UDF struct {
	Resource
	Body string `json:"body,omitempty"`
}

User Defined Function

type Unmarshal

type Unmarshal func(data []byte, v interface{}) error

Unmarshal function type

Directories

Path Synopsis
interface

Jump to

Keyboard shortcuts

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