Documentation
¶
Overview ¶
Package behold provides a generic key-value store with versioning and transactional capabilities. It's designed to offer a flexible interface for managing data with type safety using Go's generics.
Index ¶
- Variables
- func Eq[T comparable](a, b T) bool
- func EqFn[T any](a, b T, cmp CompFunc[T]) bool
- func EqFn2[T any](a, b T, eq CondFunc[T]) bool
- func Gt[T core.Ordered](a, b T) bool
- func GtEq[T core.Ordered](a, b T) bool
- func GtEqFn[T any](a, b T, cmp CompFunc[T]) bool
- func GtEqFn2[T any](a, b T, less CondFunc[T]) bool
- func GtFn[T any](a, b T, cmp CompFunc[T]) bool
- func Lt[T core.Ordered](a, b T) bool
- func LtEq[T core.Ordered](a, b T) bool
- func LtEqFn[T any](a, b T, cmp CompFunc[T]) bool
- func LtEqFn2[T any](a, b T, less CondFunc[T]) bool
- func LtFn[T any](a, b T, cmp CompFunc[T]) bool
- func LtFn2[T any](a, b T, less CondFunc[T]) bool
- func NotEq[T comparable](a, b T) bool
- func NotEqFn[T any](a, b T, cmp CompFunc[T]) bool
- func NotEqFn2[T any](a, b T, eq CondFunc[T]) bool
- type CompFunc
- type CondFunc
- type MatchFunc
- type Matcher
- func ComposeMatch[T any, V any](fn func(T) (V, bool), match Matcher[V]) Matcher[T]
- func MatchAll[T any](queries ...Matcher[T]) Matcher[T]
- func MatchAny[T any](queries ...Matcher[T]) Matcher[T]
- func MatchEq[T comparable](v T) Matcher[T]
- func MatchEqFn[T any](v T, cmp CompFunc[T]) Matcher[T]
- func MatchEqFn2[T any](v T, eq CondFunc[T]) Matcher[T]
- func MatchGt[T core.Ordered](v T) Matcher[T]
- func MatchGtEq[T core.Ordered](v T) Matcher[T]
- func MatchGtEqFn[T core.Ordered](v T, cmp CompFunc[T]) Matcher[T]
- func MatchGtEqFn2[T core.Ordered](v T, less CondFunc[T]) Matcher[T]
- func MatchGtFn[T core.Ordered](v T, cmp CompFunc[T]) Matcher[T]
- func MatchLt[T core.Ordered](v T) Matcher[T]
- func MatchLtEq[T core.Ordered](v T) Matcher[T]
- func MatchLtEqFn[T core.Ordered](v T, cmp CompFunc[T]) Matcher[T]
- func MatchLtEqFn2[T any](v T, less CondFunc[T]) Matcher[T]
- func MatchLtFn[T core.Ordered](v T, cmp CompFunc[T]) Matcher[T]
- func MatchLtFn2[T core.Ordered](v T, less CondFunc[T]) Matcher[T]
- func MatchNotEq[T comparable](v T) Matcher[T]
- func MatchNotEqFn[T any](v T, cmp CompFunc[T]) Matcher[T]
- func MatchNotEqFn2[T any](v T, eq CondFunc[T]) Matcher[T]
- type Mutex
- type RWMutex
- type Store
- type Tx
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("closed")
ErrClosed is an error indicating that an object or resource is closed and cannot be used
var ErrInvalid = core.ErrInvalid
ErrInvalid is an error indicating an invalid state or argument
var ErrNilReceiver = core.ErrNilReceiver
ErrNilReceiver is an error indicating a nil receiver was passed to a method
var ErrReadOnlyTx = errors.New("read-only transaction")
ErrReadOnlyTx is an error indicating an attempt to modify a read-only transaction
Functions ¶
func Eq ¶
func Eq[T comparable](a, b T) bool
Eq returns true if a is equal to b for comparable types.
func EqFn ¶
EqFn returns true if a is equal to b using a custom comparison function. It panics if the provided comparison function is nil.
func EqFn2 ¶ added in v0.0.2
EqFn2 returns true if a is equal to b using a custom equality function. It panics if the provided equality function is nil.
func GtEqFn ¶
GtEqFn returns true if a is greater than or equal to b using a custom comparison function. It panics if the provided comparison function is nil.
func GtEqFn2 ¶ added in v0.0.2
GtEqFn2 returns true if a is greater than or equal to b using a custom less-than condition function. It panics if the provided less-than condition function is nil.
func GtFn ¶
GtFn returns true if a is greater than b using a custom comparison function. It panics if the provided comparison function is nil.
func LtEqFn ¶
LtEqFn returns true if a is less than or equal to b using a custom comparison function. It panics if the provided comparison function is nil.
func LtEqFn2 ¶ added in v0.0.3
LtEqFn2 returns true if a is less than or equal to b using a custom less-than condition function. It panics if the provided less-than condition function is nil.
func LtFn ¶
LtFn returns true if a is less than b using a custom comparison function. It panics if the provided comparison function is nil.
func LtFn2 ¶ added in v0.0.2
LtFn2 returns true if a is less than b using a custom less-than condition function. It panics if the provided less-than condition function is nil.
func NotEq ¶
func NotEq[T comparable](a, b T) bool
NotEq returns true if a is not equal to b for comparable types.
Types ¶
type CompFunc ¶
CompFunc is a generic comparison function that takes two values of type T and returns an integer. The return value follows the standard comparison convention: - Negative value if a < b - Zero if a == b - Positive value if a > b
type CondFunc ¶ added in v0.0.2
CondFunc is a generic condition function that takes two values of type T and returns a boolean. The return value indicates whether the condition is true or false for the given pair of values.
type MatchFunc ¶ added in v0.0.3
MatchFunc is a function type that implements the Matcher interface. It allows simple functions to be used as matchers.
func (MatchFunc[T]) And ¶ added in v0.0.3
And combines this query function with others using logical AND.
type Matcher ¶ added in v0.0.3
type Matcher[T any] interface { // And combines this query with others using logical AND. // All conditions must match for the combined query to match. And(...Matcher[T]) Matcher[T] // Or combines this query with others using logical OR. // At least one condition must match for the combined query to match. Or(...Matcher[T]) Matcher[T] // Match tests if the given value satisfies this query's conditions. Match(T) bool }
Matcher is a generic interface for filtering and combining predicates of type T. It allows logical AND and OR operations between conditions, and matching against a value.
func ComposeMatch ¶ added in v0.0.3
ComposeMatch creates a new Matcher by applying an accessor function to transform input values before matching against an existing matcher. It allows composing matchers on different types by first extracting a specific field or transforming the input. Panics if the accessor function or the base query is nil.
func MatchAll ¶
MatchAll returns a query that matches if all of the provided queries match. If no queries are provided, the result will match everything (return true). Nil queries in the provided list are ignored during matching.
func MatchAny ¶
MatchAny returns a query that matches if any of the provided queries match. If no queries are provided, the result will match nothing (return false). Nil queries in the provided list are ignored during matching.
func MatchEq ¶ added in v0.0.3
func MatchEq[T comparable](v T) Matcher[T]
MatchEq creates a Matcher that checks for equality with the given value. It returns a function that returns true if the input is equal to the specified value.
func MatchEqFn ¶ added in v0.0.3
MatchEqFn creates a Matcher that checks for equality using a custom comparison function. It returns a function that returns true if the input is equal to the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchEqFn2 ¶ added in v0.0.3
MatchEqFn2 creates a Matcher that checks for equality using a custom equality function. It returns a function that returns true if the input is equal to the specified value according to the provided equality function. Panics if the equality function is nil.
func MatchGt ¶ added in v0.0.3
MatchGt creates a Matcher that checks if a value is strictly greater than the given value. It returns a function that returns true if the input is greater than the specified value.
func MatchGtEq ¶ added in v0.0.3
MatchGtEq creates a Matcher that checks if a value is greater than or equal to the given value. It returns a function that returns true if the input is greater than or equal to the specified value.
func MatchGtEqFn ¶ added in v0.0.3
MatchGtEqFn creates a Matcher that checks if a value is greater than or equal to the given value using a custom comparison function. It returns a function that returns true if the input is greater than or equal to the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchGtEqFn2 ¶ added in v0.0.3
MatchGtEqFn2 creates a Matcher that checks if a value is greater than or equal to the given value using a custom condition function. It returns a function that returns true if the input is greater than or equal to the specified value according to the provided condition function. Panics if the condition function is nil.
func MatchGtFn ¶ added in v0.0.3
MatchGtFn creates a Matcher that checks if a value is strictly greater than the given value using a custom comparison function. It returns a function that returns true if the input is greater than the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchLt ¶ added in v0.0.3
MatchLt creates a Matcher that checks if a value is strictly less than the given value. It returns a function that returns true if the input is less than the specified value.
func MatchLtEq ¶ added in v0.0.3
MatchLtEq creates a Matcher that checks if a value is less than or equal to the given value. It returns a function that returns true if the input is less than or equal to the specified value.
func MatchLtEqFn ¶ added in v0.0.3
MatchLtEqFn creates a Matcher that checks if a value is less than or equal to the given value using a custom comparison function. It returns a function that returns true if the input is less than or equal to the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchLtEqFn2 ¶ added in v0.0.3
MatchLtEqFn2 creates a Matcher that checks if a value is less than or equal to the given value using a custom condition function. It returns a function that returns true if the input is less than or equal to the specified value according to the provided condition function. Panics if the condition function is nil.
func MatchLtFn ¶ added in v0.0.3
MatchLtFn creates a Matcher that checks if a value is strictly less than the given value using a custom comparison function. It returns a function that returns true if the input is less than the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchLtFn2 ¶ added in v0.0.3
MatchLtFn2 creates a Matcher that checks if a value is strictly less than the given value using a custom condition function. It returns a function that returns true if the input is less than the specified value according to the provided condition function. Panics if the condition function is nil.
func MatchNotEq ¶ added in v0.0.3
func MatchNotEq[T comparable](v T) Matcher[T]
MatchNotEq creates a Matcher that checks for inequality with the given value. It returns a function that returns true if the input is not equal to the specified value.
func MatchNotEqFn ¶ added in v0.0.3
MatchNotEqFn creates a Matcher that checks for inequality using a custom comparison function. It returns a function that returns true if the input is not equal to the specified value according to the provided comparison function. Panics if the comparison function is nil.
func MatchNotEqFn2 ¶ added in v0.0.3
MatchNotEqFn2 creates a Matcher that checks for inequality using a custom equality function. It returns a function that returns true if the input is not equal to the specified value according to the provided equality function. Panics if the equality function is nil.
type Mutex ¶
type Mutex interface {
Lock()
TryLock() bool
Unlock()
}
Mutex defines a standard interface for mutual exclusion locking mechanisms that support basic locking, unlocking, and non-blocking lock attempts.
type RWMutex ¶
RWMutex extends the Mutex interface with read-locking capabilities, allowing multiple readers or a single writer to access a shared resource.
type Store ¶
type Store[K comparable, V any] interface { // Version returns the current version of the data in the Store. Version() uint64 // Now returns the store's current time reference Now() time.Time // View executes a read-only transaction with optional mutex locks // The provided function will be called with a transaction object that // can be used to access data in the store View(ctx context.Context, fn func(Tx[K, V]) error, locks ...Mutex) error // Update executes a read-write transaction with optional mutex locks // The provided function will be called with a transaction object that // can be used to access and modify data in the store Update(ctx context.Context, fn func(Tx[K, V]) error, locks ...Mutex) error // Close closes the store and releases its resources Close() error }
Store represents a generic key-value store with versioning and transaction support. It provides a clean interface for working with data in a consistent manner.
Type Parameters:
- K comparable: The key type, which must be comparable (supports == and != operators)
- V any: The value type, which can be any type
type Tx ¶
type Tx[K comparable, V any] interface { // Context returns the transaction's context Context() context.Context // Version returns the data version accessed by this transaction. Version() uint64 // Now returns the transaction's time reference Now() time.Time // ForEach iterates through key-value pairs matching optional queries // The provided function is called for entries matching any of the queries, // or for every entry if no queries are provided. // Iteration can be ended early by returning false from the callback. ForEach(fn func(key K, value V) bool, ors ...Matcher[any]) error // Get retrieves a value by key Get(key K) (value V, err error) // Set associates a value with a key Set(key K, value V) error // Append adds a value to an existing key (implementation depends on value type) Append(key K, value V) error // Delete removes a key-value pair Delete(key K) error // Commit persists changes made within the transaction Commit() error // Close aborts the transaction if not already committed Close() error }
Tx represents a transaction within the key-value store. It provides methods for reading, writing, and managing data within a transactional context.
Type Parameters:
- K comparable: The key type, matching the store's key type
- V any: The value type, matching the store's value type