jsondb

package module
v0.0.0-...-089cf83 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 12 Imported by: 1 module, 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

jsondb

JSONDB

Example usage:

package main

import (
	"fmt"
	"os"

	"github.com/rocksolidlabs/jsondb"
	"github.com/sirupsen/logrus"
)

var log = &logrus.Logger{}

type Person struct {
	ID    string
	FName string
	LName string
	Age   int
}

func main() {

	host := os.Args[1]
	username := os.Args[2]
	password := os.Args[3]

	db, err := jsondb.NewJSONDBWithSftpReplication(".", host, username, password, log, true)
	if err != nil {
		panic(err)
	}

	person := &Person{
		ID:    jsondb.GenIDFromSeeed("PhenixRizen"),
		FName: "Phenix",
		LName: "Rizen",
		Age:   96,
	}

	err = db.Put("people", person.ID, person)
	if err != nil {
		panic(err)
	}

	person = &Person{
		ID:    jsondb.GenIDFromSeeed("PhenixFallen"),
		FName: "Phenix",
		LName: "Fallen",
		Age:   69,
	}

	err = db.Put("people", person.ID, person)
	if err != nil {
		panic(err)
	}

	var people []*Person
	err = db.GetWhere("people", "FName", "Phenix", &people, -1)

	for _, p := range people {
		fmt.Printf("Name: %s %s, Age: %d\n", p.FName, p.LName, p.Age)
	}

}

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Variables

This section is empty.

Functions

func GenID

func GenID(idSize int) string

Simple ID Generating function

func GenIDFromSeeed

func GenIDFromSeeed(seed string) string

Simple ID Generating function from seed

Types

type JSONDB

type JSONDB struct {
	Trace  bool
	Logger *logger.Logger
	Dir    string
	// contains filtered or unexported fields
}

func NewJSONDB

func NewJSONDB(datadir string, log *logger.Logger, trace bool) (*JSONDB, error)

Create a new JSONDB instance using os FS

func (*JSONDB) Delete

func (db *JSONDB) Delete(collection, resource string) error

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

func (*JSONDB) Get

func (db *JSONDB) Get(collection, resource string, record interface{}) error

Get a record from the database and marshal it to the passed object

func (*JSONDB) GetAll

func (db *JSONDB) GetAll(collection string, records interface{}) error

GetAll records from a collection; this populates the passed slice with records

func (*JSONDB) GetBytes

func (db *JSONDB) GetBytes(collection, resource string) ([]byte, error)

Get a record from the database and return the JSON byte array

func (*JSONDB) GetWhere

func (db *JSONDB) GetWhere(collection, query string, expression, records interface{}, limit int64) error

GetWhere records from a collection where the query path equals the expression; this populates the passed slice with records

func (*JSONDB) GetWhereNot

func (db *JSONDB) GetWhereNot(collection, query string, expression, records interface{}, limit int64) error

GetWhereNot records from a collection where the query path does not equal the expression; this populates the passed slice with records

func (*JSONDB) InitCollection

func (db *JSONDB) InitCollection(collection string) error

InitCollection creates a collection in the JSONDB

func (db *JSONDB) Link(srcCollection, srcResource, destCollection, destResource string) error

Link locks that database and then creates a link to a existing resource

func (*JSONDB) Put

func (db *JSONDB) Put(collection, resource string, v interface{}) error

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

func (*JSONDB) Stat

func (db *JSONDB) Stat(path string) (fi os.FileInfo, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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