💿 In-memory key value store that saves your data to disk using JSON.
20 Commits
.editorconfig | ||
.gitignore | ||
Collection_test.go | ||
Collection.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
README.md |
ocean
In-memory key value store that saves your data to plain old JSON files.
If you like, you can operate on your entire data with classic UNIX tools.
Installation
go get git.akyoto.dev/go/ocean
API
type Collection[T any] interface {
All() <-chan *T
Clear()
Delete(key string)
Exists(key string) bool
Get(key string) (value *T, ok bool)
Set(key string, value *T)
}
Example
// User data
type User struct {
Name string
}
// Load existing data from ~/.ocean/User/
users := ocean.New[User]()
// Store in memory and also store in ~/.ocean/User/1.json
users.Set("1", &User{Name: "User 1"})
// Read from memory
firstUser, err := users.Get("1")
// Iterate over all users
for user := range users.All() {
fmt.Println(user.Name)
}
In a real project you would usually prefix your collections with a project or company name:
// Data saved to ~/.ocean/google/User/
users := ocean.New[User]("google")
You can add as many directory hierarchies as you need but I recommend using a simple /namespace/collection/
structure.
Limitations
This storage mechanism is suitable for small to medium data volume.
It is not suited for big data, however the package is pretty lightweight so you can combine it with a big data store.