crud

package
v0.13.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MongoCollectionPrefix = "cnab_"

MongoCollectionPrefix is applied to every collection.

Variables

View Source
var ErrRecordDoesNotExist = errors.New("File does not exist")

ErrRecordDoesNotExist represents when file path is not found on file system

Functions

This section is empty.

Types

type BackingStore

type BackingStore struct {

	// AutoClose specifies if the connection should be automatically
	// closed when done accessing the backing store.
	AutoClose bool
	// contains filtered or unexported fields
}

BackingStore wraps another store that may have Connect/Close methods that need to be called. - Connect is called before a method when the connection is closed. - Close is called after each method when AutoClose is true (default).

func NewBackingStore

func NewBackingStore(store Store) *BackingStore

func (*BackingStore) Close

func (s *BackingStore) Close() error

func (*BackingStore) Connect

func (s *BackingStore) Connect() error

func (*BackingStore) Delete

func (s *BackingStore) Delete(itemType string, name string) error

func (*BackingStore) GetDataStore

func (s *BackingStore) GetDataStore() Store

GetStore returns the data store, e.g. filesystem, mongodb, managed by this wrapper.

func (*BackingStore) HandleConnect

func (s *BackingStore) HandleConnect() (func() error, error)

func (*BackingStore) List

func (s *BackingStore) List(itemType string, group string) ([]string, error)

func (*BackingStore) Read

func (s *BackingStore) Read(itemType string, name string) ([]byte, error)

func (*BackingStore) ReadAll

func (s *BackingStore) ReadAll(itemType string, group string) ([][]byte, error)

ReadAll retrieves all the items with the specified prefix

func (*BackingStore) Save

func (s *BackingStore) Save(itemType string, group string, name string, data []byte) error

type FileSystemStore

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

func NewFileSystemStore

func NewFileSystemStore(baseDirectory string, fileExtensions map[string]string) FileSystemStore

NewFileSystemStore creates a Store backed by a file system directory. Each key is represented by a file in that directory. - baseDirectory: the base directory under which files should be stored, e.g. /Users/carolynvs/.cnab - fileExtensions: map from item types (e.g. "claims") to the file extension that should be used (e.g. ".json")

func (FileSystemStore) Delete

func (s FileSystemStore) Delete(itemType string, name string) error

func (FileSystemStore) List

func (s FileSystemStore) List(itemType string, group string) ([]string, error)

func (FileSystemStore) Read

func (s FileSystemStore) Read(itemType string, name string) ([]byte, error)

func (FileSystemStore) Save

func (s FileSystemStore) Save(itemType string, group string, name string, data []byte) error

type HasClose

type HasClose interface {
	Close() error
}

HasClose indicates that a struct must be cleaned up using the Close method before the interface's methods are called.

type HasConnect

type HasConnect interface {
	Connect() error
}

HasConnect indicates that a struct must be initialized using the Connect method before the interface's methods are called.

type MockStore

type MockStore struct {

	// DeleteMock replaces the default Delete implementation with the specified function.
	// This allows for simulating failures.
	DeleteMock func(itemType string, name string) error

	// ListMock replaces the default List implementation with the specified function.
	// This allows for simulating failures.
	ListMock func(itemType string, group string) ([]string, error)

	// ReadMock replaces the default Read implementation with the specified function.
	// This allows for simulating failures.
	ReadMock func(itemType string, name string) ([]byte, error)

	// SaveMock replaces the default Save implementation with the specified function.
	// This allows for simulating failures.
	SaveMock func(itemType string, name string, data []byte) error
	// contains filtered or unexported fields
}

MockStore is an in-memory store with optional mocked functionality that is intended for use with unit testing.

func NewMockStore

func NewMockStore() MockStore

func (MockStore) Close

func (s MockStore) Close() error

func (MockStore) Connect

func (s MockStore) Connect() error

func (MockStore) Delete

func (s MockStore) Delete(itemType string, name string) error

func (MockStore) GetCloseCount

func (s MockStore) GetCloseCount() (int, error)

GetCloseCount is for tests to safely read the Close call count without accidentally triggering it by using Read.

func (MockStore) GetConnectCount

func (s MockStore) GetConnectCount() (int, error)

GetConnectCount is for tests to safely read the Connect call count without accidentally triggering it by using Read.

func (MockStore) List

func (s MockStore) List(itemType string, group string) ([]string, error)

func (MockStore) Read

func (s MockStore) Read(itemType string, name string) ([]byte, error)

func (MockStore) ResetCounts

func (s MockStore) ResetCounts()

func (MockStore) Save

func (s MockStore) Save(itemType string, group string, name string, data []byte) error

type Store

type Store interface {
	List(itemType string, group string) ([]string, error)
	Save(itemType string, group string, name string, data []byte) error
	Read(itemType string, name string) ([]byte, error)
	Delete(itemType string, name string) error
}

Store is a simplified interface to a key-blob store supporting CRUD operations.

func NewMongoDBStore

func NewMongoDBStore(url string) Store

NewMongoDBStore creates a new storage engine that uses MongoDB

The URL provided must point to a MongoDB server and database.

Jump to

Keyboard shortcuts

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