Documentation ¶
Index ¶
- type Mode
- type Repository
- type Store
- func (s *Store) Contains(key []byte) (bool, error)
- func (s *Store) DropAll() error
- func (s *Store) Get(key []byte, value any) (bool, error)
- func (s *Store) Keys() ([][]byte, error)
- func (s *Store) KeysCount() (int, error)
- func (s *Store) Name() string
- func (s *Store) Put(key []byte, value any) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Mode ¶
type Mode uint8
Mode identifies the strategy adopted by Repositories and Stores in respect to the data from disk.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
A Repository of key-value Stores persisted on disk.
func NewRepository ¶
func NewRepository(path string, mode Mode) (*Repository, error)
NewRepository returns a Repository bound to data located on disk at the given path, handled according to the specified mode.
In ReadWriteMode, if the directory named path does not exist, it is created along with any necessary parents, setting its permissions bits to 0755 (rwxr-xr-x).
Once you are done with its usage, it's important to call Repository.Close to ensure that any pending update on the repository's Stores is persisted to disk.
func (*Repository) Close ¶
func (r *Repository) Close() error
Close flushes pending updates of all previously used stores (if any), and closes any binding with data on disk, also freeing internal resources.
In case of failures, the first error encountered is returned, aborting the closing operation; if this happens, not all stores might have been closed and flushed properly.
This must be the last operation performed after using a Repository and its stores. You must be sure that no Store object obtained before performing this operation will be used thereafter.
func (*Repository) DropAll ¶
func (r *Repository) DropAll() (err error)
DropAll removes all data and drops all stores.
Before proceeding with data removal, any existing binding with files on disk is first closed. To avoid errors or unexpected behaviors, you must be sure that no Store object obtained before performing this operation will be used thereafter.
This operation internally loops through each previously open store. In case of failures, the first error encountered is returned, aborting the operation; if this happens, not all stores might have been dropped properly.
func (*Repository) Store ¶
func (r *Repository) Store(name string) (store.Store, error)
Store returns an on-disk data store by name.
In ReadWriteMode, getting a store for the first time will cause its creation. In ReadOnlyMode, you can only get existing stores, otherwise an error is returned.
Getting a store will cause the creation of a binding with the underlying data on disk. Getting the same store more than once will return the same underlying object and data binding (the operation is idempotent).
Once you are done using all stores from a Repository, remember to call Repository.Close to ensure all data is correctly written on disk and resources are freed.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
A Store is an on-disk key-value database.
func (*Store) DropAll ¶
DropAll drops all data from the store.
It panics in read-only mode.
New readings performed during this operation may result in panics.
func (*Store) Get ¶
Get attempts to fetch the value associated with the key, assigning it to the given parameter, and returns a flag which reports whether the key has been found or not.