kvega

package module
v0.0.0-...-5e07a61 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: EUPL-1.2 Imports: 9 Imported by: 0 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.

README

kvega

Build Lint Test Package Reference

Setup and Development

  1. mise install - Install build dependencies
  2. mise setup - Setup environment
  3. mise build - Build packages
  4. mise test - Runs tests
  5. mise testrace - Run tests with race detector enabled
  6. mise lint - Lint code
  7. mise fuzz - Fuzz test code
  8. mise bench - Benchmark code

Documentation

Overview

Package kvega provides an embedded key value database as well as acting as a Go client to a kvega database server.

Index

Examples

Constants

View Source
const Version = "0.0.1"

Version is the version of kvega.

Variables

View Source
var (
	// ErrClosed is returned when a database has been closed.
	ErrClosed = errors.New("kvega: database closed")
	// ErrNotFound is returned when a key could not be found.
	ErrNotFound = errors.New("kvega: key not found")
	// ErrEmptyKey is returned when the given key is empty.
	ErrEmptyKey = errors.New("kvega: empty key")
)

Functions

This section is empty.

Types

type Binary

type Binary = binfmt.Binary

Binary implements ValueType[[]byte] and is able to encode and decode []byte values.

type EmbeddedDB

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

EmbeddedDB is an implementation of DB that provides access to a database backed by a file stored on the local disk.

Example
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/larzconwell/kvega"
)

func main() {
	path := filepath.Join(os.TempDir(), "example.kvega")

	db, err := kvega.OpenEmbeddedDB(path)
	if err != nil {
		fmt.Println("failed to open db:", err)
		return
	}

	defer func() {
		err := db.Close()
		if err != nil {
			fmt.Println("failed to close db:", err)
		}
	}()

	err = db.Set[kvega.String]("key", "value")
	if err != nil {
		fmt.Println("failed to set key:", err)
		return
	}

	err = db.Delete("key")
	if err != nil {
		fmt.Println("failed to delete key:", err)
		return
	}

	err = db.Set[kvega.Uint]("key", 5)
	if err != nil {
		fmt.Println("failed to set key:", err)
		return
	}

	val, err := db.Get[kvega.Uint]("key")
	if err != nil {
		fmt.Println("failed to get key:", err)
		return
	}

	fmt.Println("value:", val)

}
Output:
value: 5

func OpenEmbeddedDB

func OpenEmbeddedDB(path string) (*EmbeddedDB, error)

OpenEmbeddedDB opens the database located at the given path, creating it if it doesn't exist. All writes to the database are flushed to disk at the time of the write.

The returned EmbeddedDB is safe for concurrent use by multiple goroutines, and as a result should only require one call.

The returned EmbeddedDB should be closed when finished to ensure caches are flushed.

func (*EmbeddedDB) Close

func (edb *EmbeddedDB) Close() error

Close handles flushing caches and releasing resources related to the EmbeddedDB.

ErrClosed is returned if the database has been closed.

func (*EmbeddedDB) Delete

func (edb *EmbeddedDB) Delete(key string) error

Delete handles deleting the provided key if one exists.

ErrClosed is returned if the database has been closed.

func (*EmbeddedDB) Get

func (edb *EmbeddedDB) Get[VT ValueType[T], T any](key string) (T, error)

Get returns the value that's associated with the key if one exists.

ErrNotFound is returned if the key was not found. ErrClosed is returned if the database has been closed.

func (*EmbeddedDB) Set

func (edb *EmbeddedDB) Set[VT ValueType[T], T any](key string, value T) error

Set handles setting the key to the provided value.

ErrClosed is returned if the database has been closed.

type Int

type Int = binfmt.Int

Int implements ValueType[int64] and is able to encode and decode int64 values.

type String

type String = binfmt.String

String implements ValueType[string] and is able to encode and decode string values.

type Uint

type Uint = binfmt.Uint

Uint implements ValueType[uint64] and is able to encode and decode uint64 values.

type ValueType

type ValueType[T any] = binfmt.ValueType[T]

ValueType describes a type that can encode and decode values of type T.

Directories

Path Synopsis
Package binfmt defines the binary format used for encoding and decoding rows and their data to disk as well as over the network.
Package binfmt defines the binary format used for encoding and decoding rows and their data to disk as well as over the network.

Jump to

Keyboard shortcuts

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