store

package
v0.0.7-dev Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package store defines types to implement a store.

Index

Constants

View Source
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 {
	// Returns arbitrary information about the adapter.
	GetInfo() (interface{}, error)

	// Adds a channel that receives segments whenever they are saved.
	AddDidSaveChannel(chan *cs.Segment)

	// Creates or updates a segment. Segments passed to this method are
	// assumed to be valid.
	SaveSegment(segment *cs.Segment) error

	// Get a segment by link hash. Returns nil if no match is found.
	GetSegment(linkHash *types.Bytes32) (*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)

	// 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)
}

Adapter must be implemented by a store.

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

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.

Jump to

Keyboard shortcuts

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