couchstore

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Name is the name set in the store's information.
	Name = "CouchDB"

	// Description is the description set in the store's information.
	Description = "Stratumn's CouchDB Store"
)

Variables

This section is empty.

Functions

func NewMapQuery

func NewMapQuery(filter *store.MapFilter) ([]byte, error)

NewMapQuery generates json data used to filter queries using couchdb _find api.

func NewSegmentQuery

func NewSegmentQuery(filter *store.SegmentFilter) ([]byte, error)

NewSegmentQuery generates json data used to filter queries using couchdb _find api.

Types

type BulkDocuments

type BulkDocuments struct {
	Documents []*Document `json:"docs"`
	Atomic    bool        `json:"all_or_nothing,omitempty"`
}

BulkDocuments is used to bulk save documents to couchdb.

type Config

type Config struct {
	// Address is CouchDB api end point.
	Address string

	// A version string that will be set in the store's information.
	Version string

	// A git commit hash that will be set in the store's information.
	Commit string
}

Config contains configuration options for the store.

type CouchFindResponse

type CouchFindResponse struct {
	Docs []*Document `json:"docs"`
}

CouchFindResponse is couchdb response type when posting to /db/_find

type CouchResponseStatus

type CouchResponseStatus struct {
	Ok         bool
	StatusCode int
	Error      string `json:"error,omitempty"`
	Reason     string `json:"reason,omitempty"`
}

CouchResponseStatus contains couch specific response when querying the API.

type CouchStore

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

CouchStore is the type that implements github.com/stratumn/go-core/store.Adapter.

func New

func New(config *Config) (*CouchStore, error)

New creates an instance of a CouchStore.

func (*CouchStore) AddEvidence

func (c *CouchStore) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, evidence *chainscript.Evidence) error

AddEvidence implements github.com/stratumn/go-core/store.EvidenceWriter.AddEvidence.

func (*CouchStore) AddStoreEventChannel

func (c *CouchStore) AddStoreEventChannel(eventChan chan *store.Event)

AddStoreEventChannel implements github.com/stratumn/go-core/store.Adapter.AddStoreEventChannel

func (*CouchStore) CreateDatabase added in v0.3.1

func (c *CouchStore) CreateDatabase(dbName string) error

CreateDatabase creates a database.

func (*CouchStore) CreateIndex added in v0.3.1

func (c *CouchStore) CreateIndex(dbName string, indexName string, fields []string) error

CreateIndex creates an index.

func (c *CouchStore) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)

CreateLink implements github.com/stratumn/go-core/store.LinkWriter.CreateLink.

func (*CouchStore) DeleteDatabase added in v0.3.1

func (c *CouchStore) DeleteDatabase(name string) error

DeleteDatabase deletes a database.

func (*CouchStore) DeleteValue

func (c *CouchStore) DeleteValue(ctx context.Context, key []byte) ([]byte, error)

DeleteValue implements github.com/stratumn/go-core/store.Adapter.DeleteValue.

func (*CouchStore) FindSegments

func (c *CouchStore) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)

FindSegments implements github.com/stratumn/go-core/store.Adapter.FindSegments.

func (*CouchStore) GetDatabases added in v0.3.1

func (c *CouchStore) GetDatabases() ([]string, error)

GetDatabases lists available databases.

func (*CouchStore) GetEvidences

func (c *CouchStore) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)

GetEvidences implements github.com/stratumn/go-core/store.EvidenceReader.GetEvidences.

func (*CouchStore) GetInfo

func (c *CouchStore) GetInfo(ctx context.Context) (interface{}, error)

GetInfo implements github.com/stratumn/go-core/store.Adapter.GetInfo.

func (*CouchStore) GetMapIDs

func (c *CouchStore) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)

GetMapIDs implements github.com/stratumn/go-core/store.Adapter.GetMapIDs.

func (*CouchStore) GetSegment

func (c *CouchStore) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)

GetSegment implements github.com/stratumn/go-core/store.Adapter.GetSegment.

func (*CouchStore) GetValue

func (c *CouchStore) GetValue(ctx context.Context, key []byte) ([]byte, error)

GetValue implements github.com/stratumn/go-core/store.Adapter.GetValue.

func (*CouchStore) NewBatch

func (c *CouchStore) NewBatch(ctx context.Context) (store.Batch, error)

NewBatch implements github.com/stratumn/go-core/store.Adapter.NewBatch.

func (*CouchStore) SetValue

func (c *CouchStore) SetValue(ctx context.Context, key, value []byte) error

SetValue implements github.com/stratumn/go-core/store.KeyValueStore.SetValue.

type Document

type Document struct {
	ID         string `json:"_id,omitempty"`
	Revision   string `json:"_rev,omitempty"`
	ObjectType string `json:"docType,omitempty"`

	// The following fields are used when querying couchdb for link documents.
	LinkWrapper *LinkWrapper `json:"linkWrapper,omitempty"`

	// The following fields are used when querying couchdb for evidences documents.
	Evidences types.EvidenceSlice `json:"evidences,omitempty"`

	// The following fields are used when querying couchdb for map documents.
	Process string `json:"process,omitempty"`

	// The following fields are used when querying couchdb for values stored via key/value.
	Value []byte `json:"value,omitempty"`
}

Document is the object stored in CouchDB.

type Info

type Info struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Version     string `json:"version"`
	Commit      string `json:"commit"`
}

Info is the info returned by GetInfo.

type LinkHashIn

type LinkHashIn struct {
	LinkHashes []string `json:"$in,omitempty"`
}

LinkHashIn specifies the list of link hashes to search for

type LinkQuery

type LinkQuery struct {
	Selector LinkSelector        `json:"selector,omitempty"`
	Limit    int                 `json:"limit,omitempty"`
	Skip     int                 `json:"skip,omitempty"`
	Sort     []map[string]string `json:"sort,omitempty"`
}

LinkQuery used in CouchDB rich queries

type LinkSelector

type LinkSelector struct {
	ObjectType   string        `json:"docType"`
	PrevLinkHash *PrevLinkHash `json:"linkWrapper.prevLinkHash,omitempty"`
	Process      string        `json:"linkWrapper.link.meta.process.name,omitempty"`
	MapIds       *MapIdsIn     `json:"linkWrapper.link.meta.mapId,omitempty"`
	Step         string        `json:"linkWrapper.link.meta.step,omitempty"`
	Tags         *TagsAll      `json:"linkWrapper.link.meta.tags,omitempty"`
	LinkHash     *LinkHashIn   `json:"_id,omitempty"`
}

LinkSelector used in LinkQuery.

type LinkWrapper struct {
	Link         *chainscript.Link `json:"link"`
	Priority     float64           `json:"priority"`
	PrevLinkHash string            `json:"prevLinkHash"`
}

LinkWrapper wraps a link before saving it to a CouchDB document. Links omit empty values in their JSON representation, which can break CouchDB's filtering. So we make sure the LinkWrapper contains explicit default values for all fields we want to be able to sort on.

func WrapLink(link *chainscript.Link) *LinkWrapper

WrapLink wraps a link.

type MapIdsFilter added in v0.3.1

type MapIdsFilter struct {
	MapIdsMatch string `json:"$regex,omitempty"`
}

MapIdsFilter specifies that segment mapId should match a given regex.

type MapIdsFilters added in v0.3.1

type MapIdsFilters struct {
	Filters []MapIdsFilter `json:"$and,omitempty"`
}

MapIdsFilters contain the filters on the segment map ID. MapIdsFilters.And is a list of MapIdsFilter.

type MapIdsIn

type MapIdsIn struct {
	MapIds []string `json:"$in,omitempty"`
}

MapIdsIn specifies that segment mapId should be in specified list

type MapQuery

type MapQuery struct {
	Selector MapSelector `json:"selector,omitempty"`
	Limit    int         `json:"limit,omitempty"`
	Skip     int         `json:"skip,omitempty"`
}

MapQuery used in CouchDB rich queries.

type MapSelector

type MapSelector struct {
	ObjectType string         `json:"docType"`
	Process    string         `json:"process,omitempty"`
	MapIds     *MapIdsFilters `json:"_id,omitempty"`
}

MapSelector used in MapQuery.

type PrevLinkHash

type PrevLinkHash struct {
	Exists *bool  `json:"$exists,omitempty"`
	Equals string `json:"$eq"`
}

PrevLinkHash is used to specify PrevLinkHash in selector.

type TagsAll

type TagsAll struct {
	Tags []string `json:"$all,omitempty"`
}

TagsAll specifies all tags in specified list should be in segment tags

Jump to

Keyboard shortcuts

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