diskstore

package module
v0.0.0-...-8f17065 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2023 License: BSD-2-Clause Imports: 10 Imported by: 2

Documentation

Index

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.

const (
	// ReadWriteMode allows full reading and writing access to data stored on
	// disk. If no data exists yet, a new blank store is created.
	ReadWriteMode Mode = iota
	// ReadOnlyMode provides read-only access.
	// If no data exists yet on disk, an error is reported.
	ReadOnlyMode
)

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) Contains

func (s *Store) Contains(key []byte) (bool, error)

Contains reports whether the given key is found in the store.

func (*Store) DropAll

func (s *Store) DropAll() error

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

func (s *Store) Get(key []byte, value any) (bool, error)

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.

func (*Store) Keys

func (s *Store) Keys() ([][]byte, error)

Keys returns all the keys from the store.

func (*Store) KeysCount

func (s *Store) KeysCount() (int, error)

KeysCount reports how many key/value pairs are in the store.

func (*Store) Name

func (s *Store) Name() string

The Name of the store.

func (*Store) Put

func (s *Store) Put(key []byte, value any) (err error)

Put sets a key/value pair in the store. If a value for the same key already exists in the store, it is overwritten with the new value.

Jump to

Keyboard shortcuts

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