constellation/coordinator/store/store.go
Leonard Cohnen 2d8fcd9bf4 monorepo
Co-authored-by: Malte Poll <mp@edgeless.systems>
Co-authored-by: katexochen <katexochen@users.noreply.github.com>
Co-authored-by: Daniel Weiße <dw@edgeless.systems>
Co-authored-by: Thomas Tendyck <tt@edgeless.systems>
Co-authored-by: Benedict Schlueter <bs@edgeless.systems>
Co-authored-by: leongross <leon.gross@rub.de>
Co-authored-by: Moritz Eckert <m1gh7ym0@gmail.com>
2022-03-22 16:09:39 +01:00

56 lines
1.5 KiB
Go

package store
import (
"fmt"
)
// Store is the interface for persistence.
type Store interface {
// BeginTransaction starts a new transaction.
BeginTransaction() (Transaction, error)
// Get returns a value from store by key.
Get(string) ([]byte, error)
// Put saves a value to store by key.
Put(string, []byte) error
// Iterator returns an Iterator for a given prefix.
Iterator(string) (Iterator, error)
// Transfer copies the whole store Database.
Transfer(Store) error
// Delete deletes the key.
Delete(string) error
}
// Transaction is a Store transaction.
type Transaction interface {
// Get returns a value from store by key.
Get(string) ([]byte, error)
// Put saves a value to store by key.
Put(string, []byte) error
// Delete deletes the key.
Delete(string) error
// Iterator returns an Iterator for a given prefix.
Iterator(string) (Iterator, error)
// Commit ends a transaction and persists the changes.
Commit() error
// Rollback aborts a transaction. Noop if already committed.
Rollback()
}
// Iterator is an iterator for the store.
type Iterator interface {
// GetNext returns the next element of the iterator.
GetNext() (string, error)
// HasNext returns true if there are elements left to get with GetNext().
HasNext() bool
}
// StoreValueUnsetError is an error raised by unset values in the store.
type StoreValueUnsetError struct {
requestedValue string
}
// Error implements the Error interface.
func (s *StoreValueUnsetError) Error() string {
return fmt.Sprintf("store: requested value not set: %s", s.requestedValue)
}