storage

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: MIT Imports: 5 Imported by: 1

README

go-storage

Supported engines

  • Memory
  • Json file
  • Etcd

Usage

import "github.com/rafalb8/go-storage/engine/jsondb"

func connect() {
    db, err := jsondb.New(jsondb.File("/path/to/file.json"))
    // handle err ...

    // Set key in db
    db.Set("key", "value")

    val, err := helpers.Get[string](db, "key")
    // handle db err ...

    // print value
    fmt.Println(val)
}

Planned features

  • JsonDB in multiple files

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("obj not found")
)

Functions

This section is empty.

Types

type Bucket

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

func NewBucket

func NewBucket(conn Connection, keys ...string) *Bucket

func (Bucket) Bucket

func (b Bucket) Bucket(bucket ...string) *Bucket

func (*Bucket) DecodeValue

func (b *Bucket) DecodeValue(c encoding.ValueCoder, data []byte) error

func (Bucket) Delete

func (b Bucket) Delete(k string) error

func (Bucket) EncodeValue

func (b Bucket) EncodeValue(c encoding.ValueCoder) ([]byte, error)

func (Bucket) Encoding

func (b Bucket) Encoding() encoding.Coder

func (Bucket) Exists

func (b Bucket) Exists(k string) bool

func (Bucket) Get

func (b Bucket) Get(k string, v any) error

func (Bucket) Iter

func (b Bucket) Iter(ctx context.Context, pfx string) types.Iterator[string, []byte]

func (Bucket) Keys

func (b Bucket) Keys() ([]string, error)

func (Bucket) Len

func (b Bucket) Len() (int, error)

func (Bucket) Prefix

func (b Bucket) Prefix() string

func (Bucket) PrintDebug

func (b Bucket) PrintDebug() error

func (Bucket) Set

func (b Bucket) Set(k string, v any, op ...Option) error

func (Bucket) Tx

func (b Bucket) Tx(fn func(tx Transactioner) error) error

func (Bucket) Values

func (b Bucket) Values() ([][]byte, error)

func (Bucket) Watch

func (b Bucket) Watch(ctx context.Context, k string) types.Watcher[string, []byte]

type Bucketer

type Bucketer interface {
	Getter
	Setter
	Deleter

	Watcher
	Iterator
	Transactioner

	Prefix() string
	Bucket(bucket ...string) *Bucket
	Encoding() encoding.Coder
	Tx(fn func(tx Transactioner) error) error

	Len() (int, error)
	Keys() ([]string, error)
	PrintDebug() error

	// Returns Raw unmarshaled bytes. Recomended to use with helpers.Values[T]
	Values() ([][]byte, error)
}

type Connection

type Connection interface {
	Getter
	Setter
	Deleter

	Watcher
	Iterator
	Transactioner

	// Close connection
	Close()

	Bucket(bucket ...string) *Bucket
	Encoding() encoding.Coder
	Tx(pfx string, fn func(tx Transactioner) error) error

	Len(pfx string) (int, error)
	Keys(pfx string) ([]string, error)
	PrintDebug(pfx string) error

	// Returns Raw unmarshaled bytes. Recomended to use with helpers.Values[T]
	Values(pfx string) ([][]byte, error)
}

type Deleter

type Deleter interface {
	Delete(k string) error
}

type Getter

type Getter interface {
	Exists(k string) bool
	Get(k string, v any) error
}

type Iterator

type Iterator interface {
	// Returns Raw unmarshaled bytes. Recomended to use with helpers.NewIter[T]
	Iter(ctx context.Context, pfx string) types.Iterator[string, []byte]
}

type Logger added in v0.1.1

type Logger interface {
	Debug(args ...any)
	Warn(args ...any)
	Info(args ...any)
	Error(args ...any)
	Fatal(args ...any)
}

type Option

type Option interface{}

Set option, for use with etcd

type Setter

type Setter interface {
	Set(k string, v any, op ...Option) error
}

type Transactioner

type Transactioner interface {
	Getter
	Setter
	Deleter
	Iterator
	Encoding() encoding.Coder
}

type Watcher

type Watcher interface {
	// Returns Raw unmarshaled bytes. Recomended to use with helpers.NewWatcher[T]
	Watch(ctx context.Context, pfx string) types.Watcher[string, []byte]
}

Directories

Path Synopsis
key
engine
net

Jump to

Keyboard shortcuts

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