datastore

package
v0.0.0-...-2c2efe1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package datastore - enables data to be persisted in built in datebase (Bolt)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBackendNotInitialized is returned when the backend is not set
	ErrBackendNotInitialized = errors.New("backend not initialized")
	// ErrCodecNotInitialized is returned when the codec is not set
	ErrCodecNotInitialized = errors.New("codec not initialized")
	// ErrKeyNotFound is returned when an attempt to load a value of a missing key is made
	ErrKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Set(datatype, key string, value []byte, indexData map[string]string) error
	Get(datatype, key string) ([]byte, error)
	Del(datatype, key string) error
	ListKeys(datatype, index string, skip, limit int, reverse bool) (keys []string, err error)
	Close() error
}

Backend provides data storage interface

func NewBoltBackend

func NewBoltBackend(filename string) (Backend, error)

NewBoltBackend creates a new Bolt backend using CoreOS bbolt implementation

type BoltBackend

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

BoltBackend implements Backend interface with embedded Bolt storage

func (*BoltBackend) Close

func (bb *BoltBackend) Close() error

Close closes the database

func (*BoltBackend) Del

func (bb *BoltBackend) Del(datatype, key string) error

Del deletes a key and all the indexes

func (*BoltBackend) Get

func (bb *BoltBackend) Get(datatype, key string) (data []byte, err error)

Get retreives the value for specified key and datatyoe Returns ErrKeyNotFound if the key has no value set

func (*BoltBackend) ListKeys

func (bb *BoltBackend) ListKeys(datatype, index string, skip, limit int, reverse bool) (keys []string, err error)

ListKeys lists all keys for specified datatype

func (*BoltBackend) Set

func (bb *BoltBackend) Set(datatype, key string, value []byte, indexData map[string]string) error

Set stores the value for a key of datatype using bolt datastore

type Codec

type Codec interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

Codec probides data serialization interface

func NewGOBCodec

func NewGOBCodec() Codec

NewGOBCodec creates a new GOB Codec

func NewJSONCodec

func NewJSONCodec() Codec

NewJSONCodec creates a new JSON Codec

type GOBCodec

type GOBCodec struct{}

GOBCodec implement Codec interface with GOB encoding

func (*GOBCodec) Marshal

func (s *GOBCodec) Marshal(v interface{}) ([]byte, error)

Marshal with GOB encoding

func (*GOBCodec) Unmarshal

func (s *GOBCodec) Unmarshal(b []byte, v interface{}) error

Unmarshal with GOB encoding

type JSONCodec

type JSONCodec struct{}

JSONCodec implement Codec interface with JSON encoding

func (*JSONCodec) Marshal

func (s *JSONCodec) Marshal(v interface{}) ([]byte, error)

Marshal with JSON encoding

func (*JSONCodec) Unmarshal

func (s *JSONCodec) Unmarshal(b []byte, v interface{}) error

Unmarshal with JSON encoding

type Store

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

Store provides key-value data storage with specific backend and codec

func NewStore

func NewStore(options ...StoreOption) (*Store, error)

NewStore constructs a new store

func (*Store) Close

func (s *Store) Close() error

Close closes the database

func (*Store) Del

func (s *Store) Del(datatype, key string) error

Del deletes a key and all the indexes

func (*Store) Get

func (s *Store) Get(datatype, key string, v interface{}) error

Get retreives the value for specified key and datatyoe Returns ErrKeyNotFound if the key has no value set

func (*Store) ListKeys

func (s *Store) ListKeys(datatype, index string, skip, limit int, reverse bool) (keys []string, err error)

ListKeys lists keys by index

func (*Store) Set

func (s *Store) Set(datatype, key string, v interface{}, indexData map[string]string) error

Set stores the value for a key of datatype

type StoreOption

type StoreOption func(s *Store) error

StoreOption sets additional parameters to the Store

func WithBackend

func WithBackend(b Backend) StoreOption

WithBackend sets the store backend

func WithCodec

func WithCodec(enc Codec) StoreOption

WithCodec sets the store codec

Jump to

Keyboard shortcuts

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