scribble

package module
v0.0.0-...-76df67a Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Scribble GoDoc Go Report Card

This fork is to make scribble handle nested folder structures. So you can have layouts like bowls/{bowlname}/fish/{fishname}.json instead of the flat structure of only fish/{fishname}.json and no deeper. ReadAll will still work by reading all the json files in bowls/{bowlname}/fish folder.

A tiny JSON database in Golang

Installation

Install using go get github.com/sdomino/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!)

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

View Source
var (
	ErrMissingResource   = errors.New("missing resource - unable to save record")
	ErrMissingCollection = errors.New("missing collection - no place to save record")
)

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 the database 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) ([][]byte, 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
⌂ 换网址