persistent

package
v0.0.0-...-810b4b3 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Picker

type Picker interface {
	strpick.Picker

	// SoftRemove removes a string from the Picker without removing it from the
	// underlying database. A subsequent Add or LoadDB call will restore its
	// current generation.
	SoftRemove(string) error
	// SoftRemoveAll removes strings from the Picker without removing them from
	// the underlying database. A subsequent Add or LoadDB call will restore
	// their current generations.
	SoftRemoveAll([]string) error

	// LoadDB loads all existing data from the database.
	// Calling this is not necessary, but can be substantially more efficient
	// than calling Add or AddAll.
	LoadDB() error

	// Initialize is equivalent to AddAll but is more efficient when dealing with
	// the majority of the contents of the DB.
	Initialize([]string) error

	// CleanDB deletes any strings not currently present (returned by Values())
	// in this Picker from the database. This includes any strings that have been
	// removed using SoftRemove().
	CleanDB() error
	// DumpDB loads all existing data from the database and returns it as a list
	// of key, value pairs.
	// Useful for debugging or to satisfy curiosity
	DumpDB() ([]kv, error)
}

Picker extends strpick.Picker with the additional methods related to persisting the state the the Picker to disk. None of these methods are required. Close() must be called to safely close the database.

func NewPicker

func NewPicker(dir string) (Picker, error)

NewPicker creates a new persist.Picker backed by a database in the provided directory dir, which will be created if it does not exist. Acquires a lock on the database, preventing multiple processes from accessing it at once. Writes are all performed synchronously. Close() must be called to safely close the database.

Jump to

Keyboard shortcuts

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