badgerfx

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const SeekEnd = byte(0xFF)

Variables

This section is empty.

Functions

func Module

func Module() fx.Option

func New

func New(config Config, logger *zapLogger) (*badger.DB, error)

Types

type BaseEntity

type BaseEntity struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

BaseEntity provides common fields for all storage entities.

type Config

type Config struct {
	// Path to the BadgerDB data directory
	Dir string
}

func (Config) Build

func (c Config) Build() badger.Options

type Entity

type Entity interface {
	StorageKey(id ...string) string
	StorageIndexes() []string

	MarshalStorage() ([]byte, error)
	UnmarshalStorage([]byte) error
}

type EntityFactory

type EntityFactory[T Entity] func() T

type Repository

type Repository[T Entity] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[T Entity](factory EntityFactory[T]) *Repository[T]

func (*Repository[T]) CreateIndexes

func (r *Repository[T]) CreateIndexes(txn *badger.Txn, entity T) error

func (*Repository[T]) Delete

func (r *Repository[T]) Delete(txn *badger.Txn, id string) error

func (*Repository[T]) DeleteIndexes

func (r *Repository[T]) DeleteIndexes(txn *badger.Txn, entity T) error

func (*Repository[T]) List

func (r *Repository[T]) List(txn *badger.Txn, prefix string, options badger.IteratorOptions) ([]T, error)

func (*Repository[T]) Read

func (r *Repository[T]) Read(txn *badger.Txn, id string) (T, error)

func (*Repository[T]) ReadByIndex

func (r *Repository[T]) ReadByIndex(txn *badger.Txn, index string) (T, error)

func (*Repository[T]) Write

func (r *Repository[T]) Write(txn *badger.Txn, entity T) error

Jump to

Keyboard shortcuts

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