diskstore

package
v1.9.13-beta2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiskStore

type DiskStore[V any] struct {
	// contains filtered or unexported fields
}

DiskStore is a generic file-per-record store on disk. Each record is stored as a JSON file keyed by primary key.

func NewDiskStore

func NewDiskStore[V any](baseDir string, entityName string) (*DiskStore[V], error)

NewDiskStore creates a new DiskStore. The baseDir/entityName directory is created if it does not exist.

func (*DiskStore[V]) Delete

func (d *DiskStore[V]) Delete(key string) error

Delete removes a record from disk.

func (*DiskStore[V]) List

func (d *DiskStore[V]) List() ([]string, error)

List returns all keys in the store, sorted alphabetically.

func (*DiskStore[V]) Read

func (d *DiskStore[V]) Read(key string) (V, error)

Read reads a record from disk and unmarshals it.

func (*DiskStore[V]) Scan

func (d *DiskStore[V]) Scan(fn func(key string, value V) error) error

Scan iterates over all records in sorted key order, calling fn for each. If fn returns an error, iteration stops and the error is returned.

func (*DiskStore[V]) Write

func (d *DiskStore[V]) Write(key string, value V) error

Write marshals the value to JSON and writes it to disk. The write is atomic: it writes to a temp file then renames.

Jump to

Keyboard shortcuts

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