store

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2017 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package store abstracts the persistent storage used by elvish.

Index

Constants

View Source
const BucketCmd = "cmd"
View Source
const BucketDir = "dir"
View Source
const BucketSchema = "schema"
View Source
const BucketSharedVar = "shared_var"
View Source
const SchemaVersion = 1

SchemaVersion is the current schema version. It should be bumped every time a backwards-incompatible change has been made to the schema.

Variables

View Source
var ErrInvalidBucket = errors.New("invalid bucket")
View Source
var ErrNoVar = errors.New("no such variable")

ErrNoVar is returned by (*Store).GetSharedVar when there is no such variable.

Functions

func DefaultDB

func DefaultDB(dbname string) (*bolt.DB, error)

DefaultDB returns the default database for storage.

func SchemaUpToDate added in v0.5.0

func SchemaUpToDate(db *bolt.DB) bool

SchemaUpToDate returns whether the database has the current or newer version of the schema.

Types

type Store

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

Store is the permanent storage backend for elvish. It is not thread-safe. In particular, the store may be closed while another goroutine is still accessing the store. To prevent bad things from happening, every time the main goroutine spawns a new goroutine to operate on the store, it should call Waits.Add(1) in the main goroutine before spawning another goroutine, and call Waits.Done() in the spawned goroutine after the operation is finished.

func NewStore

func NewStore(dbname string) (*Store, error)

NewStore creates a new Store with the default database.

func NewStoreDB

func NewStoreDB(db *bolt.DB) (*Store, error)

NewStoreDB creates a new Store with a custom database. The database must be a Bolt database.

func (*Store) AddCmd

func (s *Store) AddCmd(cmd string) (int, error)

AddCmd adds a new command to the command history.

func (*Store) AddDir

func (s *Store) AddDir(d string, incFactor float64) error

AddDir adds a directory to the directory history.

func (*Store) AddDirRaw added in v0.10.0

func (s *Store) AddDirRaw(d string, score float64) error

AddDir adds a directory and its score to history.

func (*Store) Close

func (s *Store) Close() error

Close waits for all outstanding operations to finish, and closes the database.

func (*Store) Cmd

func (s *Store) Cmd(seq int) (string, error)

Cmd queries the command history item with the specified sequence number.

func (*Store) Cmds

func (s *Store) Cmds(from, upto int) ([]string, error)

Cmds returns the contents of all commands within the specified range.

func (*Store) DelSharedVar

func (s *Store) DelSharedVar(n string) error

DelSharedVar deletes a shared variable.

func (*Store) GetDirs added in v0.8.0

func (s *Store) GetDirs(blacklist map[string]struct{}) ([]storedefs.Dir, error)

GetDirs lists all directories in the directory history whose names are not in the blacklist. The results are ordered by scores in descending order.

func (*Store) GetSharedVar

func (s *Store) GetSharedVar(n string) (string, error)

GetSharedVar gets the value of a shared variable.

func (*Store) IterateCmds added in v0.5.0

func (s *Store) IterateCmds(from, upto int, f func(string) bool) error

IterateCmds iterates all the commands in the specified range, and calls the callback with the content of each command sequentially.

func (*Store) NextCmd added in v0.9.0

func (s *Store) NextCmd(from int, prefix string) (int, string, error)

NextCmd finds the first command after the given sequence number (inclusive) with the given prefix.

func (*Store) NextCmdSeq

func (s *Store) NextCmdSeq() (int, error)

NextCmdSeq returns the next sequence number of the command history.

func (*Store) PrevCmd added in v0.9.0

func (s *Store) PrevCmd(upto int, prefix string) (int, string, error)

PrevCmd finds the last command before the given sequence number (exclusive) with the given prefix.

func (*Store) RemoveCmd added in v0.10.0

func (s *Store) RemoveCmd(seq int) error

RemoveCmd removes a command from command history referenced by sequence.

func (*Store) RemoveDir added in v0.10.0

func (s *Store) RemoveDir(d string) error

RemoveDir removes a directory record from history.

func (*Store) SetSharedVar

func (s *Store) SetSharedVar(n, v string) error

SetSharedVar sets the value of a shared variable.

func (*Store) Waits

func (s *Store) Waits() *sync.WaitGroup

Waits returns a WaitGroup used to register outstanding storage requests when making calls asynchronously.

Directories

Path Synopsis
Package storedefs contains definitions used by the store package.
Package storedefs contains definitions used by the store package.

Jump to

Keyboard shortcuts

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