A tiny BSON database in Golang.
Go to file
Atlas Cove 8ce8dfb12e Forked from github.com/sdomino/scribble 2021-09-01 23:04:46 +01:00
example Correct import 2019-03-30 19:46:09 +01:00
.gitignore first commit 2014-12-01 15:55:19 -07:00
LICENSE Forked from github.com/sdomino/scribble 2021-09-01 23:04:46 +01:00
README.md Forked from github.com/sdomino/scribble 2021-09-01 23:04:46 +01:00
scratch.go Forked from github.com/sdomino/scribble 2021-09-01 23:04:46 +01:00
scratch_test.go Forked from github.com/sdomino/scribble 2021-09-01 23:04:46 +01:00

README.md

Scratch GoDoc Go Report Card

A tiny BSON database in Golang, a drop-in replacement for scribble.

Installation

Install using go get git.sdf.org/Atlas48/scratch.

Usage

// a new scratch driver, providing the directory where it will be writing to,
// and a qualified logger if desired
db, err := scratch.New(dir, nil)
if err != nil {
  fmt.Println("Error", err)
}

// Write a fish to the database
fish := Fish{}
if err := db.Write("fish", "onefish", fish); err != nil {
  fmt.Println("Error", err)
}

// Read a fish from the database (passing fish by reference)
onefish := Fish{}
if err := db.Read("fish", "onefish", &onefish); err != nil {
  fmt.Println("Error", err)
}

// Read all fish from the database, unmarshaling the response.
records, err := db.ReadAll("fish")
if err != nil {
  fmt.Println("Error", err)
}

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 {
  fmt.Println("Error", err)
}

// Delete all fish from the database
if err := db.Delete("fish", ""); err != nil {
  fmt.Println("Error", err)
}

Documentation

  • Complete documentation is available on godoc.
  • Coverage Report is available on gocover

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!)