ystore

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrorInvalidCollectionName is returned when a collection param is an empty string
	ErrorInvalidCollectionName = errors.New("No collection name provided")
	// ErrorInvalidKeyName is returned when a key param is an empty string
	ErrorInvalidKeyName = errors.New("No key name provided")
	// ErrorInvalidValue is returned when a key param is an empty string
	ErrorInvalidValue = errors.New("No value provided, if you are trying to delete the key please use Delete()")
	// ErrorCollectionNotFound is returned when trying to read a non exitant collection
	ErrorCollectionNotFound = errors.New("collection not found")
	// ErrorKeyNotFound is returned when trying to read a non exitant key
	ErrorKeyNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Batch

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

Batch handles multiple writes without a write to the disk so that many values can be written at a single time

func (*Batch) Commit

func (batch *Batch) Commit() error

Commit will lock the batch and store while it writes all of the values at one time to the data store

func (*Batch) Write

func (batch *Batch) Write(collection, key, value string) error

Write will set a value on a collection key in the batch. This will have no effect on the store until Commit() is called on the batch

type YStore

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

YStore is the struct that handles all interaction with the datastore.

func New

func New(path string) (*YStore, error)

New will create and return a new YStore. A error will be returned if the store already exists and contains invalid data.

func (*YStore) Batch

func (store *YStore) Batch() *Batch

Batch will return a batch object for this store that can be used to write multiple values ona single file write.

func (*YStore) Collections

func (store *YStore) Collections() ([]string, error)

Collections will return a string array of all the collections in the datastore. Collections will only ever return an error if the datastore is corrupt.

func (*YStore) Delete

func (store *YStore) Delete(collection, key string) error

Delete will remove a key/value from the collection in the data store. An error will be returned if the collection cannot be found or the change cannot be persisted.

func (*YStore) DeleteCollection

func (store *YStore) DeleteCollection(collection string) error

DeleteCollection will remove the collection from the database. DeleteCollection will return an error if the change cannot be persisted.

func (*YStore) Drop

func (store *YStore) Drop() error

Drop will clear the data cache as well as remove the file on the disk that acts as the datastore. This will completely clear the datastore.

func (*YStore) Dump

func (store *YStore) Dump() (map[string]map[string]string, error)

Dump will return the total contents of the store

func (*YStore) Read

func (store *YStore) Read(collection, key string) (string, error)

Read will read and return the value from the datastore for the provided collection key. Read requires that the collection and key are not empty strings otherwise an error will be returned. If the collection or key does not exist, an error will be returned.

func (*YStore) ReadAll

func (store *YStore) ReadAll(collection string) ([]string, error)

ReadAll will return a string array of all the keys in a collections. ReadAll will return an error if the collection does not exist or the collection parameter is an empty string.

func (*YStore) SetComment

func (store *YStore) SetComment(comment string) error

SetComment will set a comment that will be prepended to the file.

func (*YStore) Write

func (store *YStore) Write(collection, key, value string) error

Write will set the value for a key in a collection. Write also lazily instantiates the store so that if the file does not already exist, Write will create it. Write requires that all strings provided to it are not blank.

Jump to

Keyboard shortcuts

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