jsondb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2020 License: MIT Imports: 16 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) FuncMap
func (d *DB) FuncMap() template.FuncMap

FuncMap is a database enabled template parser

func (*DB) Get
func (d *DB) Get(tenant, bucket string) ([]Record, error)

Get returns an array of records within the target bucket.

func (*DB) GetContains
func (d *DB) GetContains(tenant, bucket, contains string) ([]Record, error)

GetContains returns a array of records within a bucket that have keys that contain the input string.

func (*DB) GetKey
func (d *DB) GetKey(tenant, bucket string, key string) (Record, error)

GetKey gets the JSON object by key from the target bucket

func (*DB) GetPattern
func (d *DB) GetPattern(tenant, bucket, regex string) ([]Record, error)

GetPattern returns a array of records within a bucket that have keys that match the regex pattern.

func (*DB) KeyExists
func (d *DB) KeyExists(tenant, bucket string, key string) bool

KeyExists returns true if the key is within the target bucket

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

LoadBackup 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(records []Record) error

SetMany sets each record in the database under its key

func (*DB) Start
func (d *DB) Start(ctx context.Context) error

Start starts the database & garbage collection

func (*DB) Subscribe
func (d *DB) Subscribe(sub SubscriptionOpts) error
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"`
	Tenant      string            `json:"tenant"`
	Bucket      string            `json:"bucket"`
	Value       gjson.Result      `json:"value"`
	Metadata    map[string]string `json:"metadata"`
	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 NewObjectRecord
func NewObjectRecord(tenant, bucket, key string, object interface{}, expires int64) Record
func NewRecord
func NewRecord(tenant, bucket, key string, value []byte, expires int64) Record

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

func (Record) Clone
func (r Record) Clone() Record
func (Record) Pointer
func (r Record) Pointer() *Record
type SubscriptionOpts
type SubscriptionOpts struct {
	Id         string
	Tenant     string   // tenant is required if not global
	Buckets    []string // at least one bucket if not global
	TargetKeys []string // if specified, only keys within this array will be streamed
	Global     bool     // subscribe to all buckets
	// Handler is executed on filtered records after they are created.
	Handler func(r Record)
}

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) FuncMap

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

FuncMap is a database enabled template parser

func (*DB) Get

func (d *DB) Get(tenant, bucket string) ([]Record, error)

Get returns an array of records within the target bucket.

func (*DB) GetContains added in v1.0.0

func (d *DB) GetContains(tenant, bucket, contains string) ([]Record, error)

GetContains returns a array of records within a bucket that have keys that contain the input string.

func (*DB) GetKey added in v1.0.0

func (d *DB) GetKey(tenant, bucket string, key string) (Record, error)

GetKey gets the JSON object by key from the target bucket

func (*DB) GetPattern added in v1.0.0

func (d *DB) GetPattern(tenant, bucket, regex string) ([]Record, error)

GetPattern returns a array of records within a bucket that have keys that match the regex pattern.

func (*DB) KeyExists added in v1.0.0

func (d *DB) KeyExists(tenant, bucket string, key string) bool

KeyExists returns true if the key is within the target bucket

func (*DB) LoadBackup

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

LoadBackup 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(records []Record) error

SetMany sets each record in the database under its key

func (*DB) Start

func (d *DB) Start(ctx context.Context) error

Start starts the database & garbage collection

func (*DB) Subscribe added in v1.0.0

func (d *DB) Subscribe(sub SubscriptionOpts) error

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"`
	Tenant      string            `json:"tenant"`
	Bucket      string            `json:"bucket"`
	Value       gjson.Result      `json:"value"`
	Metadata    map[string]string `json:"metadata"`
	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 NewObjectRecord added in v1.0.0

func NewObjectRecord(tenant, bucket, key string, object interface{}, expires int64) Record

func NewRecord

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

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

func (Record) Clone added in v0.0.2

func (r Record) Clone() Record

func (Record) Pointer added in v0.0.2

func (r Record) Pointer() *Record

type SubscriptionOpts added in v1.0.0

type SubscriptionOpts struct {
	Id         string
	Tenant     string   // tenant is required if not global
	Buckets    []string // at least one bucket if not global
	TargetKeys []string // if specified, only keys within this array will be streamed
	Global     bool     // subscribe to all buckets
	// Handler is executed on filtered records after they are created.
	Handler func(r Record)
}

Directories

Path Synopsis
gen

Jump to

Keyboard shortcuts

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