https://github.com/annybs/ezdb
Simple interfaces for working with basic key-value storage in your Go application
https://github.com/annybs/ezdb
database go golang
Last synced: 2 months ago
JSON representation
Simple interfaces for working with basic key-value storage in your Go application
- Host: GitHub
- URL: https://github.com/annybs/ezdb
- Owner: annybs
- License: other
- Created: 2024-06-08T07:42:50.000Z (about 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-07-11T16:57:53.000Z (almost 2 years ago)
- Last Synced: 2024-09-14T04:39:07.624Z (almost 2 years ago)
- Topics: database, go, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/annybs/ezdb
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# EZ DB
This package provides simple interfaces for working with basic key-value document storage in your Go application.
## System requirements
- [Go v1.21](https://go.dev/dl/)
## Basic usage
The primary interface in EZ DB is `Collection[T]` which reflects a single key-value store. This is analogous to tables in RDBMS, collections in NoSQL databases etc.
Collections use a generic type `T` to specify the document type. You can use this to enforce a document schema. This example creates a collection which only accepts `Student` documents:
```go
package main
import "github.com/annybs/ezdb"
type Student struct {
Name string
Age int
}
var db = ezdb.Memory[Student](nil)
func main() {
db.Open()
db.Put("annie", Student{Name: "Annie", Age: "32"})
db.Close()
}
```
## Marshaling data
Some database backends require marshaling and unmarshaling data. The `DocumentMarshaler[T1, T2]` interface allows you to use whatever marshaler suits your needs or the requirements of your chosen database.
The following marshalers are included in EZ DB:
- `JSON[T]` marshals your data `T` to `[]byte` using [encoding/json](https://pkg.go.dev/encoding/json)
## Supported databases
The following databases are included in EZ DB:
- `LevelDB[T]` is [fast key-value storage](https://github.com/google/leveldb) on disk
- `Memory[T]` is essentially a wrapper for `map[string]T`. It can be provided another Collection to use as a persistence backend
## Limitations
EZ DB is intended for simple document storage and can work with any addressable data represented as `T` in your Go app.
This makes it unsuited for working with unaddressable types, such as byte arrays, particularly when a document marshaler is involved.
If you want more control beyond what EZ DB offers, it's best to just use the appropriate database software and connector for your needs.
## License
See [LICENSE.md](./LICENSE.md)