store

package
v1.49.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2021 License: MIT Imports: 9 Imported by: 2

Documentation

Overview

Package store provides a simple and convenient data store interface for plugins to persist data along with a default filed-based leveldb implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeKey

func DecodeKey(rawKey string) (silo string, key string, err error)

DecodeKey returns a logical key and silo given its raw key value

func EncodeKey

func EncodeKey(silo string, key string) (encKey string)

EncodeKey encodes a key with the silo name and the \xda character (not a valid utf8 character)

func SiloPrefix

func SiloPrefix(silo string) (prefix string)

SiloPrefix returns the prefix for a key in the given silo

Types

type BytesStorer

type BytesStorer interface {
	io.Closer
	Scanner

	Get(key []byte) (value []byte, err error)
	Put(key []byte, value []byte) (err error)
	Delete(key []byte) (err error)
}

BytesStorer is implemented by any value that has the Get/Put/Delete/Scan and Closer methods on byte arrays for keys/values.

type GlobalSiloStringStorer

type GlobalSiloStringStorer interface {
	SiloStringStorer
	GlobalScan() (entries map[string]map[string]string, err error)
}

GlobalSiloStringStorer is implemented by any value that has all the SiloStringStorer methods and the GlobalScanSilo method

type LevelDB

type LevelDB struct {
	Name string
	// contains filtered or unexported fields
}

LevelDB holds a datastore name and its leveldb instance

func NewLevelDB

func NewLevelDB(name string, storagePath string) (ldb *LevelDB, err error)

NewLevelDB instantiates and open a new LevelDB instance backed by a leveldb database. If the leveldb database doesn't exist, one is created

func (*LevelDB) Close

func (ldb *LevelDB) Close() (err error)

Close closes the LevelDB

func (*LevelDB) Delete

func (ldb *LevelDB) Delete(key []byte) (err error)

Delete deletes an entry for a given key

func (*LevelDB) DeleteSiloString

func (ldb *LevelDB) DeleteSiloString(silo string, key string) (err error)

DeleteSiloString deletes an entry for a given key string in the given silo

func (*LevelDB) DeleteString

func (ldb *LevelDB) DeleteString(key string) (err error)

DeleteString deletes an entry for a given key string

func (*LevelDB) Get

func (ldb *LevelDB) Get(key []byte) (value []byte, err error)

Get retrieves a value associated to the key

func (*LevelDB) GetSiloString

func (ldb *LevelDB) GetSiloString(silo string, key string) (value string, err error)

GetSiloString retrieves a value associated to the key in the given silo

func (*LevelDB) GetString

func (ldb *LevelDB) GetString(key string) (value string, err error)

GetString retrieves a value associated to the key

func (*LevelDB) GlobalScan

func (ldb *LevelDB) GlobalScan() (entries map[string]map[string]string, err error)

GlobalScan returns the complete set of key/values from the database for all silos

func (*LevelDB) Put

func (ldb *LevelDB) Put(key []byte, value []byte) (err error)

Put adds or updates a value associated to the key

func (*LevelDB) PutSiloString

func (ldb *LevelDB) PutSiloString(silo string, key string, value string) (err error)

PutSiloString adds or updates a value associated to the key in the given silo

func (*LevelDB) PutString

func (ldb *LevelDB) PutString(key string, value string) (err error)

PutString adds or updates a value associated to the key

func (*LevelDB) Scan

func (ldb *LevelDB) Scan() (entries map[string]string, err error)

Scan returns the complete set of key/values from the database

func (*LevelDB) ScanSilo

func (ldb *LevelDB) ScanSilo(silo string) (entries map[string]string, err error)

ScanSilo returns the complete set of key/values from the database in the given silo

type Scanner

type Scanner interface {
	Scan() (entries map[string]string, err error)
}

Scanner is implemented by any value that has the Scan method returning all key/values as strings.

Since []byte aren't allowed as map keys, we use don't have an equivalent Scanner interface returning the data as bytes. For implementers, it should be easy to convert the []byte values to string with a simple string(value) conversion as strings are immutable arrays of bytes

type SiloStringStorer

type SiloStringStorer interface {
	io.Closer

	GetSiloString(silo string, key string) (value string, err error)
	PutSiloString(silo string, key string, value string) (err error)
	DeleteSiloString(silo string, key string) (err error)
	ScanSilo(silo string) (entries map[string]string, err error)
}

SiloStringStorer is implemented by any value that has the Get/Put/Delete/Scan and Closer methods on string keys/values with a silo name.

type StringStorer

type StringStorer interface {
	io.Closer
	Scanner

	GetString(key string) (value string, err error)
	PutString(key string, value string) (err error)
	DeleteString(key string) (err error)
}

StringStorer is implemented by any value that has the Get/Put/Delete/Scan and Closer methods on string keys/values.

Directories

Path Synopsis
Package datastoredb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface backed by the Google Cloud Datastore.
Package datastoredb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface backed by the Google Cloud Datastore.
Package inmemorydb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface as an in-memory data store relying on a wrapping StringStorer for actual persistence.
Package inmemorydb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface as an in-memory data store relying on a wrapping StringStorer for actual persistence.
Package mocks contains a mock of the store package interfaces
Package mocks contains a mock of the store package interfaces

Jump to

Keyboard shortcuts

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