Documentation
¶
Overview ¶
Package database provides a key/value storage. It allows binary serialization and deserialization to a reader/writer of to file
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct { // Storage stores the key storage mappings Storage map[string]interface{} }
DB represents a database
func (*DB) Delete ¶
Delete removes a record from the database. It returns true if the key was present and false otherwise
type FileDB ¶
type FileDB struct { DB // contains filtered or unexported fields }
FileDB implements a database backed up by a file
func (*FileDB) Deserialize ¶
Deserialize reads the file storage from disk and re-populates the in-memory database
type Serializable ¶
type Serializable interface { // Serialize allows saving the database storage to a file on disk Serialize() error // DeserializeFromFile allows populating the database from a file on disk Deserialize() error }
Serializable defines the interface that all serializable objects should implement
type Storer ¶
type Storer interface { Serializable // Get allows retrieving the value associated with the provided key // If the key is not present, it returns nil Get(key string) interface{} // Set allows setting a value identified by the provided key Set(key string, value interface{}) // Delete allows deleting a key. // It returns true if the key was present or false otherwise Delete(key string) bool //Exists returns true if the key exists and false otherwise Exists(key string) bool // Keys returns the list of key identifiers stored Keys() []string }
Storer defines the interface that all database kinds should implement
func NewFileDatabase ¶
NewFileDatabase returns a file-backed database. If 'file' exists, the function will try to load its contents to populate the database.