store

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: BSD-2-Clause Imports: 48 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyField contains the name of the record's value field containing the
	// record's key when exported through Fields()
	KeyField = "Name"
)

Variables

View Source
var (
	// ErrKeyIsNotValid raises an error if provided key is invalid
	ErrKeyIsNotValid = errors.New("key is invalid")

	// ErrRecordAlreadyExists raises an error if a record already exits
	ErrRecordAlreadyExists = errors.New("record already exists")

	// ErrRecordDoesNotExist raises an error is a record does not exist
	ErrRecordDoesNotExist = errors.New("record does not exist")
)
View Source
var (
	// ErrRecordNotFoundInDb alerts if no record is found
	ErrRecordNotFoundInDb = fmt.Errorf("Record not found")
)

Functions

func UseFrozenTimeStamps added in v0.3.3

func UseFrozenTimeStamps()

UseFrozenTimeStamps sets the time-stamp function to returns a fixed time-stamp. It is especially useful for time-sensitive tests and a normal user would probably never wants this feature to be set.

Types

type Config added in v0.3.2

type Config struct {
	// Path is the path to store the Store
	Path string

	// Logger is the logger used by Store to feedback events.
	// Default to ioutil.Discard (no log).
	Logger *log.Logger

	// TypeField is the name used for identifying record's type to apply
	// specific indexing scheme.
	// Default to "Type"
	TypeField string

	// IndexingAnalyzer is the default analyzer used to index store's records.
	// Available analyzer are any analyzer compatible with bleve-search
	IndexingAnalyzer string

	// IndexingScheme is the bleve's document mapping used to index store's
	// records.
	IndexingScheme *mapping.IndexMappingImpl
}

Config describes a configuration set for a Store

func NewConfig added in v0.3.3

func NewConfig() *Config

NewConfig creates config

func (*Config) Analyzers added in v0.5.0

func (c *Config) Analyzers() []string

Analyzers lists the available analyzers that can be used to configure the collection's indexer.

type Option

type Option func(*Store) error

Option is a function that can tweak the behavior of a Store

func UsingDefaultAnalyzer

func UsingDefaultAnalyzer(analyzer string) Option

UsingDefaultAnalyzer sets the default analyzer of the Store's index

Available analyzer are any analyzer compatible with bleve-search.

func UsingIndexingScheme

func UsingIndexingScheme(idxMappings *mapping.IndexMappingImpl) Option

UsingIndexingScheme adds bleve's document mapping to the Store's index

Available mappings are any mappings compatible with bleve-search The index mapping can take benefit of Record implementing bleve.Classifier interface.

Mapping only applies to newly created indexes so that you might need to manually regenerate the index if you modify the mapping.

func UsingLogger

func UsingLogger(l *log.Logger) Option

UsingLogger sets the logger used for logging events from store module. By default, log messages are discarded (sent to ioutil.Discard)

func UsingTypeField

func UsingTypeField(name string) Option

UsingTypeField customizes the name of the field used to identified the type of the stored record. Type is used to implement specific indexing scheme that can be customized with UsingIndexingScheme.

UsingTypeField shall be used after UsingIndexingScheme

type ReadCloser added in v0.7.0

type ReadCloser interface {
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Closer
}

ReadCloser is an interface that wraps all io Read methods that are usually need to play with media files.

type Record

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

Record represents a Store's record.

func NewRecord

func NewRecord(key string, data map[string]interface{}) *Record

NewRecord creates a Record.

func (Record) Data added in v0.4.0

func (val Record) Data() map[string]interface{}

Data returns stored user-supplied data

func (Record) Del added in v0.4.0

func (val Record) Del(k string)

Del removes a (key, value).

func (*Record) File added in v0.6.0

func (r *Record) File() ReadCloser

File returns the file attached to a Record. It rewinds the Record's file to its start before returning it. File is nil if Record's as no known attached file. File is usually needed to reference source media file of a record before having it inserted or updated in the store.

func (*Record) Flatted added in v0.3.3

func (r *Record) Flatted() map[string]interface{}

Flatted returns all Record's data in a single flat map including Record's Key

func (Record) Get added in v0.3.3

func (val Record) Get(key string) interface{}

Get retrieves a (key, value) information stored in a Value.

func (*Record) Key

func (r *Record) Key() string

Key is Record's (unique) identifier in the store

func (Record) MergeData added in v0.7.0

func (val Record) MergeData(data map[string]interface{})

MergeData completes and replaces stored data with data content (data values are copied and supersede record's existing values. Record's values not in data are kept as is).

func (Record) Set added in v0.3.3

func (val Record) Set(k string, v interface{})

Set adds a new (key, value).

func (Record) SetData added in v0.4.0

func (val Record) SetData(data map[string]interface{})

SetData replaces record's user-supplied data.

func (*Record) SetFile added in v0.6.0

func (r *Record) SetFile(f ReadCloser)

SetFile sets Record's file

func (Record) SetIfExists added in v0.5.0

func (val Record) SetIfExists(k string, v interface{})

SetIfExists updates a value if already exists.

func (*Record) SetKey

func (r *Record) SetKey(key string)

SetKey modifies Record's (unique) identifier

func (Record) Value

func (val Record) Value() map[string]interface{}

Value returns all information stored in value, both user-supplied data and automatic managed data like creation/update time.

type Records

type Records []*Record

Records represents a collection of Record

func (Records) Data added in v0.4.0

func (r Records) Data() (v []map[string]interface{})

Data returns the Data() for each record in the collection.

func (Records) Flatted added in v0.3.3

func (r Records) Flatted() (v []map[string]interface{})

Flatted returns the Flatted() form for each record in the collection.

func (Records) Key

func (r Records) Key() (k []string)

Key returns the Key() for each record in the collection.

func (Records) Value

func (r Records) Value() (v []map[string]interface{})

Value returns the Value() for each record in the collection.

type Store

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

Store represents the actual storing engine. It is made of a filesystem, a key-value database and an indexer (bleve)

func New

func New(path string, opts ...Option) (*Store, error)

New creates a new Store. New accepts options to customize default Store behaviour

func NewFromConfig added in v0.3.2

func NewFromConfig(cfg *Config) (*Store, error)

NewFromConfig creates a Store from a given Config

func (*Store) CheckGhosts added in v0.4.0

func (s *Store) CheckGhosts() ([]string, error)

CheckGhosts lists any database entries that has no corresponding file in the store's filesystem.

func (*Store) CheckOrphans added in v0.4.0

func (s *Store) CheckOrphans() ([]string, error)

CheckOrphans Lists any file in store that is not in the database.

func (*Store) Close

func (s *Store) Close() error

Close cleanly closes a Store

func (*Store) Create

func (s *Store) Create(key string, data map[string]interface{}, f ReadCloser) (*Record, error)

Create creates a new record then inserts it in the Store. Create does not replace existing Record (you have to use Update for that) but will replace partially existing records resulting from an inconsistent state of the Store (e.g. file exists but entry in db does not).

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes a record from the Store

func (*Store) Exists

func (s *Store) Exists(key string) (exists bool, err error)

Exists returns whether a Record exists for the given key. If the Store's state is inconsistent for the given key (e.g. file is not present but and entry exists in the database), Exists returns false

func (*Store) Fields added in v0.5.0

func (s *Store) Fields() ([]string, error)

Fields list the fields that can be used when searching the collection.

func (*Store) Insert added in v0.6.0

func (s *Store) Insert(r *Record) error

Insert inserts a new record in the Store. It does not replace existing Record (you have to use Update for that) but will replace partially existing records resulting from an inconsistent state of the Store (e.g. file exists but entry in db does not)

func (*Store) IsDirty added in v0.4.0

func (s *Store) IsDirty() bool

IsDirty verify store's general health in term of consistency between database, index and filesystem.

func (*Store) MatchFields added in v0.6.0

func (s *Store) MatchFields(fuzziness int, fields ...string) (keys []string, values map[string][]interface{}, err error)

MatchFields looks for Records' fields that match the provided list of field/value with given fuzziness: . < 0: an exact term search is perform . 0: the input text is analyzed first. An attempt is made to use the same

analyzer that was used when the field was indexed.

. > 0: the input text is analysed first, the match is done with the given

level of fuzziness.

MatchFields returns for the found Record the matching values of the provided fields.

func (*Store) Open

func (s *Store) Open() error

Open opens a Store for use

func (*Store) OpenRecord

func (s *Store) OpenRecord(r *Record) (ReadCloser, error)

OpenRecord opens the Record corresponding to the given key for reading. If Record's Key is absolute, store will look for Record's content from the host file-system, other wise it get it from store's storage.

func (*Store) Read

func (s *Store) Read(key string) (*Record, error)

Read returns the stored Record corresponding to the given key

func (*Store) ReadAll

func (s *Store) ReadAll() (list Records, err error)

ReadAll returns all store's records

func (*Store) ReadGlob added in v0.4.0

func (s *Store) ReadGlob(pattern string) (Records, error)

ReadGlob returns the list of records corresponding to the given search pattern. Under the hood the pattern matching follows the same behaviour than filepath.Match.

func (*Store) ReadQuery added in v0.5.0

func (s *Store) ReadQuery(query string) (Records, error)

ReadQuery returns the Records that match the given search query. The query follows the bleve search engine syntax (http://blevesearch.com/docs/Query-String-Query/).

func (*Store) RebuildIndex

func (s *Store) RebuildIndex() error

RebuildIndex deletes then rebuild the index from scratch based on the database content. It can be used for example to implement a new mapping strategy or if things are really going bad

func (*Store) RepairIndex added in v0.4.0

func (s *Store) RepairIndex() error

RepairIndex check the consistency between the index and the database. Try to repair them as far as possible.

func (*Store) SearchFields added in v0.5.0

func (s *Store) SearchFields(fuzziness int, fields ...string) ([]string, error)

SearchFields looks for Records' keys that match the provided list of fields name/value with the given fuzziness: . < 0: an exact term search is perform . 0: the input text is analyzed first. An attempt is made to use the same

analyzer that was used when the field was indexed.

. > 0: the input text is analysed first, the match is done with the given

level of fuzziness.

func (*Store) SearchGlob added in v0.5.0

func (s *Store) SearchGlob(pattern string) ([]string, error)

SearchGlob returns the Records' keys that match the given glob pattern. Under the hood the pattern matching follows the same behaviour than filepath.Match.

func (*Store) SearchQuery added in v0.5.0

func (s *Store) SearchQuery(query string) ([]string, error)

SearchQuery returns the Records' keys that match the given search query. The query and sort order should follow the bleve search engine syntax.

func (*Store) Update

func (s *Store) Update(key string, r *Record) error

Update replaces an existing Store's record. Update will fail if the new record key is already existing (ErrRecordAlreadyExists).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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