Documentation ¶
Overview ¶
Note: this file is used as a proof of concept for having a generic keyvalue store backed by specific implementations of kv.Store.
Index ¶
- Variables
- type Bucket
- type Cursor
- type ExampleService
- func (c *ExampleService) CreateUser(ctx context.Context, u *platform.User) error
- func (c *ExampleService) DeleteUser(ctx context.Context, id platform.ID) error
- func (c *ExampleService) FindUser(ctx context.Context, filter platform.UserFilter) (*platform.User, error)
- func (c *ExampleService) FindUserByID(ctx context.Context, id platform.ID) (*platform.User, error)
- func (c *ExampleService) FindUserByName(ctx context.Context, n string) (*platform.User, error)
- func (c *ExampleService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error)
- func (c *ExampleService) Initialize() error
- func (c *ExampleService) PutUser(ctx context.Context, u *platform.User) error
- func (c *ExampleService) UpdateUser(ctx context.Context, id platform.ID, upd platform.UserUpdate) (*platform.User, error)
- type Pair
- type Store
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyNotFound is the error returned when the key requested is not found. ErrKeyNotFound = errors.New("key not found") // ErrTxNotWritable is the error returned when an mutable operation is called during // a non-writable transaction. ErrTxNotWritable = errors.New("transaction is not writable") )
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket interface { Get(key []byte) ([]byte, error) Cursor() (Cursor, error) // Put should error if the transaction it was called in is not writable. Put(key, value []byte) error // Delete should error if the transaction it was called in is not writable. Delete(key []byte) error }
Bucket is the abstraction used to perform get/put/delete/get-many operations in a key value store.
type Cursor ¶
type Cursor interface { Seek(prefix []byte) (k []byte, v []byte) First() (k []byte, v []byte) Last() (k []byte, v []byte) Next() (k []byte, v []byte) Prev() (k []byte, v []byte) }
Cursor is an abstraction for iterating/ranging through data. A concrete implementation of a cursor can be found in cursor.go.
func NewStaticCursor ¶
NewStaticCursor returns an instance of a StaticCursor. It destructively sorts the provided pairs to be in key ascending order.
type ExampleService ¶
type ExampleService struct {
// contains filtered or unexported fields
}
ExampleService is an example user like service built on a generic kv store.
func NewExampleService ¶
func NewExampleService(kv Store, idGen platform.IDGenerator) *ExampleService
NewExampleService creates an instance of an example service.
func (*ExampleService) CreateUser ¶
CreateUser creates a platform example and sets b.ID.
func (*ExampleService) DeleteUser ¶
DeleteUser deletes a example and prunes it from the index.
func (*ExampleService) FindUser ¶
func (c *ExampleService) FindUser(ctx context.Context, filter platform.UserFilter) (*platform.User, error)
FindUser retrives a example using an arbitrary example filter. Filters using ID, or Name should be efficient. Other filters will do a linear scan across examples until it finds a match.
func (*ExampleService) FindUserByID ¶
FindUserByID retrieves a example by id.
func (*ExampleService) FindUserByName ¶
FindUserByName returns a example by name for a particular example.
func (*ExampleService) FindUsers ¶
func (c *ExampleService) FindUsers(ctx context.Context, filter platform.UserFilter, opt ...platform.FindOptions) ([]*platform.User, int, error)
FindUsers retrives all examples that match an arbitrary example filter. Filters using ID, or Name should be efficient. Other filters will do a linear scan across all examples searching for a match.
func (*ExampleService) Initialize ¶
func (c *ExampleService) Initialize() error
Initialize creates the buckets for the example service
func (*ExampleService) UpdateUser ¶
func (c *ExampleService) UpdateUser(ctx context.Context, id platform.ID, upd platform.UserUpdate) (*platform.User, error)
UpdateUser updates a example according the parameters set on upd.
type Store ¶
type Store interface { // View opens up a transaction that will not write to any data. Implementing interfaces // should take care to ensure that all view transactions do not mutate any data. View(func(Tx) error) error // Update opens up a transaction that will mutate data. Update(func(Tx) error) error }
Store is an interface for a generic key value store. It is modeled after the boltdb database struct.