2017-02-09 22:31:44 -07:00
# Scribble
[](https://coveralls.io/github/nanobox-io/golang-scribble?branch=master) [](http://godoc.org/github.com/nanobox-io/golang-scribble) [](https://goreportcard.com/report/github.com/nanobox-io/golang-scribble)
2015-07-07 17:37:08 -06:00
--------
2015-11-13 14:21:11 -07:00
A tiny JSON database in Golang
2015-07-07 17:37:08 -06:00
### Installation
2015-09-29 09:15:17 -06:00
Install using `go get github.com/nanobox-io/golang-scribble` .
2015-07-07 17:37:08 -06:00
### Usage
2015-10-12 13:30:50 -06:00
```go
// a new scribble driver, providing the directory where it will be writing to,
2015-11-21 10:32:17 -07:00
// and a qualified logger if desired
db, err := scribble.New(dir, nil)
2015-10-12 13:30:50 -06:00
if err != nil {
fmt.Println("Error", err)
}
2015-07-07 17:37:08 -06:00
2015-10-12 13:30:50 -06:00
// Write a fish to the database
fish := Fish{}
2015-10-29 11:22:23 -06:00
if err := db.Write("fish", "onefish", fish); err != nil {
2015-11-21 10:32:17 -07:00
fmt.Println("Error", err)
2015-10-12 13:30:50 -06:00
}
2015-07-07 17:37:08 -06:00
2015-12-17 17:13:27 -07:00
// Read a fish from the database (passing fish by reference)
2015-10-12 13:30:50 -06:00
fish := []Fish{}
2015-12-17 17:13:27 -07:00
if err := db.Read("fish", "onefish", &fish); err != nil {
2015-11-21 10:32:17 -07:00
fmt.Println("Error", err)
2015-07-07 17:37:08 -06:00
}
2015-12-17 17:13:27 -07:00
// Read all fish from the database, unmarshaling the response.
records, err := db.ReadAll("fish")
if err != nil {
2015-11-21 10:32:17 -07:00
fmt.Println("Error", err)
2015-10-12 13:30:50 -06:00
}
2015-07-07 17:37:08 -06:00
2015-12-17 17:13:27 -07:00
fish := []Fish{}
2015-12-17 17:20:20 -07:00
if err := json.Unmarshal([]byte(records), &fish); err != nil {
2015-11-21 10:32:17 -07:00
fmt.Println("Error", err)
2015-10-12 13:30:50 -06:00
}
// Delete a fish from the database
2015-10-29 11:22:23 -06:00
if err := db.Delete("fish", "onefish"); err != nil {
2015-11-21 10:32:17 -07:00
fmt.Println("Error", err)
2015-07-07 17:37:08 -06:00
}
2015-12-17 17:13:27 -07:00
// Delete all fish from the database
if err := db.Delete("fish", ""); err != nil {
fmt.Println("Error", err)
}
2015-07-07 17:37:08 -06:00
```
2015-10-12 10:14:36 -06:00
## Documentation
2016-03-11 16:59:00 -07:00
Complete documentation is available on [godoc ](http://godoc.org/github.com/nanobox-io/golang-scribble ).
2015-10-12 10:14:36 -06:00
## Todo/Doing
2015-10-20 11:06:33 -06:00
- Support for windows
- Better support for concurrency
2015-10-12 13:30:50 -06:00
- Better support for sub collections
- More methods to allow different types of reads/writes
2015-12-17 17:13:27 -07:00
- More tests (you can never have enough!)
2015-10-12 10:06:42 -06:00
2015-10-12 10:14:36 -06:00
## Contributing
2016-03-11 16:59:00 -07: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/ ).