database

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EOF         = errors.New("No remain item to pop")
	ErrNotFound = errors.New("Could not find this key in database")
)

Functions

func BoltHandler

func BoltHandler(path string) (*bolt.DB, error)

func IsEOF

func IsEOF(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func PodKey

func PodKey(podName, podNS, sandboxId string) string

func Values

func Values[T any](kvs []*KeyValue[T]) []*T

Types

type Bolt

type Bolt[T any] struct {
	// contains filtered or unexported fields
}

func (*Bolt[T]) Close

func (b *Bolt[T]) Close() error

func (*Bolt[T]) Count

func (b *Bolt[T]) Count() (int, error)

func (*Bolt[T]) Delete

func (b *Bolt[T]) Delete(key string) error

func (*Bolt[T]) Get

func (b *Bolt[T]) Get(key string) (*T, error)

func (*Bolt[T]) List

func (b *Bolt[T]) List() ([]*KeyValue[T], error)

func (*Bolt[T]) Pop

func (b *Bolt[T]) Pop() (*KeyValue[T], error)

func (*Bolt[T]) Put

func (b *Bolt[T]) Put(key string, value *T) error

type Database

type Database[T any] interface {
	// Put a key-value. If the key is already exists, it will be replaced.
	Put(key string, value *T) error

	// Get a key-value. If the key is not exists, we will return `ErrNotFound`.
	// You can use `database.IsNotFound` to check.
	Get(key string) (*T, error)

	// Delete a key-value. If the key is not exists, we won't return error.
	Delete(key string) error

	// Pop return the first key-value, and delete it. The pop order is not
	// guaranteed (unlike traditional stack).
	// If the database is empty and no key-value to pop, this will return `EOF`
	// error, you can use `database.IsEOF` to check.
	Pop() (*KeyValue[T], error)

	// List returns all key-values in database.
	List() ([]*KeyValue[T], error)

	// Count returns the number of key-values in database.
	Count() (int, error)

	// Close closes the database.
	Close() error
}

Database is a Key-Value based database interface. It is used to store data that requires persistence. Implementations may be disk-based, or other independent databases.

func NewBolt

func NewBolt[T any](bucket string, db *bolt.DB) (Database[T], error)

type KeyValue

type KeyValue[T any] struct {
	Key   string
	Value *T
}

Jump to

Keyboard shortcuts

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