memorykv

package module
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: BSD-2-Clause Imports: 7 Imported by: 0

README

memorykv

In-memory key-value store implementing github.com/bborbe/kv interface.

Installation

go get github.com/bborbe/memorykv

Usage

package main

import (
    "context"
    "github.com/bborbe/kv/libkv"
    "github.com/bborbe/memorykv"
)

func main() {
    ctx := context.Background()
    
    // Open in-memory database
    db, err := memorykv.OpenMemory(ctx)
    if err != nil {
        panic(err)
    }
    defer db.Close(ctx)
    
    // Use within transactions
    err = db.Update(ctx, func(ctx context.Context, tx libkv.Tx) error {
        bucket, err := tx.CreateBucketIfNotExists(ctx, []byte("my-bucket"))
        if err != nil {
            return err
        }
        return bucket.Put(ctx, []byte("key"), []byte("value"))
    })
}

Perfect for testing and development where you need a lightweight, ephemeral key-value store that's compatible with other github.com/bborbe/kv implementations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BucketAddKey

func BucketAddKey(bucket libkv.BucketName, key []byte) []byte

func BucketRemoveKey

func BucketRemoveKey(bucket libkv.BucketName, key []byte) []byte

func BucketToPrefix

func BucketToPrefix(bucket libkv.BucketName) []byte

func IsTransactionOpen

func IsTransactionOpen(ctx context.Context) bool

func NewBucket

func NewBucket() libkv.Bucket

func NewItem

func NewItem(
	key []byte,
	valueGetter ValueGetter,
) libkv.Item

func NewIterator

func NewIterator(
	keys []string,
	valueGetter ValueGetter,
) libkv.Iterator

func NewIteratorReverse

func NewIteratorReverse(
	keys []string,
	valueGetter ValueGetter,
) libkv.Iterator

func NewTx

func NewTx() libkv.Tx

func OpenMemory

func OpenMemory(ctx context.Context) (libkv.DB, error)

func SetOpenState

func SetOpenState(ctx context.Context) context.Context

Types

type DB

type DB interface {
	libkv.DB
}

func NewDB

func NewDB() DB

type ValueGetter

type ValueGetter interface {
	Get(ctx context.Context, key []byte) (libkv.Item, error)
}

Jump to

Keyboard shortcuts

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