jcosmos

package module
v0.0.0-...-7bc148f Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

JCOSMOS

Go Reference A simple easy to use cosmos db library.

We Support hierachical Namespaces!

Though Microsoft has not documented this feature, we have added it, ensuring compatibility with the latest cosmos DB endpoints

Does not support

Currently Jcosmos is in the process of being written and only features basic operations, all documented endpoints will be included with exceptions listed below

exceptions

  • predefined S1, S2, S3 performance levels
  • Resource Provider (will be added in the future, this requires azure auth token)

Tests

Currently all methods have been tested manually, tests will be written shortly and are greatly welcomed to be contributed.

Documentation

Index

Constants

View Source
const (
	CosmosDBSimulatorKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
	JcosmosVersion       = "0.0.2"
)
View Source
const (
	LogLevelTrace loglevel = 5
	LogLevelDebug loglevel = 4
	LogLevelInfo  loglevel = 3
	LogLevelWarn  loglevel = 2
	LogLevelError loglevel = 1
	LogLevelNone  loglevel = 0
)
View Source
const (
	TriggerTypePre  = "Pre"
	TriggerTypePost = "Post"

	TriggerOperationAll     = "All"
	TriggerOperationCreate  = "Create"
	TriggerOperationReplace = "Replace"
	TriggerOperationDelete  = "Delete"
)
View Source
const (
	ErrorDatabaseIDTooLong = "database id is toolong, id must be between 1 and 255 characters"
)
View Source
const (
	ErrorUserIDTooLong = "user id is toolong, id must be between 1 and 255 characters"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Jcosmos

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

func EasyInit

func EasyInit(host, key, db, collection string) *Jcosmos

func Init

func Init(host, keytype, key, db, collection string, loglevel loglevel, metrics, crossPartition bool, logger *log.Logger) *Jcosmos

func LocalInit

func LocalInit(host, key, db, collection string, metrics, crossPartition bool, logger *log.Logger) *Jcosmos

func (Jcosmos) CreateDatabase

func (c Jcosmos) CreateDatabase(db newDatabaseRequest, obj any) error

func (Jcosmos) CreateDatabaseWithAutopilot

func (c Jcosmos) CreateDatabaseWithAutopilot(db newDatabaseRequest, max int, obj any) error

func (Jcosmos) CreateDatabaseWithThroughput

func (c Jcosmos) CreateDatabaseWithThroughput(db newDatabaseRequest, throughput int, obj any) error

func (Jcosmos) CreateDocument

func (c Jcosmos) CreateDocument(pk []string, upsert bool, obj any) error

func (Jcosmos) CreateTrigger

func (c Jcosmos) CreateTrigger(t Trigger, obj TriggerResponse) error

func (Jcosmos) CreateUser

func (c Jcosmos) CreateUser(user newUserRequest, obj UserResponse) error

func (Jcosmos) DeleteDatabase

func (c Jcosmos) DeleteDatabase(db newDatabaseRequest, resp databaseResponse) error

func (Jcosmos) DeleteDocument

func (c Jcosmos) DeleteDocument(id string, pk []string) error

func (Jcosmos) DeleteTrigger

func (c Jcosmos) DeleteTrigger(id string) error

func (Jcosmos) DeleteUser

func (c Jcosmos) DeleteUser(user newUserRequest) error

func (Jcosmos) HealthCheck

func (c Jcosmos) HealthCheck() error

func (Jcosmos) ListDatabase

func (c Jcosmos) ListDatabase(resp databaseResponse) error

func (Jcosmos) ListDocument

func (c Jcosmos) ListDocument(pk []string, cont string, obj any) (string, error)

func (Jcosmos) ListOffer

func (c Jcosmos) ListOffer(q Query, obj ListOfferResponse) error

func (Jcosmos) ListTrigger

func (c Jcosmos) ListTrigger(obj TriggerList) error

func (Jcosmos) ListUser

func (c Jcosmos) ListUser(obj ListUserResponse) error

func (Jcosmos) PatchDocument

func (c Jcosmos) PatchDocument(id string, pk []string, p Patch, obj any) error

func (Jcosmos) QueryDocument

func (c Jcosmos) QueryDocument(pk []string, query Query, cont string, obj any) (string, error)

func (Jcosmos) QueryOffer

func (c Jcosmos) QueryOffer(query Query, obj ListOfferResponse) error

func (Jcosmos) ReadDatabase

func (c Jcosmos) ReadDatabase(resp databaseResponse) error

func (Jcosmos) ReadDocument

func (c Jcosmos) ReadDocument(id string, pk []string, obj any) error

func (Jcosmos) ReadOffer

func (c Jcosmos) ReadOffer(rid string, obj OfferResponse) error

func (Jcosmos) ReadUser

func (c Jcosmos) ReadUser(user newUserRequest, obj UserResponse) error

func (Jcosmos) ReplaceOffer

func (c Jcosmos) ReplaceOffer(offer OfferRequest, obj OfferResponse) error

func (Jcosmos) ReplaceTrigger

func (c Jcosmos) ReplaceTrigger(t Trigger, obj TriggerResponse) error

func (Jcosmos) UpdateDocument

func (c Jcosmos) UpdateDocument(id string, pk []string, obj any) error

func (Jcosmos) UpdateUser

func (c Jcosmos) UpdateUser(user newUserRequest, obj UserResponse) error

func (Jcosmos) UseCol

func (c Jcosmos) UseCol(coll string) *Jcosmos

func (Jcosmos) UseDB

func (c Jcosmos) UseDB(db string) *Jcosmos

func (Jcosmos) UseLogLevel

func (c Jcosmos) UseLogLevel(loglevel loglevel) *Jcosmos

func (Jcosmos) XPartitionQueryDocument

func (c Jcosmos) XPartitionQueryDocument(query Query, cont string, obj any) (string, error)

type ListOfferResponse

type ListOfferResponse struct {
	Offers []OfferResponse `json:"Offers"`
	Count  int             `json:"_count"`
	Rid    string          `json:"_rid"`
}

type ListUserResponse

type ListUserResponse struct {
	Users []UserResponse `json:"Users"`
	Count int            `json:"_count"`
	Rid   string         `json:"_rid"`
}

type OfferContent

type OfferContent struct {
	OfferThroughput int `json:"offerThroughput"`
}

type OfferRequest

type OfferRequest struct {
	OfferVersion    string       `json:"offerVersion"`
	Content         OfferContent `json:"content"`
	Resource        string       `json:"resource"`
	OfferResourceID string       `json:"offerResourceID"`
	ID              string       `json:"id"`
	Rid             string       `json:"_rid"`
}

permissions offers

type OfferResponse

type OfferResponse struct {
	OfferVersion    string       `json:"offerVersion"`
	OfferType       string       `json:"offerType"`
	Content         OfferContent `json:"content"`
	Resource        string       `json:"resource"`
	OfferResourceID string       `json:"offerResourceID"`
	ID              string       `json:"id"`
	Rid             string       `json:"_rid"`
	Self            string       `json:"_self"`
	Etag            string       `json:"_etag"`
	Ts              int64        `json:"_ts"`
}

type Parameter

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

type Patch

type Patch struct {
	Condition  string           `json:"condition,omitempty"`
	Operations []PatchOperation `json:"operations"`
}

type PatchOp

type PatchOp string
const (
	PatchOpAdd       PatchOp = "add"
	PatchOpSet       PatchOp = "set"
	PatchOpReplace   PatchOp = "replace"
	PatchOpRemove    PatchOp = "remove"
	PatchOpIncrement PatchOp = "increment"
)

type PatchOperation

type PatchOperation struct {
	Op    PatchOp `json:"op"`
	Path  string  `json:"path"`
	Value any     `json:"value"`
}

type Query

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

func (Query) ToJson

func (q Query) ToJson() ([]byte, error)

type QueryResponse

type QueryResponse struct {
	Documents []any  `json:"Documents"`
	Count     int    `json:"_count"`
	Rid       string `json:"_rid"`
}

type Trigger

type Trigger struct {
	ID               string `json:"id"`
	Body             string `json:"body"`
	TriggerOperation string `json:"triggerOperation"`
	TriggerType      string `json:"triggerType"`
}

attachments sprocs functions trigers

type TriggerList

type TriggerList struct {
	Triggers []TriggerResponse `json:"Users"`
	Count    int               `json:"_count"`
	Rid      string            `json:"_rid"`
}

type TriggerResponse

type TriggerResponse struct {
	ID               string `json:"id"`
	Body             string `json:"body"`
	TriggerOperation string `json:"triggerOperation"`
	TriggerType      string `json:"triggerType"`
	Rid              string `json:"_rid"`
	Ts               int64  `json:"_ts"`
	Self             string `json:"_self"`
	Etag             string `json:"_etag"`
}

type UserResponse

type UserResponse struct {
	ID          string `json:"id"`
	Rid         string `json:"_rid"`
	Ts          int64  `json:"_ts"`
	Self        string `json:"_self"`
	Etag        string `json:"_etag"`
	Permissions string `json:"_permissions"`
}

Directories

Path Synopsis
example
hierachial command
simple command

Jump to

Keyboard shortcuts

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