store

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const BatchCount int = 100

BatchCount specifies the batch count for store operations.

Variables

View Source
var (
	ErrOpenStore  = errors.New("open store error")
	ErrCloseStore = errors.New("close store error")
)

Errors related to store operations.

Functions

This section is empty.

Types

type BadgerStore

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

BadgerStore is an implementation of the Store interface using the Badger database.

func (*BadgerStore) Add

func (s *BadgerStore) Add(updates map[string]ItemInfo) (err error)

Add adds or updates items in the Badger store. If the transaction becomes too big, it is committed, and a new transaction is started.

func (*BadgerStore) Close

func (s *BadgerStore) Close() (err error)

Close closes the Badger store.

func (*BadgerStore) Delete

func (s *BadgerStore) Delete(key string) (err error)

Delete deletes an item from the Badger store based on the key.

func (*BadgerStore) Find

func (s *BadgerStore) Find(key string) (item ItemInfo)

Find retrieves information about an item from the Badger store based on the key.

func (*BadgerStore) Info

func (s *BadgerStore) Info() string

Info returns information about the Badger store, including whether it's in-memory and the store path.

func (*BadgerStore) Items

func (s *BadgerStore) Items() (items []*ItemInfo, err error)

Items retrieves all items from the Badger store.

func (*BadgerStore) Keys

func (s *BadgerStore) Keys(prefix string, pattern string, limit int) (keys []string)

Keys retrieves keys from the Badger store based on the prefix, pattern, and limit.

func (*BadgerStore) Maintenance

func (s *BadgerStore) Maintenance()

Maintenance performs maintenance tasks on the Badger store, such as value log garbage collection.

func (*BadgerStore) Open

func (s *BadgerStore) Open() (err error)

Open opens the Badger store.

func (*BadgerStore) Reset

func (s *BadgerStore) Reset() (err error)

Reset resets the Badger store, dropping all data. TODO: Need mutex for read and writes

func (*BadgerStore) Type

func (s *BadgerStore) Type() DatabaseType

Type returns the type of the database (Badger in this case).

type DatabaseType

type DatabaseType string

DatabaseType represents the type of the database.

const BadgerDatabaseType DatabaseType = "badger"

BadgerDatabaseType represents the Badger database type.

type ItemInfo

type ItemInfo struct {
	Name     string    // Name of the item.
	Path     string    // Path to the item.
	Type     ItemType  // Type of the item.
	MimeType string    // MIME type of the item.
	ModTime  time.Time // Modification time of the item.
	Size     int64     // Size of the item.
	Hash     string    // Hash of the item.
}

ItemInfo represents information about an item in the store.

func Item

func Item(item *badger.Item) ItemInfo

Item returns an ItemInfo from a Badger item.

func NewItemInfo

func NewItemInfo(name string, path string, modTime time.Time, size int64, t ItemType) (i ItemInfo)

NewItemInfo creates a new ItemInfo with the specified attributes.

func (*ItemInfo) Decode

func (o *ItemInfo) Decode(data []byte)

Decode deserializes the item information from a byte slice.

func (*ItemInfo) Encode

func (o *ItemInfo) Encode() []byte

Encode serializes the item information to a byte slice.

func (*ItemInfo) KeyName

func (o *ItemInfo) KeyName() string

KeyName generates a key name for the item.

func (*ItemInfo) String

func (o *ItemInfo) String() string

String converts the item information to a string for hashing purposes.

func (*ItemInfo) XXhash

func (o *ItemInfo) XXhash() string

XXhash calculates and returns the XXhash of the item.

type ItemType

type ItemType string

ItemType represents the type of an item.

type Store

type Store interface {
	Open() error                                            // Open the store.
	Close() error                                           // Close the store.
	Reset() error                                           // Reset the store.
	Delete(key string) error                                // Delete a key from the store.
	Find(key string) ItemInfo                               // Find information about a key in the store.
	Info() string                                           // Get information about the store.
	Maintenance()                                           // Perform maintenance tasks on the store.
	Type() DatabaseType                                     // Get the type of the database.
	Keys(prefix string, pattern string, limit int) []string // Get keys based on prefix, pattern, and limit.

	Add(map[string]ItemInfo) error // Add items to the store.
	Items() ([]*ItemInfo, error)   // Get all items from the store. // DEBUG func
}

Store defines the interface for a key-value store.

func NewBadgerStore

func NewBadgerStore(storePath string, inMemory bool) Store

NewBadgerStore creates a new BadgerStore instance based on the provided parameters.

func NewDiskBadgerStore

func NewDiskBadgerStore(storePath string) Store

NewDiskBadgerStore creates a new BadgerStore instance for disk-based storage.

func NewInMemoryBadgerStore

func NewInMemoryBadgerStore() Store

NewInMemoryBadgerStore creates a new BadgerStore instance for in-memory storage.

func NewStore

func NewStore(c config.StoreConfig) (s Store, err error)

NewStore creates a new store based on the provided configuration.

Jump to

Keyboard shortcuts

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