Documentation ¶
Index ¶
- type Database
- func (db *Database) Clear()
- func (db *Database) Delete(key string)
- func (db *Database) Get(key string) interface{}
- func (db *Database) Has(key string) bool
- func (db *Database) IsEmpty() bool
- func (db *Database) IsLoaded() bool
- func (db *Database) Keys() []string
- func (db *Database) Load() error
- func (db *Database) Save() error
- func (db *Database) Set(key string, value interface{})
- func (db *Database) Size() int
- func (db *Database) Values() []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Database ¶
Represents a database
func New ¶
Initializes a instance of a database Database should be loaded before using it!
db := New("database.json") db.Load()
func (*Database) Clear ¶
func (db *Database) Clear()
Deletes all keys from the database
db.Clear() db.Save()
func (*Database) Get ¶
Returns the value of a key
val := db.Get("key") if val == nil { fmt.Println("key not found") } fmt.Println(val)
func (*Database) Has ¶
Whether the key exists in the database
if db.Has("key") { fmt.Println("key exists") }
func (*Database) IsEmpty ¶
Whether the database is empty
if db.IsEmpty() { fmt.Println("database is empty") }
func (*Database) IsLoaded ¶
Whether the database is loaded
if db.IsLoaded() { fmt.Println("database is loaded") } else { db.Load() defer db.Save() db.Set("key", "value") }
func (*Database) Keys ¶
Returns a slice of all keys in the database
keys := db.Keys() for _, key := range keys { fmt.Println(key) }
func (*Database) Save ¶
Saves the database to the database file You should call this method everytime you make changes
func (*Database) Set ¶
Sets the value of a key
db.Set("key", "value") db.Set("ints", 12) db.Set("maps", map[string]string{"a": "b"}) db.Set("slices", []string{"a", "b"}) db.Save()
Click to show internal directories.
Click to hide internal directories.