Skip to content

Multi-file database, using codecs. Based on github.com/nanobox-io/golang-scribble. Apache-2.0 license.

License

Notifications You must be signed in to change notification settings

nanohard/scribble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scribble

GoDoc Go Report Card

Flat-file database in Golang using choosable encoders.

Currently supports:

  • JSON
  • Binary

Installation

Install using go get github.com/nanohard/scribble.

Usage

Unless you have a need to use JSON, it is recommended to use the default Binary for reduced file size.

Initialize Database

import(
    "github.com/nanohard/scribble"

    // Needed for Unmarshaling when using db.ReadAll()
    "github.com/nanohard/scribble/codec/json"
    // Or
    "github.com/nanohard/scribble/codec/binary"
)

// A new scribble driver, providing the directory where it will be writing to,
// and a qualified logger if desired.
// Defaults to using encoding/binary (well, really kelindar/binary)
db, err := scribble.New(dir, nil) // `binary.Codec` is used by default
if err != nil {
    fmt.Println("Error", err)
}

// Or

options := scribble.Options{
    Codec: json.Codec,  // `binary.Codec` is used by default
}
db, err := scribble.New(dir, options)
if err != nil {
    fmt.Println("Error", err)
}

DB Functions

// 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{}
    // binary.Codec.Unmarshal or json.Codec.Unmarshal
    if err := json.Codec.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.

Todo/Doing

  • More encoders?

Contributing

  • Rebase into one commit.
  • Have liberal code comments.

About

Multi-file database, using codecs. Based on github.com/nanobox-io/golang-scribble. Apache-2.0 license.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages