Simple Go library for in-memory data storage with file persistence.
- No data races
- Everything is stored in memory
- Multiple ways to persist to disk
- Small and fast
I wanted a safe way to access Go slices from multiple goroutines and the ability to save those slices to the disk. This is useful for APIs (see example) that require fast data access.
Dumps save to the disk (usually with a ".db" file extension). There are currently three persistence settings available.
Using the dump.PERSIST_MANUAL
constant allows you to control when the dump is saved to disk.
You can manually save the dump by calling the *Dump.Save()
function.
... = dump.NewDump(..., dump.PERSIST_MANUAL, ...)
Using the dump.PERSIST_WRITES
constant will cause the dump to save to disk when *Dump.Add()
or *Dump.Update()
is called.
... = dump.NewDump(..., dump.PERSIST_WRITES, ...)
Using the dump.PERSIST_INTERVAL
constant will cause the dump to save to disk on a timed interval (currently 60 seconds).
... = dump.NewDump(..., dump.PERSIST_INTERVAL, ...)
users, err := dump.NewDump("users.db", dump.PERSIST_WRITES, dump.Type{"main.User", User{}})
// id is assigned to the index location of the item after it is added
id, err := users.Add(&User{Name: "karl"})
err := users.View(func(items []dump.Item) error {
println(items[id].(*User).Name) // will output "karl"
return nil
})
err := users.Update(func(items []dump.Item) error {
items[id].(*User).Name = "santa"
return nil
})