pkg

package
v0.0.0-...-15eb0b2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = badger.ErrKeyNotFound
)

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	// Put saves val by key
	Put(key, val []byte, opts ...PutOption) error
	// PutVal saves value and return auto inc id (binary with big endian)
	// Do not use it with Put func in the same bucket
	// Items may be overwritten with auto generated key
	PutVal(val []byte, opts ...PutOption) ([]byte, error)
	// Get gets val by key
	Get(key []byte) ([]byte, *Meta, error)
	// GetAt gets val from offset, it returns num of bytes
	// It returns io.EOF if no bytes were read
	GetAt(key, buf []byte, offset int) (int, error)
	// GetMeta returns meta info
	// It returns nil, nil when there is no meta
	GetMeta(key []byte) (*Meta, error)
	// Exists check if key exists
	Exists(key []byte) (bool, error)
	// Delete removes val by key
	Delete(key []byte) error
	// Range returns iterator for [beginKey, endKey), all for nil, nil
	Range(beginKey, endKey []byte, reverse bool) (Iterator, error)
	// Count returns item count of [beginKey, endKey), all for nil, nil
	Count(beginKey, endKey []byte) (int, error)
}

type ChunkKey

type ChunkKey = []byte

type DB

type DB interface {
	// CreateNamespace creates or gets namespace
	CreateNamespace(name []byte) (Namespace, error)
	// DeleteNamespace deletes namespace by name and all data in the namespace
	DeleteNamespace(name []byte) error
	// Compact do flush and compaction on db
	Compact() error
	// Close release db lock
	Close() error
}

func New

func New(path string, opts ...Option) (DB, error)

type DocBucket

type DocBucket interface {
	Bucket
	PutDoc(key []byte, val Item) error
	GetDoc(key []byte) (Item, error)
	Find(Query) (DocIterator, error)
}

type DocIterator

type DocIterator interface {
	Iterator
	ValueDoc() (Item, error)
}

type Item

type Item = bson.M

type Iterator

type Iterator interface {
	Next() bool
	Key() ([]byte, error)
	Value() ([]byte, error)
	Err() error
	Release() error
}

type Logger

type Logger = badger.Logger

type Meta

type Meta struct {
	// inputs
	// mine type: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
	Mime string `json:"mime"`
	// chunk size in bytes, value will split to chunk when it is set
	ChunkSize int `json:"chunkSize"`

	// outputs
	// value len in bytes, it will automatically set
	TotalLen int `json:"totalLen"`
	// chunk list keys
	Chunks []ChunkKey `json:"chunks"`
}

type MetaPrefix

type MetaPrefix = byte

type Namespace

type Namespace interface {
	// DocBucket returns builtin bucket for saving main docs
	DocBucket() DocBucket
	// ObjectBucket returns builtin bucket for saving binary resources
	ObjectBucket() Bucket
	// CreateBucket creates or gets bucket
	CreateBucket(name []byte) (Bucket, error)
	// CreateDocBucket creates or gets doc bucket
	CreateDocBucket(name []byte) (DocBucket, error)
	// DeleteBucket deletes bucket by name and all data in the bucket
	DeleteBucket(name []byte) error
	// ListBucket gets all user buckets
	ListBucket() ([]string, error)
}

type Option

type Option func(*dbOption)

func ReadOnly

func ReadOnly() Option

func WithLogger

func WithLogger(l Logger) Option

type PutOption

type PutOption func(*putOption)

func WithMeta

func WithMeta(meta *Meta) PutOption

type Query

type Query = bson.D

type Resource

type Resource = []byte

type Resources

type Resources map[string]Resource

Jump to

Keyboard shortcuts

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