2017-03-27 17:44:30 -04:00
Scribble [![GoDoc ](https://godoc.org/github.com/boltdb/bolt?status.svg )](http://godoc.org/github.com/nanobox-io/golang-scribble) [![Go Report Card ](https://goreportcard.com/badge/github.com/nanobox-io/golang-scribble )](https://goreportcard.com/report/github.com/nanobox-io/golang-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
2015-09-29 11:15:17 -04:00
Install using `go get github.com/nanobox-io/golang-scribble` .
2015-07-07 19:37:08 -04:00
### Usage
2015-10-12 15:30:50 -04:00
```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)
2015-10-12 15:30:50 -04:00
if err != nil {
fmt.Println("Error", err)
}
2015-07-07 19:37:08 -04:00
2015-10-12 15:30:50 -04:00
// Write a fish to the database
fish := Fish{}
2015-10-29 13:22:23 -04:00
if err := db.Write("fish", "onefish", fish); err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
2015-10-12 15:30:50 -04:00
}
2015-07-07 19:37:08 -04:00
2015-12-17 19:13:27 -05:00
// Read a fish from the database (passing fish by reference)
2015-10-12 15:30:50 -04:00
fish := []Fish{}
2015-12-17 19:13:27 -05:00
if err := db.Read("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
}
2015-12-17 19:13:27 -05: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-10-12 15:30:50 -04:00
}
2015-07-07 19:37:08 -04:00
2015-12-17 19:13:27 -05:00
fish := []Fish{}
2015-12-17 19:20:20 -05:00
if err := json.Unmarshal([]byte(records), &fish); err != nil {
2015-11-21 12:32:17 -05:00
fmt.Println("Error", err)
2015-10-12 15:30:50 -04:00
}
// Delete a fish from the database
2015-10-29 13:22:23 -04:00
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
}
2015-12-17 19:13:27 -05: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
2017-03-27 17:44:30 -04:00
- Complete documentation is available on [godoc ](http://godoc.org/github.com/nanobox-io/golang-scribble ).
- Coverage Report is available on [gocover ](https://gocover.io/github.com/nanobox-io/golang-scribble )
2015-10-12 12:14:36 -04:00
## Todo/Doing
2015-10-20 13:06:33 -04:00
- Support for windows
- Better support for concurrency
2015-10-12 15:30:50 -04:00
- Better support for sub collections
- More methods to allow different types of reads/writes
2015-12-17 19:13:27 -05:00
- More tests (you can never have enough!)
2015-10-12 12:06:42 -04:00
2015-10-12 12:14:36 -04:00
## Contributing
2016-03-11 18:59:00 -05:00
Contributions to scribble are welcome and encouraged. Scribble is a [Nanobox ](https://nanobox.io ) project and contributions should follow the [Nanobox Contribution Process & Guidelines ](https://docs.nanobox.io/contributing/ ).