From 3fed61059baeac8cdd167c623d4cb652f1ac6832 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 19 Jul 2023 11:52:13 +0200 Subject: [PATCH] Renamed module --- Benchmarks_test.go | 12 ++++++------ Collection.go | 4 ++-- Collection_test.go | 6 +++--- File.go | 2 +- File_test.go | 10 +++++----- KeyNotFoundError.go | 2 +- README.md | 20 ++++++++++---------- Storage.go | 2 +- go.mod | 2 +- keyValue.go | 2 +- storageData.go | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Benchmarks_test.go b/Benchmarks_test.go index b9a0b0f..8d89466 100644 --- a/Benchmarks_test.go +++ b/Benchmarks_test.go @@ -1,14 +1,14 @@ -package ocean_test +package data_test import ( "testing" "git.akyoto.dev/go/assert" - "git.akyoto.dev/go/ocean" + "git.akyoto.dev/go/data" ) func BenchmarkGet(b *testing.B) { - users, err := ocean.New[User]("test", nil) + users, err := data.New[User]("test", nil) assert.Nil(b, err) defer users.Sync() @@ -29,7 +29,7 @@ func BenchmarkGet(b *testing.B) { } func BenchmarkSet(b *testing.B) { - users, err := ocean.New[User]("test", nil) + users, err := data.New[User]("test", nil) assert.Nil(b, err) defer users.Sync() @@ -50,7 +50,7 @@ func BenchmarkSet(b *testing.B) { } func BenchmarkDelete(b *testing.B) { - users, err := ocean.New[User]("test", nil) + users, err := data.New[User]("test", nil) assert.Nil(b, err) defer users.Sync() @@ -71,7 +71,7 @@ func BenchmarkDelete(b *testing.B) { func BenchmarkNew(b *testing.B) { b.RunParallel(func(pb *testing.PB) { for pb.Next() { - _, _ = ocean.New[User]("test", nil) + _, _ = data.New[User]("test", nil) } }) } diff --git a/Collection.go b/Collection.go index 30fa6bd..9541d16 100644 --- a/Collection.go +++ b/Collection.go @@ -1,4 +1,4 @@ -package ocean +package data import ( "os" @@ -45,7 +45,7 @@ func New[T any](namespace string, storage Storage[T]) (Collection[T], error) { } c.storage = storage - c.root = filepath.Join(home, ".ocean", namespace) + c.root = filepath.Join(home, ".data", namespace) err = os.MkdirAll(c.root, 0700) if err != nil { diff --git a/Collection_test.go b/Collection_test.go index 5903342..e5f9fb1 100644 --- a/Collection_test.go +++ b/Collection_test.go @@ -1,11 +1,11 @@ -package ocean_test +package data_test import ( "sync" "testing" "git.akyoto.dev/go/assert" - "git.akyoto.dev/go/ocean" + "git.akyoto.dev/go/data" ) type User struct { @@ -13,7 +13,7 @@ type User struct { } func TestCollection(t *testing.T) { - users, err := ocean.New[User]("test", nil) + users, err := data.New[User]("test", nil) assert.Nil(t, err) defer users.Sync() diff --git a/File.go b/File.go index b0901e6..b46dd35 100644 --- a/File.go +++ b/File.go @@ -1,4 +1,4 @@ -package ocean +package data import ( "bufio" diff --git a/File_test.go b/File_test.go index 22c563d..729e670 100644 --- a/File_test.go +++ b/File_test.go @@ -1,16 +1,16 @@ -package ocean_test +package data_test import ( "testing" "git.akyoto.dev/go/assert" - "git.akyoto.dev/go/ocean" + "git.akyoto.dev/go/data" ) -var _ ocean.Storage[string] = (*ocean.File[string])(nil) +var _ data.Storage[string] = (*data.File[string])(nil) func TestFilePersistence(t *testing.T) { - users, err := ocean.NewFile[User]("test") + users, err := data.NewFile[User]("test") assert.Nil(t, err) defer users.Clear() @@ -22,7 +22,7 @@ func TestFilePersistence(t *testing.T) { users.Sync() // Reload data from disk - reload, err := ocean.NewFile[User]("test") + reload, err := data.NewFile[User]("test") assert.Nil(t, err) user, err := reload.Get("1") diff --git a/KeyNotFoundError.go b/KeyNotFoundError.go index 5c00587..411bb0a 100644 --- a/KeyNotFoundError.go +++ b/KeyNotFoundError.go @@ -1,4 +1,4 @@ -package ocean +package data import "fmt" diff --git a/README.md b/README.md index c609f88..4762969 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ -# ocean +# data In-memory key value store that saves your data to disk using JSON. ## Installation ```shell -go get git.akyoto.dev/go/ocean +go get git.akyoto.dev/go/data ``` ## Example @@ -14,8 +14,8 @@ go get git.akyoto.dev/go/ocean // User type type User struct { Name string } -// Create ~/.ocean/myapp/User.dat -users := ocean.NewFile[User]("myapp") +// Create ~/.data/myapp/User.dat +users := data.NewFile[User]("myapp") // Write users.Set("1", &User{Name: "User 1"}) @@ -55,24 +55,24 @@ BenchmarkNew-12 48838576 22.89 ns/op 80 B/op ## Storage systems -When you initiate a new collection via `ocean.New` you can specify a storage system. -`ocean.NewFile` is a useful shortcut to create a collection with the `ocean.File` storage. +When you initiate a new collection via `data.New` you can specify a storage system. +`data.NewFile` is a useful shortcut to create a collection with the `data.File` storage. ### nil You can specify `nil` as the storage system which will keep data in RAM only. -### ocean.File +### data.File -`ocean.File` uses a single file to store all records. +`data.File` uses a single file to store all records. Writes using `Set(key, value)` are async and only mark the collection as "dirty" which is very quick. The sync to disk happens shortly afterwards. Every collection uses one goroutine to check the "dirty" flag, write the new contents to disk and reset the flag. -The biggest advantage of `ocean.File` is that it scales well with the number of requests: +The biggest advantage of `data.File` is that it scales well with the number of requests: Suppose `n` is the number of write requests and `io` is the time it takes for one write. Immediate writes would require `O(n * io)` time to complete all writes but the async behavior makes it `O(n)`. -You should use `ocean.File` if you have a permanently running process such as a web server where end users expect quick responses and background work can happen after the user request has already been dealt with. +You should use `data.File` if you have a permanently running process such as a web server where end users expect quick responses and background work can happen after the user request has already been dealt with. Make sure you `defer collection.Sync()` to ensure that queued writes will be handled when the process ends. diff --git a/Storage.go b/Storage.go index b603db2..fe8eb37 100644 --- a/Storage.go +++ b/Storage.go @@ -1,4 +1,4 @@ -package ocean +package data type Storage[T any] interface { Init(data storageData) error diff --git a/go.mod b/go.mod index cdc665d..dfb4958 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module git.akyoto.dev/go/ocean +module git.akyoto.dev/go/data go 1.20 diff --git a/keyValue.go b/keyValue.go index 7e4d60d..46c8489 100644 --- a/keyValue.go +++ b/keyValue.go @@ -1,4 +1,4 @@ -package ocean +package data type keyValue struct { key string diff --git a/storageData.go b/storageData.go index ee3c3b9..ffa9349 100644 --- a/storageData.go +++ b/storageData.go @@ -1,4 +1,4 @@ -package ocean +package data import "sync"