Go to file
kayos@tcp.direct 374ca0d5fb
Feat: Discover automatically recovers from bad meta.json
2024-01-28 21:10:36 -08:00
.github/workflows CI: Add pre-coverage test check for output purposes 2022-06-10 11:06:03 -07:00
bitcask Feat: Discover automatically recovers from bad meta.json 2024-01-28 21:10:36 -08:00
kv Docs: refresh markdown 2022-07-25 21:57:01 -07:00
.gitignore Chore: lint 2022-07-23 18:07:09 -07:00
LICENSE fix go.mod path, etc 2022-05-21 16:03:59 -07:00
README.md Docs: refresh markdown 2022-08-29 00:44:21 -07:00
filer.go Add: interface methods + Fix: testing 2022-08-28 23:36:37 -07:00
go.mod Fix: go mod retract 2024-01-28 20:41:49 -08:00
go.sum Fix: nil bitcask store during withnew when store exists 2023-11-27 16:02:42 -08:00
keeper.go Feat: DB.Discover() 2024-01-28 20:36:59 -08:00
searcher.go Add: interface methods + Fix: testing 2022-08-28 23:36:37 -07:00
store.go Add: interface methods + Fix: testing 2022-08-28 23:36:37 -07:00


Coverage Build Status

import "git.tcp.direct/tcp.direct/database"


type Filer

type Filer interface {

	// Backend returns the underlying key/value store.
	Backend() any

	// Has should return true if the given key has an associated value.
	Has(key []byte) bool
	// Get should retrieve the byte slice corresponding to the given key, and any associated errors upon failure.
	Get(key []byte) ([]byte, error)
	// Put should insert the value data in a way that is associated and can be retrieved by the given key data.
	Put(key []byte, value []byte) error
	// Delete should delete the key and the value associated with the given key, and return an error upon failure.
	Delete(key []byte) error
	// Close should safely end any Filer operations of the given dataStore and close any relevant handlers.
	Close() error
	// Sync should take any volatile data and solidify it somehow if relevant. (ram to disk in most cases)
	Sync() error

	Keys() [][]byte
	Len() int

Filer is is a way to implement any generic key/value store. These functions should be plug and play with most of the popular key/value store golang libraries.

NOTE: Many key/value golang libraries will already implement this interface already. This exists for more potential granular control in the case that they don't. Otherwise you'd have to build a wrapper around an existing key/value store to satisfy an overencompassing interface.

type Keeper

type Keeper interface {
	// Path should return the base path where all stores should be stored under. (likely as subdirectories)
	Path() string
	// Init should initialize our Filer at the given path, to be referenced and called by dataStore.
	Init(name string, options ...any) error
	// With provides access to the given dataStore by providing a pointer to the related Filer.
	With(name string) Store

	AllStores() map[string]Filer

	CloseAll() error
	SyncAll() error

Keeper will be in charge of the more meta operations involving Filers. This includes operations like initialization, syncing to disk if applicable, and backing up.

type Searcher

type Searcher interface {
	// PrefixScan must retrieve all keys in the datastore and stream them to the given channel.
	PrefixScan(prefix string) (<-chan *kv.KeyValue, chan error)
	// Search must be able to search through the value contents of our database and stream the results to the given channel.
	Search(query string) (<-chan *kv.KeyValue, chan error)
	// ValueExists searches for an exact match of the given value and returns the key that contains it.
	ValueExists(value []byte) (key []byte, ok bool)

Searcher must be able to search through our datastore(s) with strings.

type Store

type Store interface {

Store is an implementation of a Filer and a Searcher.