Documentation
¶
Overview ¶
Package store defines types to implement a store.
Index ¶
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 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) 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 Filter ¶
type Filter struct {
Pagination `json:"pagination"`
// A map ID the segments must have.
MapID string `json:"mapId"`
// 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"`
}
Filter 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 Pagination ¶
type Pagination struct {
// Index of the first entry.
Offset int `json:"offset"`
// Maximum number of entries, all if zero.
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 *Filter) (cs.SegmentSlice, error)
// Get all the existing map IDs.
GetMapIDs(pagination *Pagination) ([]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 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. |