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
- Variables
- func DefaultIdentificationHydrator(config *Config, doc interface{})
- type CallOption
- func ChangeFeed() CallOption
- func ChangeFeedPartitionRangeID(id string) CallOption
- func ConsistencyLevel(consistency Consistency) CallOption
- func Continuation(continuation string) CallOption
- func CrossPartition() CallOption
- func IfMatch(etag string) CallOption
- func IfModifiedSince(date string) CallOption
- func IfNoneMatch(etag string) CallOption
- func Limit(limit int) CallOption
- func PartitionKey(partitionKey interface{}) CallOption
- func SessionToken(sessionToken string) CallOption
- func Upsert() CallOption
- type Client
- func (c *Client) Create(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
- func (c *Client) Delete(link string, opts ...CallOption) (*Response, error)
- func (c *Client) Execute(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
- func (c *Client) Query(link string, query *Query, ret interface{}, opts ...CallOption) (*Response, error)
- func (c *Client) Read(link string, ret interface{}, opts ...CallOption) (*Response, error)
- func (c *Client) Replace(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
- func (c *Client) Upsert(link string, body, ret interface{}, opts ...CallOption) (*Response, error)
- type Clienter
- type Collection
- type Collections
- type Config
- type Consistency
- type Database
- type Databases
- type DecoderFactory
- type Document
- type DocumentDB
- func (c *DocumentDB) CreateCollection(db string, body interface{}, opts ...CallOption) (coll *Collection, err error)
- func (c *DocumentDB) CreateDatabase(body interface{}, opts ...CallOption) (db *Database, err error)
- func (c *DocumentDB) CreateDocument(coll string, doc interface{}, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) CreateStoredProcedure(coll string, body interface{}, opts ...CallOption) (sproc *Sproc, err error)
- func (c *DocumentDB) CreateUserDefinedFunction(coll string, body interface{}, opts ...CallOption) (udf *UDF, err error)
- func (c *DocumentDB) DeleteCollection(link string, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) DeleteDatabase(link string, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) DeleteDocument(link string, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) DeleteStoredProcedure(link string, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) DeleteUserDefinedFunction(link string, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) ExecuteStoredProcedure(link string, params, body interface{}, opts ...CallOption) (err error)
- func (c *DocumentDB) QueryCollections(db string, query *Query, opts ...CallOption) (colls []Collection, err error)
- func (c *DocumentDB) QueryDatabases(query *Query, opts ...CallOption) (dbs Databases, err error)
- func (c *DocumentDB) QueryDocuments(coll string, query *Query, docs interface{}, opts ...CallOption) (response *Response, err error)
- func (c *DocumentDB) QueryPartitionKeyRanges(coll string, query *Query, opts ...CallOption) (ranges []PartitionKeyRange, err error)
- func (c *DocumentDB) QueryStoredProcedures(coll string, query *Query, opts ...CallOption) (sprocs []Sproc, err error)
- func (c *DocumentDB) QueryUserDefinedFunctions(coll string, query *Query, opts ...CallOption) (udfs []UDF, err error)
- func (c *DocumentDB) ReadCollection(link string, opts ...CallOption) (coll *Collection, err error)
- func (c *DocumentDB) ReadCollections(db string, opts ...CallOption) (colls []Collection, err error)
- func (c *DocumentDB) ReadDatabase(link string, opts ...CallOption) (db *Database, err error)
- func (c *DocumentDB) ReadDatabases(opts ...CallOption) (dbs []Database, err error)
- func (c *DocumentDB) ReadDocument(link string, doc interface{}, opts ...CallOption) (err error)
- func (c *DocumentDB) ReadDocuments(coll string, docs interface{}, opts ...CallOption) (r *Response, err error)
- func (c *DocumentDB) ReadStoredProcedure(link string, opts ...CallOption) (sproc *Sproc, err error)
- func (c *DocumentDB) ReadStoredProcedures(coll string, opts ...CallOption) (sprocs []Sproc, err error)
- func (c *DocumentDB) ReadUserDefinedFunction(link string, opts ...CallOption) (udf *UDF, err error)
- func (c *DocumentDB) ReadUserDefinedFunctions(coll string, opts ...CallOption) (udfs []UDF, err error)
- func (c *DocumentDB) ReplaceDatabase(link string, body interface{}, opts ...CallOption) (db *Database, err error)
- func (c *DocumentDB) ReplaceDocument(link string, doc interface{}, opts ...CallOption) (*Response, error)
- func (c *DocumentDB) ReplaceStoredProcedure(link string, body interface{}, opts ...CallOption) (sproc *Sproc, err error)
- func (c *DocumentDB) ReplaceUserDefinedFunction(link string, body interface{}, opts ...CallOption) (udf *UDF, err error)
- func (c *DocumentDB) UpsertDocument(coll string, doc interface{}, opts ...CallOption) (*Response, error)
- type EncoderFactory
- type IdentificationHydrator
- type IndexingPolicy
- type Iterator
- type IteratorFunc
- type JSONDecoder
- type JSONEncoder
- type Key
- type Marshal
- type P
- type Parameter
- type PartitionKeyRange
- type Query
- type Request
- type RequestError
- type Resource
- type Response
- type SerializationDriver
- type ServicePrincipalProvider
- type Sproc
- type UDF
- type Unmarshal
Constants ¶
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 ¶
var DefaultSerialization = SerializationDriver{ EncoderFactory: func(b *bytes.Buffer) JSONEncoder { return json.NewEncoder(b) }, DecoderFactory: func(r io.Reader) JSONDecoder { return json.NewDecoder(r) }, Marshal: json.Marshal, Unmarshal: json.Unmarshal, }
DefaultSerialization holds default stdlib json driver
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 ¶
CallOption function
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 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 ¶
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
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 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
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 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 (*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
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 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 Request ¶
Resource Request
func ResourceRequest ¶
Return new resource request with type and id
func (*Request) DefaultHeaders ¶
Add 3 default headers to *Request "x-ms-date", "x-ms-version", "authorization"
func (*Request) QueryHeaders ¶
Add headers for query request
type RequestError ¶
Request Error
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 ¶
func (*Response) Continuation ¶
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