storage

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrISBNExists indicates a book with the given ISBN was already in the library.
	ErrISBNExists = errors.New("the ISBN was already in the library")

	// ErrISBNNotFound indicates a book with the given ISBN was not found in the library.
	ErrISBNNotFound = errors.New("the ISBN was not found in the library")
)
View Source
var (

	// ErrNotWriteOperation indicates that the given input string was not a known write operation.
	ErrNotWriteOperation = errors.New("the input string was not a known write operation")
)

Functions

This section is empty.

Types

type BookStore

type BookStore interface {

	// Close closes the connection to the underlying storage.
	Close(ctx context.Context) (err error)

	// Delete deletes the Book data for the given ISBNs. There will be no error if the ISBNs are not found.
	Delete(ctx context.Context, isbns []string) (err error)

	// Read reads the Book data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBNs is not found.
	Read(ctx context.Context, isbns []string) (books map[string]models.Book, err error)

	// Write writes the given Book data. It will return ErrISBNExists for in Insert operation where the ISBN already
	// exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
	Write(ctx context.Context, books []models.Book, operation WriteOperation) (err error)
}

BookStore is the Book data storage interface. It allows for Book data storage operations without needing to know how the Book data are stored.

func NewMemBook

func NewMemBook() (bookStore BookStore)

NewMemBook creates a new MemBook.

type MemBook

type MemBook struct {
	// contains filtered or unexported fields
}

MemBook is a BookStore implementation that stores everything in a Go map in memory.

func (*MemBook) Close

func (m *MemBook) Close(_ context.Context) (err error)

Close closes the connection to the underlying storage.

func (*MemBook) Delete

func (m *MemBook) Delete(_ context.Context, isbns []string) (err error)

Delete deletes the Book data for the given ISBNs. There will be no error if the ISBNs are not found.

func (*MemBook) Read

func (m *MemBook) Read(_ context.Context, isbns []string) (books map[string]models.Book, err error)

Read reads the Book data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBNs is not found.

func (*MemBook) Write

func (m *MemBook) Write(_ context.Context, books []models.Book, operation WriteOperation) (err error)

Write writes the given Book data. It will return ErrISBNExists for in Insert operation where the ISBN already exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.

type MemStatus

type MemStatus struct {
	// contains filtered or unexported fields
}

MemStatus is a StatusStore implementation that stores everything in a Go map in memory.

func (*MemStatus) Close

func (m *MemStatus) Close(_ context.Context) (err error)

Close closes the connection to the underlying storage.

func (*MemStatus) Delete

func (m *MemStatus) Delete(_ context.Context, isbns []string) (err error)

Delete deletes the Status data for the ISBNs. There will be no error if the ISBNs are not found.

func (*MemStatus) Read

func (m *MemStatus) Read(_ context.Context, isbns []string) (statuses map[string]models.History, err error)

Read reads the Status data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBN is not found.

func (*MemStatus) Write

func (m *MemStatus) Write(_ context.Context, statuses map[string]models.History, operation WriteOperation) (err error)

Write writes the given Status data. It will return ErrISBNExists for in Insert operation where the ISBN already exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.

type StatusStore

type StatusStore interface {

	// Close closes the connection to the underlying storage.
	Close(ctx context.Context) (err error)

	// Delete deletes the Status data for the ISBNs. There will be no error if the ISBNs are not found.
	Delete(ctx context.Context, isbns []string) (err error)

	// Read reads the Status data for the given ISBNs. The error ErrISBNNotFound will be given if an ISBN is not found.
	Read(ctx context.Context, isbns []string) (books map[string]models.History, err error)

	// Write writes the given Status data. It will return ErrISBNExists for in Insert operation where the ISBN already
	// exists and an ErrISBNNotFound if an Update operation has an ISBN that doesn't exist.
	Write(ctx context.Context, statuses map[string]models.History, operation WriteOperation) (err error)
}

StatusStore is the Status data storage interface. It allows for Book data storage operations without needing to know how the Book data are stored.

func NewMemStatus

func NewMemStatus() (statusStore StatusStore)

NewMemStatus creates a new MemStatus.

type WriteOperation

type WriteOperation uint

WriteOperation indicates the type of write operation.

const (

	// Insert indicates an insertion write operation. It will fail if the target already exists.
	Insert WriteOperation = iota

	// Update indicates an update write operation. It will fail if the target does not exist.
	Update

	// Upsert indicates an upsert write operation. It will be performed if the target exists or does not exist.
	Upsert
)

func (WriteOperation) FromString

func (w WriteOperation) FromString(s string) (operation WriteOperation, err error)

FromString will determine what write operation should take place based on the input string.

Jump to

Keyboard shortcuts

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