scratch/README.md

68 lines
1.9 KiB
Markdown
Raw Normal View History

2018-06-07 01:15:41 -04:00
Scribble [![GoDoc](https://godoc.org/github.com/boltdb/bolt?status.svg)](http://godoc.org/github.com/sdomino/scribble) [![Go Report Card](https://goreportcard.com/badge/github.com/sdomino/scribble)](https://goreportcard.com/report/github.com/sdomino/scribble)
2015-07-07 19:37:08 -04:00
--------
2015-11-13 16:21:11 -05:00
A tiny JSON database in Golang
2015-07-07 19:37:08 -04:00
### Installation
2019-03-30 14:46:41 -04:00
Install using `go get github.com/sdomino/scribble`.
2015-07-07 19:37:08 -04:00
### Usage
```go
// a new scribble driver, providing the directory where it will be writing to,
2015-11-21 12:32:17 -05:00
// and a qualified logger if desired
db, err := scribble.New(dir, nil)
if err != nil {
fmt.Println("Error", err)
}
2015-07-07 19:37:08 -04:00
// Write a fish to the database
fish := Fish{}
if err := db.Write("fish", "onefish", fish); err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
}
2015-07-07 19:37:08 -04:00
// Read a fish from the database (passing fish by reference)
2017-10-26 00:04:17 -04:00
onefish := Fish{}
if err := db.Read("fish", "onefish", &onefish); err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
2015-07-07 19:37:08 -04:00
}
// Read all fish from the database, unmarshaling the response.
records, err := db.ReadAll("fish")
if err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
}
2015-07-07 19:37:08 -04:00
2017-10-26 00:04:17 -04:00
fishies := []Fish{}
for _, f := range records {
fishFound := Fish{}
if err := json.Unmarshal([]byte(f), &fishFound); err != nil {
fmt.Println("Error", err)
}
fishies = append(fishies, fishFound)
}
// Delete a fish from the database
if err := db.Delete("fish", "onefish"); err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
2015-07-07 19:37:08 -04:00
}
// Delete all fish from the database
if err := db.Delete("fish", ""); err != nil {
fmt.Println("Error", err)
}
2015-07-07 19:37:08 -04:00
```
2015-10-12 12:14:36 -04:00
## Documentation
2018-06-07 01:15:41 -04:00
- Complete documentation is available on [godoc](http://godoc.org/github.com/sdomino/scribble).
- Coverage Report is available on [gocover](https://gocover.io/github.com/sdomino/scribble)
2015-10-12 12:14:36 -04:00
## Todo/Doing
- Support for windows
- Better support for concurrency
- Better support for sub collections
- More methods to allow different types of reads/writes
- More tests (you can never have enough!)