Documentation ¶
Overview ¶
Package store abstracts the persistent storage used by elvish.
Index ¶
- Constants
- Variables
- func DefaultDB(dbname string) (*sql.DB, error)
- func EnsureDataDir() (string, error)
- func SchemaUpToDate(db *sql.DB) bool
- type Cmd
- type Dir
- type Store
- func (s *Store) AddCmd(cmd string) error
- func (s *Store) AddDir(d string, incFactor float64) error
- func (s *Store) Close() error
- func (s *Store) DelSharedVar(n string) error
- func (s *Store) GetCmd(seq int) (string, error)
- func (s *Store) GetCmds(from, upto int) ([]string, error)
- func (s *Store) GetDirs(blacklist map[string]struct{}) ([]Dir, error)
- func (s *Store) GetFirstCmd(from int, prefix string) (Cmd, error)
- func (s *Store) GetLastCmd(upto int, prefix string) (Cmd, error)
- func (s *Store) GetSharedVar(n string) (string, error)
- func (s *Store) IterateCmds(from, upto int, f func(string) bool) error
- func (s *Store) NextCmdSeq() (int, error)
- func (s *Store) SetSharedVar(n, v string) error
Constants ¶
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 ¶
var ErrEmptyHOME = errors.New("environment variable HOME is empty")
ErrEmptyHOME is the error returned by EnsureDataDir when the environmental variable HOME is empty.
var ErrNoMatchingCmd = errors.New("no matching command line")
ErrNoMatchingCmd is the error returned when a LastCmd or FirstCmd query completes with no result.
var ErrNoVar = errors.New("no such variable")
ErrNoVar is returned by (*Store).GetSharedVar when there is no such variable.
var NoBlacklist = map[string]struct{}{}
NoBlacklist is an empty blacklist, to be used in GetDirs.
Functions ¶
func EnsureDataDir ¶
EnsureDataDir ensures Elvish's data directory exists, creating it if necessary. It returns the path to the data directory (never with a trailing slash) and possible error.
func SchemaUpToDate ¶ added in v0.5.0
SchemaUpToDate returns whether the database has the current or newer version of the schema.
Types ¶
type Store ¶
type Store struct { // Waits is used for registering outstanding operations on the store. Waits sync.WaitGroup // 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 NewStoreDB ¶
NewStoreDB creates a new Store with a custom database. The database must be a SQLite database.
func (*Store) Close ¶
Close waits for all outstanding operations to finish, and closes the database.
func (*Store) DelSharedVar ¶
DelSharedVar deletes a shared variable.
func (*Store) GetCmd ¶ added in v0.8.0
GetCmd queries the command history item with the specified sequence number.
func (*Store) GetCmds ¶ added in v0.8.0
GetCmds returns the contents of all commands within the specified range.
func (*Store) GetDirs ¶ added in v0.8.0
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) GetFirstCmd ¶ added in v0.8.0
GetFirstCmd finds the first command after the given sequence number (inclusive) with the given prefix.
func (*Store) GetLastCmd ¶ added in v0.8.0
GetLastCmd finds the last command before the given sequence number (exclusive) with the given prefix.
func (*Store) GetSharedVar ¶
GetSharedVar gets the value of a shared variable.
func (*Store) IterateCmds ¶ added in v0.5.0
IterateCmds iterates all the commands in the specified range, and calls the callback with the content of each command sequentially.
func (*Store) NextCmdSeq ¶
NextCmdSeq returns the next sequence number of the command history.
func (*Store) SetSharedVar ¶
SetSharedVar sets the value of a shared variable.