Documentation ¶
Index ¶
- Constants
- Variables
- func UseFrozenTimeStamps()
- type Config
- type Option
- type ReadCloser
- type Record
- func (val Record) Data() map[string]interface{}
- func (val Record) Del(k string)
- func (r *Record) File() ReadCloser
- func (r *Record) Flatted() map[string]interface{}
- func (val Record) Get(key string) interface{}
- func (r *Record) Key() string
- func (val Record) MergeData(data map[string]interface{})
- func (val Record) Set(k string, v interface{})
- func (val Record) SetData(data map[string]interface{})
- func (r *Record) SetFile(f ReadCloser)
- func (val Record) SetIfExists(k string, v interface{})
- func (r *Record) SetKey(key string)
- func (val Record) Value() map[string]interface{}
- type Records
- type Store
- func (s *Store) CheckGhosts() ([]string, error)
- func (s *Store) CheckOrphans() ([]string, error)
- func (s *Store) Close() error
- func (s *Store) Create(key string, data map[string]interface{}, f ReadCloser) (*Record, error)
- func (s *Store) Delete(key string) error
- func (s *Store) Exists(key string) (exists bool, err error)
- func (s *Store) Fields() ([]string, error)
- func (s *Store) Insert(r *Record) error
- func (s *Store) IsDirty() bool
- func (s *Store) MatchFields(fuzziness int, fields ...string) (keys []string, values map[string][]interface{}, err error)
- func (s *Store) Open() error
- func (s *Store) OpenRecord(r *Record) (ReadCloser, error)
- func (s *Store) Read(key string) (*Record, error)
- func (s *Store) ReadAll() (list Records, err error)
- func (s *Store) ReadGlob(pattern string) (Records, error)
- func (s *Store) ReadQuery(query string) (Records, error)
- func (s *Store) RebuildIndex() error
- func (s *Store) RepairIndex() error
- func (s *Store) SearchFields(fuzziness int, fields ...string) ([]string, error)
- func (s *Store) SearchGlob(pattern string) ([]string, error)
- func (s *Store) SearchQuery(query string) ([]string, error)
- func (s *Store) Update(key string, r *Record) error
Constants ¶
const ( // KeyField contains the name of the record's value field containing the // record's key when exported through Fields() KeyField = "Name" )
Variables ¶
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") )
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
type Option ¶
Option is a function that can tweak the behavior of a Store
func UsingDefaultAnalyzer ¶
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 ¶
UsingLogger sets the logger used for logging events from store module. By default, log messages are discarded (sent to ioutil.Discard)
func UsingTypeField ¶
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
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 (Record) Data ¶ added in v0.4.0
func (val Record) Data() map[string]interface{}
Data returns stored user-supplied data
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
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) 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.
type Records ¶
type Records []*Record
Records represents a collection of Record
func (Records) Flatted ¶ added in v0.3.3
Flatted returns the Flatted() form 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 NewFromConfig ¶ added in v0.3.2
NewFromConfig creates a Store from a given Config
func (*Store) CheckGhosts ¶ added in v0.4.0
CheckGhosts lists any database entries that has no corresponding file in the store's filesystem.
func (*Store) CheckOrphans ¶ added in v0.4.0
CheckOrphans Lists any file in store that is not in the database.
func (*Store) Create ¶
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) Exists ¶
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
Fields list the fields that can be used when searching the collection.
func (*Store) Insert ¶ added in v0.6.0
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
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) 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) ReadGlob ¶ added in v0.4.0
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
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 ¶
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
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
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
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
SearchQuery returns the Records' keys that match the given search query. The query and sort order should follow the bleve search engine syntax.