Documentation ¶
Overview ¶
Package store defines types to implement a store.
Index ¶
- Constants
- type Adapter
- type Batch
- type BufferedBatch
- func (b *BufferedBatch) DeleteSegment(linkHash *types.Bytes32) (segment *cs.Segment, err error)
- func (b *BufferedBatch) DeleteValue(key []byte) (value []byte, err error)
- func (b *BufferedBatch) FindSegments(filter *SegmentFilter) (cs.SegmentSlice, error)
- func (b *BufferedBatch) GetMapIDs(filter *MapFilter) ([]string, error)
- func (b *BufferedBatch) GetSegment(linkHash *types.Bytes32) (segment *cs.Segment, err error)
- func (b *BufferedBatch) GetValue(key []byte) (value []byte, err error)
- func (b *BufferedBatch) SaveSegment(segment *cs.Segment) error
- func (b *BufferedBatch) SaveValue(key, value []byte) error
- type MapFilter
- type OpType
- type Pagination
- type Reader
- type SegmentFilter
- type SegmentOperation
- type ValueOperation
- type Writer
Constants ¶
const ( // OpTypeSet set represents a save operation. OpTypeSet = iota // OpTypeDelete set represents a delete operation. OpTypeDelete )
const ( // DefaultLimit is the default pagination limit. DefaultLimit = 20 // MaxLimit is the maximum pagination limit. MaxLimit = 200 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface { Reader Writer // Returns arbitrary information about the adapter. GetInfo() (interface{}, error) // Adds a channel that receives segments whenever they are saved. AddDidSaveChannel(chan *cs.Segment) // Creates a new Batch NewBatch() (Batch, error) }
Adapter must be implemented by a store.
type Batch ¶
type Batch interface { Reader Writer // Write definitely writes the content of the Batch Write() error }
Batch represents a database transaction
type BufferedBatch ¶
type BufferedBatch struct { ValueOps []ValueOperation SegmentOps []SegmentOperation // contains filtered or unexported fields }
BufferedBatch can be used as a base class for types that want to implement github.com/stratumn/sdk/store.Batch. All operations are stored in arrays and can be replayed. Only the Write method must be implemented.
func NewBufferedBatch ¶
func NewBufferedBatch(a Adapter) *BufferedBatch
NewBufferedBatch creates a new Batch.
func (*BufferedBatch) DeleteSegment ¶
DeleteSegment implements github.com/stratumn/sdk/store.Adapter.DeleteSegment.
func (*BufferedBatch) DeleteValue ¶
func (b *BufferedBatch) DeleteValue(key []byte) (value []byte, err error)
DeleteValue implements github.com/stratumn/sdk/store.Adapter.DeleteValue.
func (*BufferedBatch) FindSegments ¶
func (b *BufferedBatch) FindSegments(filter *SegmentFilter) (cs.SegmentSlice, error)
FindSegments delegates the call to the store
func (*BufferedBatch) GetMapIDs ¶
func (b *BufferedBatch) GetMapIDs(filter *MapFilter) ([]string, error)
GetMapIDs delegates the call to the store
func (*BufferedBatch) GetSegment ¶
GetSegment returns a segment from the cache or delegates the call to the store
func (*BufferedBatch) GetValue ¶
func (b *BufferedBatch) GetValue(key []byte) (value []byte, err error)
GetValue returns a segment from the cache or delegates the call to the store
func (*BufferedBatch) SaveSegment ¶
func (b *BufferedBatch) SaveSegment(segment *cs.Segment) error
SaveSegment implements github.com/stratumn/sdk/store.Adapter.SaveSegment.
func (*BufferedBatch) SaveValue ¶
func (b *BufferedBatch) SaveValue(key, value []byte) error
SaveValue implements github.com/stratumn/sdk/store.Adapter.SaveValue.
type MapFilter ¶
type MapFilter struct { Pagination `json:"pagination"` // Process name is optionnal. Process string `json:"process"` }
MapFilter contains filtering options for segments.
type Pagination ¶
type Pagination struct { // Index of the first entry. Offset int `json:"offset"` // Maximum number of entries. Limit int `json:"limit"` }
Pagination contains pagination options.
func (*Pagination) PaginateSegments ¶
func (p *Pagination) PaginateSegments(a cs.SegmentSlice) cs.SegmentSlice
PaginateSegments paginate a list of segments
func (*Pagination) PaginateStrings ¶
func (p *Pagination) PaginateStrings(a []string) []string
PaginateStrings paginates a list of strings
type Reader ¶
type Reader interface { // Get a segment by link hash. Returns nil if no match is found. GetSegment(linkHash *types.Bytes32) (*cs.Segment, error) // Find segments. Returns an empty slice if there are no results. FindSegments(filter *SegmentFilter) (cs.SegmentSlice, error) // Get all the existing map IDs. GetMapIDs(filter *MapFilter) ([]string, error) // Gets a value at a key GetValue(key []byte) ([]byte, error) }
Reader is the interface that wraps the Read methods of a Store.
type SegmentFilter ¶
type SegmentFilter struct { Pagination `json:"pagination"` // Map IDs the segments must have. MapIDs []string `json:"mapIds"` // Process name is optionnal. Process string `json:"process"` // A previous link hash the segments must have. PrevLinkHash *types.Bytes32 `json:"prevLinkHash"` // A slice of tags the segments must all contain. Tags []string `json:"tags"` }
SegmentFilter contains filtering options for segments. If PrevLinkHash is not nil, MapID is ignored because a previous link hash implies the map ID of the previous segment.
type SegmentOperation ¶
SegmentOperation represents a operation on a segment.
type ValueOperation ¶
ValueOperation represents a operation on a value.
type Writer ¶
type Writer interface { // Creates or updates a segment. Segments passed to this method are // assumed to be valid. SaveSegment(segment *cs.Segment) error // Deletes a segment by link hash. Returns the removed segment or nil // if not found. DeleteSegment(linkHash *types.Bytes32) (*cs.Segment, error) // Saves a value at a key. SaveValue(key []byte, value []byte) error // Deletes a value at a key. DeleteValue(key []byte) ([]byte, error) }
Writer is the interface that wraps the Write methods of a Store.
Directories ¶
Path | Synopsis |
---|---|
Package storehttp is used to create an HTTP server from a store adapter.
|
Package storehttp is used to create an HTTP server from a store adapter. |
Package storetestcases defines test cases to test stores.
|
Package storetestcases defines test cases to test stores. |
Package storetesting defines helpers to test stores.
|
Package storetesting defines helpers to test stores. |