database
import "git.tcp.direct/tcp.direct/database"
[!WARNING]
This package is pre-v1 and the API is NOT stable!
Documentation
var ErrKeyNotFound = errors.New("key not found")
type Filer
type Filer interface {
Backend() any
Has(key []byte) bool
Get(key []byte) ([]byte, error)
Put(key []byte, value []byte) error
Delete(key []byte) error
Close() error
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() string
Init(name string, options ...any) error
With(name string) Filer
WithNew(name string, options ...any) Filer
Destroy(name string) error
Discover() ([]string, error)
AllStores() map[string]Filer
BackupAll(archivePath string) (models.Backup, error)
RestoreAll(archivePath string) error
Meta() models.Metadata
Close(name string) error
CloseAll() error
SyncAll() error
SyncAndCloseAll() 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.
- When opening a folder of Filers, it should be able to discover and initialize all of them.
- Additionally, it should be able to confirm the type of the underlying key/value store.
type KeeperCreator
type KeeperCreator func(path string) (Keeper, error)
type MockFiler
type MockFiler struct {
}
func (*MockFiler) Backend
func (m *MockFiler) Backend() any
func (*MockFiler) Close
func (m *MockFiler) Close() error
func (*MockFiler) Delete
func (m *MockFiler) Delete(key []byte) error
func (*MockFiler) Get
func (m *MockFiler) Get(key []byte) ([]byte, error)
func (*MockFiler) Has
func (m *MockFiler) Has(key []byte) bool
func (*MockFiler) Keys
func (m *MockFiler) Keys() [][]byte
func (*MockFiler) Len
func (m *MockFiler) Len() int
func (*MockFiler) Put
func (m *MockFiler) Put(key []byte, value []byte) error
func (*MockFiler) Sync
func (m *MockFiler) Sync() error
type MockKeeper
type MockKeeper struct {
}
func NewMockKeeper
func NewMockKeeper(name string) *MockKeeper
func (*MockKeeper) AllStores
func (m *MockKeeper) AllStores() map[string]Filer
func (*MockKeeper) BackupAll
func (m *MockKeeper) BackupAll(archivePath string) (models.Backup, error)
func (*MockKeeper) Close
func (m *MockKeeper) Close(name string) error
func (*MockKeeper) CloseAll
func (m *MockKeeper) CloseAll() error
func (*MockKeeper) Destroy
func (m *MockKeeper) Destroy(name string) error
func (*MockKeeper) Discover
func (m *MockKeeper) Discover() ([]string, error)
func (*MockKeeper) Init
func (m *MockKeeper) Init(name string, options ...any) error
func (*MockKeeper) Meta
func (m *MockKeeper) Meta() models.Metadata
func (*MockKeeper) Path
func (m *MockKeeper) Path() string
func (*MockKeeper) RestoreAll
func (m *MockKeeper) RestoreAll(archivePath string) error
func (*MockKeeper) SyncAll
func (m *MockKeeper) SyncAll() error
func (*MockKeeper) SyncAndCloseAll
func (m *MockKeeper) SyncAndCloseAll() error
func (*MockKeeper) With
func (m *MockKeeper) With(name string) Filer
func (*MockKeeper) WithNew
func (m *MockKeeper) WithNew(name string, options ...any) Filer
type Searcher
type Searcher interface {
PrefixScan(prefix string) (<-chan kv.KeyValue, chan error)
Search(query string) (<-chan kv.KeyValue, chan error)
ValueExists(value []byte) (key []byte, ok bool)
}
Searcher must be able to search through our datastore(s) with strings.
type Store
type Store interface {
Filer
Searcher
}
Store is an implementation of a Filer and a Searcher.