jsondb

package
Version: v0.0.0-...-d78814b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: GPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package jsondb implements a flat file JSON database engine.

Package jsondb implements a flat file JSON database engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CacheTimeout is how long the Redis cache keys live for in seconds, default 2 hours.
	CacheTimeout = 60 * 60 * 2
	CacheLock    sync.RWMutex
)
View Source
var (
	ErrNotFound = errors.New("document not found")
)

Error codes returned.

Functions

func SetDebug

func SetDebug(debug bool)

SetDebug turns on debug logging.

Types

type DB

type DB struct {
	Root  string        // The root directory of the database
	Cache caches.Cacher // A cacher for the JSON documents, i.e. Redis
}

DB is the database manager.

func New

func New(root string) *DB

New initializes the JSON database.

func (*DB) Commit

func (db *DB) Commit(document string, v interface{}) error

Commit writes a JSON object to the database.

func (*DB) Delete

func (db *DB) Delete(document string) error

Delete removes a JSON document from the database.

func (*DB) DeleteCache

func (db *DB) DeleteCache(key string) error

DeleteCache deletes a cache key.

func (*DB) Exists

func (db *DB) Exists(document string) bool

Exists tells you whether a document exists in the database.

func (*DB) Get

func (db *DB) Get(document string, v interface{}) error

Get a document by path and load it into the object `v`.

func (*DB) GetCache

func (db *DB) GetCache(key string) (string, error)

GetCache gets a cache key.

func (*DB) List

func (db *DB) List(path string) ([]string, error)

List all the documents at the path given.

func (*DB) ListAll

func (db *DB) ListAll(path string) ([]string, error)

ListAll recursively lists the documents at the path prefix given.

func (*DB) LockCache

func (db *DB) LockCache(key string) bool

LockCache implements 'file locking' in your cache.

func (*DB) SetCache

func (db *DB) SetCache(key, value string, expires int) error

SetCache sets a cache key.

func (*DB) SetJSONCache

func (db *DB) SetJSONCache(key string, v interface{}, expires int) error

SetJSONCache caches a JSON object.

func (*DB) UnlockCache

func (db *DB) UnlockCache(key string)

UnlockCache releases the lock on a cache key.

func (*DB) WithCache

func (db *DB) WithCache(cache caches.Cacher) *DB

WithCache configures a memory cacher for the JSON documents.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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