scribble

package module
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2018 License: MPL-2.0 Imports: 6 Imported by: 0

README

Scribble (FireScribble Edition) GoDoc Go Report Card Build Status

A tiny GOB based database in Golang - behaviour is very similar to Google Cloud Firestore

Note If you would rather use JSON instad of GOB please use a version prior to 3.0.0. You will have less functionality and a slower db but it will be human readable.

Installation

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

Usage

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

// open a collection from the base document
fishCollection := db.Collection("fish")

// open the document we want to write to
onefishDocument := fishCollection.Document("onefish")

// write the data to the document
fish := Fish{}
if err := onefishDocument.Write(fish); err != nil {
  fmt.Println("Error", err)
}

// Read a data from the database
onefish := Fish{}
if err := onefishDocument.Read(&onefish); err != nil {
  fmt.Println("Error", err)
}

// Read all fish from the database, returning an array of documents.
records, err := fishCollection.ReadAll()
if err != nil {
  fmt.Println("Error", err)
}

fishies := []Fish{}
for _, f := range records {
  fishFound := Fish{}
  if err := f.Read(&onefish); err != nil {
    fmt.Println("Error", err)
  }
  fishies = append(fishies, fishFound)
}

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

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

// Make a subcollection in a document
fishBabiesCollection := onefishDocument.Collection("babies")

// Make a make a document in a collection
firstbabyDocument := Document("firstbaby")

It is also possible to store a subcollection and data in the same document:

skrillex := db.Collection("artists").Document("skrillex")

skrillex.Write(map[string]bool{
  "IsMusicGood": true,
})

skrillex.Collection("songs").Document("bangarang").Write(map[string]string{
  "Movie": "Deadpool 2",
})

Documentation

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

Todo/Doing

  • Support for windows
  • Better support for concurrency
  • More methods to allow different types of reads/writes
  • More tests (you can never have enough!)

Documentation

Overview

Package scribble is a tiny gob database

Index

Constants

View Source
const Version = "3.0.0"

Version is the current version of the project

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

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

Collection a collection of documents

func (*Collection) Check

func (c *Collection) Check() error

Check if there is an error while getting the collection

func (*Collection) Delete

func (c *Collection) Delete() error

Delete removes a collection and all of its childeren

func (*Collection) Document

func (c *Collection) Document(key string) *Document

Document gets a document from a collection

func (*Collection) GetDocuments

func (c *Collection) GetDocuments() ([]*Document, error)

GetDocuments gets all documents in a collection.

type Document

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

Document a single document which can have sub collections

func New

func New(dir string) (*Document, 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 (*Document) Check

func (d *Document) Check() error

Check if there is an error while getting the document

func (*Document) Collection

func (d *Document) Collection(name string) *Collection

Collection gets a collction from in a document

func (*Document) Delete

func (d *Document) Delete() error

Delete locks that database and removes the document including all of its sub documents

func (*Document) Read

func (d *Document) Read(v interface{}) error

Read a record from the database

func (*Document) Write

func (d *Document) Write(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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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