db

package module
v0.0.0-...-c5043c6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger sets logger for the package.

Types

type ContextLogger

type ContextLogger interface {
	Debugf(ctx context.Context, format string, args ...interface{})
	Infof(ctx context.Context, format string, args ...interface{})
	Warningf(ctx context.Context, format string, args ...interface{})
	Errorf(ctx context.Context, format string, args ...interface{})
}

ContextLogger interface used in this package with request context.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type DB

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

DB is leveldb implementation of keyup.DocumentStore

func NewDB

func NewDB() *DB

NewDB creates a DB.

func (*DB) Close

func (d *DB) Close()

Close closes an open db

func (*DB) Collections

func (d *DB) Collections(ctx context.Context, parent string) (keyup.CollectionIterator, error)

Collections ...

func (*DB) Count

func (d *DB) Count(ctx context.Context, prefix string, contains string) (int, error)

Count returns number of docs in a collection with prefix and filter. This iterates over the prefixed docs to count them.

func (*DB) Create

func (d *DB) Create(ctx context.Context, path string, b []byte) error

Create entry.

Example
db := NewDB()
defer db.Close()
if err := db.OpenAtPath("/tmp/keyup.db"); err != nil {
	log.Fatal(err)
}

if err := db.Create(context.TODO(), "/test/1", []byte{0x01, 0x02, 0x03}); err != nil {
	log.Fatal(err)
}
Output:

func (*DB) Delete

func (d *DB) Delete(ctx context.Context, path string) (bool, error)

Delete value at path.

func (*DB) DeleteAll

func (d *DB) DeleteAll(ctx context.Context, parent string) error

DeleteAll deletes values with key prefix.

func (*DB) Documents

func (d *DB) Documents(ctx context.Context, parent string, opts *keyup.DocumentsOpts) (keyup.DocumentIterator, error)

Documents ...

func (*DB) Exists

func (d *DB) Exists(ctx context.Context, path string) (bool, error)

Exists returns true if the db row exists at path

func (*DB) Get

func (d *DB) Get(ctx context.Context, path string) (*keyup.Document, error)

Get entry at path.

Example
db := NewDB()
defer db.Close()
dir, err := ioutil.TempDir("", "keyup")
if err != nil {
	log.Fatal(err)
}
path := filepath.Join(dir, "keyup.db")
if err := db.OpenAtPath(path); err != nil {
	log.Fatal(err)
}

if err := db.Create(context.TODO(), "/test/1", []byte{0x01, 0x02, 0x03}); err != nil {
	log.Fatal(err)
}

doc, err := db.Get(context.TODO(), "/test/1")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("%s\n", doc.Path)
fmt.Printf("%v\n", doc.Data)
Output:

/test/1
[1 2 3]

func (*DB) GetAll

func (d *DB) GetAll(ctx context.Context, paths []string) ([]*keyup.Document, error)

GetAll paths.

func (*DB) IsOpen

func (d *DB) IsOpen() bool

IsOpen returns true if db is open

func (*DB) Last

func (d *DB) Last(ctx context.Context, prefix string) (*keyup.Document, error)

Last returns last item with key prefix.

func (*DB) Now

func (d *DB) Now() time.Time

Now returns current time.

func (*DB) OpenAtPath

func (d *DB) OpenAtPath(path string) error

OpenAtPath opens db located at path

Example
db := NewDB()
defer db.Close()
if err := db.OpenAtPath("/tmp/keyup.db"); err != nil {
	log.Fatal(err)
}
Output:

func (*DB) Set

func (d *DB) Set(ctx context.Context, path string, b []byte) error

Set saves document to the db at key.

func (*DB) SetTimeNow

func (d *DB) SetTimeNow(nowFn func() time.Time)

SetTimeNow sets clock.

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0
)

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger interface used in this package.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

Jump to

Keyboard shortcuts

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