jsondb

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 7 Imported by: 0

README

jsondb

-- import "github.com/autom8ter/jsondb"

Usage

type DB
type DB struct {
}

DB is an embedded JSON database

func NewDB
func NewDB(o *Opts) (*DB, error)

NewDB creates a new DB with the given options.

func (*DB) Backup
func (d *DB) Backup(w io.Writer, sinceUnix int64) (int64, error)

Backup dumps a protobuf-encoded list of all entries in the database into the given writer, that are newer than the specified version. It returns a timestamp indicating when the entries were dumped which can be passed into a later invocation to generate an incremental dump

func (*DB) Close
func (d *DB) Close() func()

Close closes all channels then shuts down the database

func (*DB) Exists
func (d *DB) Exists(key string) bool

Exists returns true if the key has been set in the database

func (*DB) FuncMap
func (d *DB) FuncMap() template.FuncMap

FuncMap is a database enabled template parser

func (*DB) Get
func (d *DB) Get(key string) (Record, error)

Get gets the JSON object by key

func (*DB) GetMany
func (d *DB) GetMany(keys []string) (map[string]Record, error)

GetMany returns a map of records that have keys that exactly match the input keys. The database key is the index on the returned map.

func (*DB) GetPrefix
func (d *DB) GetPrefix(prefix string) (map[string]Record, error)

GetPrefix returns a map of records that have keys that match the prefix pattern. The database key is the index on the returned map.

func (*DB) GetRegex
func (d *DB) GetRegex(meta byte, regex string) (map[string]Record, error)

GetRegex returns a map of records that have keys that match the regex pattern. The database key is the index on the returned map.

func (*DB) LoadBackup
func (d *DB) LoadBackup(r io.Reader, maxPendingBytes int64) error

Load reads a protobuf-encoded list of all entries from a reader and writes them to the database.

func (*DB) PublishChan
func (d *DB) PublishChan(channel string, record Record)

PublishChan publishes the record to the given channel

func (*DB) Set
func (d *DB) Set(r Record) error

Set sets the given record under its key

func (*DB) SetMany
func (d *DB) SetMany(jsonMap map[string]Record) error

SetMany sets each record in the database under its key

func (*DB) Start
func (d *DB) Start() error

Start starts the database & garbage collection

func (*DB) SubscribeChan
func (d *DB) SubscribeChan(ctx context.Context, channel string, handler func(record Record))

SubscribeChan creates a subscription to the given channel

type Opts
type Opts struct {
	InMem bool
	Path  string
}

Opts holds configuration options for creating a DB

type Record
type Record struct {
	Key         string       `json:"key"`
	Value       gjson.Result `json:"value"`
	ExpiresUnix int64        `json:"expiresUnix"`
}

Record is a stored json object. The key is what may be used later to query the JSON object from the database.

func NewRecord
func NewRecord(key string, value []byte, expires int64) Record

New Record creates a record from the given key, json value, and exipiration unix.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is an embedded JSON database

func NewDB

func NewDB(o *Opts) (*DB, error)

NewDB creates a new DB with the given options.

func (*DB) Backup

func (d *DB) Backup(w io.Writer, sinceUnix int64) (int64, error)

Backup dumps a protobuf-encoded list of all entries in the database into the given writer, that are newer than the specified version. It returns a timestamp indicating when the entries were dumped which can be passed into a later invocation to generate an incremental dump

func (*DB) Close

func (d *DB) Close() func()

Close closes all channels then shuts down the database

func (*DB) Exists

func (d *DB) Exists(key string) bool

Exists returns true if the key has been set in the database

func (*DB) FuncMap

func (d *DB) FuncMap() template.FuncMap

FuncMap is a database enabled template parser

func (*DB) Get

func (d *DB) Get(key string) (Record, error)

Get gets the JSON object by key

func (*DB) GetMany

func (d *DB) GetMany(keys []string) (map[string]Record, error)

GetMany returns a map of records that have keys that exactly match the input keys. The database key is the index on the returned map.

func (*DB) GetPrefix

func (d *DB) GetPrefix(prefix string) (map[string]Record, error)

GetPrefix returns a map of records that have keys that match the prefix pattern. The database key is the index on the returned map.

func (*DB) GetRegex

func (d *DB) GetRegex(meta byte, regex string) (map[string]Record, error)

GetRegex returns a map of records that have keys that match the regex pattern. The database key is the index on the returned map.

func (*DB) LoadBackup

func (d *DB) LoadBackup(r io.Reader, maxPendingBytes int64) error

Load reads a protobuf-encoded list of all entries from a reader and writes them to the database.

func (*DB) Set

func (d *DB) Set(r Record) error

Set sets the given record under its key

func (*DB) SetMany

func (d *DB) SetMany(jsonMap map[string]Record) error

SetMany sets each record in the database under its key

func (*DB) Start

func (d *DB) Start() error

Start starts the database & garbage collection

type Opts

type Opts struct {
	InMem bool
	Path  string
}

Opts holds configuration options for creating a DB

type Record

type Record struct {
	Key         string       `json:"key"`
	Value       gjson.Result `json:"value"`
	ExpiresUnix int64        `json:"expiresUnix"`
}

Record is a stored json object. The key is what may be used later to query the JSON object from the database.

func NewRecord

func NewRecord(key string, value []byte, expires int64) Record

New Record creates a record from the given key, json value, and exipiration unix.

Jump to

Keyboard shortcuts

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