scribble

package module
v0.0.0-...-aa3e7c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2019 License: MIT Imports: 7 Imported by: 0

README

Scribble GoDoc Go Report Card

A tiny JSON database in Golang

Installation

Install using go get github.com/nanobox-io/golang-scribble.

Usage

// a new scribble driver, providing the directory where it will be writing to,
// and a qualified logger if desired
db, err := scribble.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!)

Contributing

Contributions to scribble are welcome and encouraged. Scribble is a Nanobox project and contributions should follow the Nanobox Contribution Process & Guidelines.

Documentation

Overview

Package scribble is a tiny JSON database

Index

Constants

View Source
const Version = "1.0.4"

Version is the current version of the project

Variables

This section is empty.

Functions

This section is empty.

Types

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is what is used to interact with the scribble database. It runs transactions, and provides log output

func New

func New(dir string, options *Options) (*Driver, error)

New creates a new scribble database at the desired directory location, and returns a *Driver to then use for interacting with the database

func (*Driver) Delete

func (d *Driver) Delete(collection, resource string) error

Delete locks that database and then attempts to remove the collection/resource specified by path

func (*Driver) Read

func (d *Driver) Read(collection, resource string, v interface{}) error

Read a record from the database

func (*Driver) ReadAll

func (d *Driver) ReadAll(collection string) ([]string, error)

ReadAll records from a collection; this is returned as a slice of strings because there is no way of knowing what type the record is.

func (*Driver) Write

func (d *Driver) Write(collection, resource string, v interface{}) error

Write locks the database and attempts to write the record to the database under the [collection] specified with the [resource] name given

type Logger

type Logger interface {
	Fatal(string, ...interface{})
	Error(string, ...interface{})
	Warn(string, ...interface{})
	Info(string, ...interface{})
	Debug(string, ...interface{})
	Trace(string, ...interface{})
}

Logger is a generic logger interface

type Options

type Options struct {
	Logger // the logger scribble will use (configurable)
}

Options uses for specification of working golang-scribble

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL