💿 In-memory key value store that saves your data to disk using JSON. 33 Commits
2023-07-08 19:08:28 +02:00
.editorconfig Added explanation 2023-07-05 22:02:16 +02:00
.gitignore Added explanation 2023-07-05 22:02:16 +02:00
Collection_test.go Improved data safety 2023-07-08 19:08:28 +02:00
Collection.go Implemented file storage 2023-07-08 17:26:36 +02:00
Decoder.go Added custom encoding/decoding 2023-07-07 14:38:41 +02:00
DirectoryStorage.go Implemented file storage 2023-07-08 17:26:36 +02:00
Encoder.go Added custom encoding/decoding 2023-07-07 14:38:41 +02:00
Errors.go Improved error handling 2023-07-06 17:26:19 +02:00
FileStorage.go Improved data safety 2023-07-08 19:08:28 +02:00
go.mod Added basic tests 2023-07-05 17:23:50 +02:00
go.sum Added basic tests 2023-07-05 17:23:50 +02:00
keyValue.go Implemented file storage 2023-07-08 17:26:36 +02:00
LICENSE Added basic information 2023-07-05 00:20:26 +02:00
README.md Implemented file storage 2023-07-08 17:26:36 +02:00
Storage.go Implemented file storage 2023-07-08 17:26:36 +02:00

ocean

In-memory key value store that saves your data in JSON format.

1
{"name":"User 1"}
2
{"name":"User 2"}
3
{"name":"User 3"}

If you like, you can operate on your entire data with classic UNIX tools.

Installation

go get git.akyoto.dev/go/ocean

Example

// User data
type User struct {
    Name string
}

// Load existing data from ~/.ocean/User.dat
users := ocean.New[User]()

// Store in memory and also store in ~/.ocean/User.dat
users.Set("1", &User{Name: "User 1"})

// Read from memory
first, 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.dat
users := ocean.New[User]("google")

Disk writes are async and they work like this:

  1. Set key and value in memory (sync.Map.Store)
  2. Mark the collection as "dirty" (atomic.StoreUint32)
  3. Immediately return control to the program

Because a Set call doesn't immediately flush the memory to disk, calling Set multiple times in a web server request becomes extremely efficient.