Improved documentation
This commit is contained in:
parent
35c039d01b
commit
3949809138
10
README.md
10
README.md
@ -4,11 +4,17 @@ 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.
|
If you like, you can operate on your entire data with classic UNIX tools.
|
||||||
|
|
||||||
|
Let's say we use this struct to save our user data:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Then we can create a typesafe collection using Go generics:
|
||||||
|
|
||||||
|
```go
|
||||||
// Data saved to ~/.ocean/User/
|
// Data saved to ~/.ocean/User/
|
||||||
users := ocean.New[User]("User")
|
users := ocean.New[User]("User")
|
||||||
|
|
||||||
@ -16,11 +22,11 @@ users := ocean.New[User]("User")
|
|||||||
users.Set("1", &User{Name: "User 1"})
|
users.Set("1", &User{Name: "User 1"})
|
||||||
```
|
```
|
||||||
|
|
||||||
In a real project you would usually prefix your user collection with a project or company name, serving as a namespace:
|
In a real project you would usually prefix your collections with a project or company name:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Data saved to ~/.ocean/google/User/
|
// Data saved to ~/.ocean/google/User/
|
||||||
users := ocean.New("google", "User")
|
users := ocean.New[User]("google", "User")
|
||||||
```
|
```
|
||||||
|
|
||||||
You can add as many hierarchies as you need but I recommend using a simple `/namespace/collection/` structure.
|
You can add as many hierarchies as you need but I recommend using a simple `/namespace/collection/` structure.
|
||||||
|
Loading…
Reference in New Issue
Block a user