Documentation ¶
Index ¶
- Constants
- type BaseMiniDB
- type MiniCollections
- func (c *MiniCollections) FilterBool() []bool
- func (c *MiniCollections) FilterFloat() []float64
- func (c *MiniCollections) FilterInt() []int
- func (c *MiniCollections) FilterString() []string
- func (c *MiniCollections) Find(v interface{}) int
- func (c *MiniCollections) FindAll(v interface{}) []interface{}
- func (c *MiniCollections) First() interface{}
- func (c *MiniCollections) Last() interface{}
- func (c *MiniCollections) List() []interface{}
- func (c *MiniCollections) MatchString(v string) (string, error)
- func (c *MiniCollections) MatchStringAll(v string) ([]string, error)
- func (c *MiniCollections) Push(v ...interface{})
- func (c *MiniCollections) Remove(v interface{}) error
- func (c *MiniCollections) RemoveAll(v interface{}) error
- func (c *MiniCollections) RemoveMany(v interface{}, l int) error
- type MiniDB
- func (db *MiniDB) Collections(key string) *MiniCollections
- func (db *MiniDB) FindCollection(key string) (string, error)
- func (db *MiniDB) FindKey(key string) (string, error)
- func (db *MiniDB) FindStore(key string) (string, error)
- func (db *MiniDB) Key(key string) *MiniDB
- func (db *MiniDB) ListCollections() []string
- func (db *MiniDB) ListStores() []string
- func (db *MiniDB) RemoveCollection(key string) error
- func (db *MiniDB) RemoveKey(key string) error
- func (db *MiniDB) RemoveStore(key string) error
- func (db *MiniDB) Store(key string) *MiniStore
- type MiniDBContent
- type MiniStore
- func (db *MiniStore) FindKey(key string) []string
- func (db *MiniStore) Get(key string) (interface{}, bool)
- func (db *MiniStore) GetBool(key string) bool
- func (db *MiniStore) GetBoolSlice(key string) []bool
- func (db *MiniStore) GetFloat32(key string) float32
- func (db *MiniStore) GetFloat32Slice(key string) []float32
- func (db *MiniStore) GetFloat64(key string) float64
- func (db *MiniStore) GetFloat64Slice(key string) []float64
- func (db *MiniStore) GetInt(key string) int
- func (db *MiniStore) GetIntSlice(key string) []int
- func (db *MiniStore) GetString(key string) string
- func (db *MiniStore) GetStringSlice(key string) []string
- func (db *MiniStore) IsExists(key string) bool
- func (db *MiniStore) List() map[string]interface{}
- func (db *MiniStore) Read(v interface{}) error
- func (db *MiniStore) ReadKey(key string, v interface{}) error
- func (db *MiniStore) Remove(key string) error
- func (db *MiniStore) Set(key string, v interface{}) error
- func (db *MiniStore) Update(key string, v interface{}) error
- func (db *MiniStore) Write(v interface{}) error
Constants ¶
const Version = "0.1.6"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseMiniDB ¶
type BaseMiniDB struct {
// contains filtered or unexported fields
}
BaseMiniDB is the base db structure.
type MiniCollections ¶
type MiniCollections struct { BaseMiniDB // contains filtered or unexported fields }
MiniCollections is a collections store.
func NewMiniCollections ¶
func NewMiniCollections(f string) *MiniCollections
NewMiniCollections creates and returns a new collections json db.
func (*MiniCollections) FilterBool ¶ added in v0.1.4
func (c *MiniCollections) FilterBool() []bool
FilterBool returns all bool elements.
func (*MiniCollections) FilterFloat ¶ added in v0.1.4
func (c *MiniCollections) FilterFloat() []float64
FilterFloat returns all float elements (uses float64). Some integers (int) might be included.
func (*MiniCollections) FilterInt ¶ added in v0.1.4
func (c *MiniCollections) FilterInt() []int
FilterInt returns all int elements.
func (*MiniCollections) FilterString ¶ added in v0.1.4
func (c *MiniCollections) FilterString() []string
FilterString returns all string elements.
func (*MiniCollections) Find ¶
func (c *MiniCollections) Find(v interface{}) int
Find attemps to find the value from the store and returns it's index. If it doesn't exist, it will return -1.
func (*MiniCollections) FindAll ¶
func (c *MiniCollections) FindAll(v interface{}) []interface{}
FindAll returns all values that matches v.
func (*MiniCollections) First ¶
func (c *MiniCollections) First() interface{}
First returns the first element of the collections.
func (*MiniCollections) Last ¶
func (c *MiniCollections) Last() interface{}
Last returns the last element of the collections.
func (*MiniCollections) List ¶ added in v0.1.3
func (c *MiniCollections) List() []interface{}
List returns all of the contents of the collection
func (*MiniCollections) MatchString ¶
func (c *MiniCollections) MatchString(v string) (string, error)
MatchString returns the first element that contains v.
func (*MiniCollections) MatchStringAll ¶
func (c *MiniCollections) MatchStringAll(v string) ([]string, error)
MatchStringAll returns the first element that contains v.
func (*MiniCollections) Push ¶
func (c *MiniCollections) Push(v ...interface{})
Push adds an item to the store slice.
func (*MiniCollections) Remove ¶ added in v0.1.5
func (c *MiniCollections) Remove(v interface{}) error
Remove removes the first element that is equal to v. It wraps around RemoveMany().
func (*MiniCollections) RemoveAll ¶ added in v0.1.5
func (c *MiniCollections) RemoveAll(v interface{}) error
RemoveAll removes all elements that are equal to v. It wraps around RemoveMany().
func (*MiniCollections) RemoveMany ¶ added in v0.1.5
func (c *MiniCollections) RemoveMany(v interface{}, l int) error
RemoveMany removes the number of elements corresponding to l. Use RemoveAll() for removing all elements and Remove() for a single element. `l` cannot be less than -1 or equal to 0.
type MiniDB ¶
type MiniDB struct { BaseMiniDB // contains filtered or unexported fields }
MiniDB is the base store file.
func New ¶
New creates a new MiniDB struct. The dir will be created if it doesn't exist and a file named `__default.json` will also be generated. It is better to use this in managing multiple json files.
func (*MiniDB) Collections ¶
func (db *MiniDB) Collections(key string) *MiniCollections
Collections creates a new key with an array / slice value.
func (*MiniDB) FindCollection ¶
FindCollection gets the key in the keys map and returns its corresponding filename. It returns nil if it exists.
func (*MiniDB) FindKey ¶
FindKey gets the key in the keys map and returns its corresponding filename. It returns nil if it exists.
func (*MiniDB) FindStore ¶
FindStore gets the key in the keys map and returns its corresponding filename. It returns nil if it exists.
func (*MiniDB) Key ¶
Key creates a new key in the json. It is better to use this for nesting and only if needed.
func (*MiniDB) ListCollections ¶ added in v0.1.1
ListCollections returns the list of collections created.
func (*MiniDB) ListStores ¶ added in v0.1.1
ListCollections returns the list of collections created.
func (*MiniDB) RemoveCollection ¶
RemoveCollection removes the collection key and the files corresponding to it. It returns nil if it is successful.
func (*MiniDB) RemoveKey ¶
RemoveKey removes the key and the files corresponding to it. It returns nil if it is successful.
func (*MiniDB) RemoveStore ¶
RemoveStore removes the store key and the files corresponding to it. It returns nil if it is successful.
type MiniDBContent ¶ added in v0.1.5
type MiniDBContent struct { Keys map[string]string `json:"keys"` Collections map[string]string `json:"collections"` Store map[string]string `json:"store"` }
MiniDBContent is the types of MiniDB.store
type MiniStore ¶
type MiniStore struct { BaseMiniDB // contains filtered or unexported fields }
MiniStore is a key-value store.
func NewMiniStore ¶
NewMiniStore creates and returns a new key-store collection json db.
func (*MiniStore) FindKey ¶ added in v0.1.6
FindKeys finds all the keys that contains `key`. It will return only all of the matched keys. This is useful for searching keys.
func (*MiniStore) Get ¶
Get finds the key and returns an interface value. It also returns false if the key does not exist and true, otherwise.
func (*MiniStore) GetBool ¶
GetBool finds the key with bool value and returns if exits. It panics if there is an error in type assertion.
func (*MiniStore) GetBoolSlice ¶
GetBoolSlice finds the key with the []bool value and returns if exits. It panics if there is an error in type assertion.
func (*MiniStore) GetFloat32 ¶
GetFloat32 finds the key with the float32 value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetFloat32Slice ¶
GetFloat32Slice finds the key with the []float32 value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetFloat64 ¶
GetFloat64 finds the key with the float64 value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetFloat64Slice ¶
GetFloat64Slice finds the key with the []float64 value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetInt ¶
GetInt finds the key with the int value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetIntSlice ¶
GetIntSlice finds the key with the []int value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetString ¶
GetString finds the key with the string value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) GetStringSlice ¶
GetStringSlice finds the key with the []string value and returns if exists. It panics if there is an error in type assertion.
func (*MiniStore) IsExists ¶ added in v0.1.4
IsExists asserts if the key exists. You should use Get() if you want to get the Raw value and if it exists.
func (*MiniStore) Read ¶ added in v0.1.1
Read parses the contents of db.store to v which is a struct object. It just wraps around `json.Marshal` and `json.Unmarshal`.
func (*MiniStore) ReadKey ¶ added in v0.1.1
ReadKey parses the contents of db.store[key] to v which is a struct object. It is better to use this if the value of key is a map. It just wraps around `json.Marshal` and `json.Unmarshal`.
func (*MiniStore) Remove ¶
Remove attemps to remove the key from the db if it exists. It returns nil if it is removed