💿 In-memory key value store that saves your data to disk using JSON.
38 Commits
storage | ||
.editorconfig | ||
.gitignore | ||
Benchmarks_test.go | ||
Collection_test.go | ||
Collection.go | ||
Errors.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
README.md | ||
Storage.go |
ocean
In-memory key value store that saves your data to disk using JSON.
Installation
go get git.akyoto.dev/go/ocean
Example
// User type
type User struct { Name string }
// Create a new collection
users := ocean.New[User]("todolist", &storage.File[User]{})
// Store some data
users.Set("1", &User{Name: "User 1"})
users.Set("2", &User{Name: "User 2"})
users.Set("3", &User{Name: "User 3"})
// Read from memory
first, err := users.Get("1")
// Iterate over all users
for user := range users.All() {
fmt.Println(user.Name)
}
Data will be stored in ~/.ocean/todolist/User.dat
.
Format
1
{"name":"User 1"}
2
{"name":"User 2"}
3
{"name":"User 3"}
Usage
- Create all the collections you need at the start
defer users.Sync()
to ensure queued writes will be handled on exit- Start your web server
- Retrieve and update your data using
Get
andSet
calls