crud

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2021 License: MIT Imports: 11 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) Count added in v0.14.0

func (s *BackingStore) Count(itemType string, group string) (int, 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) Count added in v0.14.0

func (s FileSystemStore) Count(itemType string, group string) (int, error)

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 ManagedStore added in v0.14.0

type ManagedStore interface {
	// Store is the underlying datastore.
	Store

	// ReadAll retrieves all the items with the optional item type.
	ReadAll(itemType string, group string) ([][]byte, error)

	// GetDataStore returns the datastore managed by this instance.
	GetDataStore() Store

	// HandleConnect connects if necessary, returning a function to close the
	// connection. This close function may be a no-op when connection was
	// already established and this call to Connect isn't managing the
	// connection.
	HandleConnect() (func() error, error)
}

ManagedStore is a wrapped crud.Store with a managed connection lifecycle.

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) Count added in v0.14.0

func (s MockStore) Count(itemType string, group string) (int, 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 {
	// Count the number of items of the optional type and group.
	Count(itemType string, group string) (int, error)

	// List the names of the items of the optional type and group.
	List(itemType string, group string) ([]string, error)

	// Save an item's data using the specified name with optional metadata
	// identifying it with an item type and group.
	Save(itemType string, group string, name string, data []byte) error

	// Read the data for a named item of the optional type.
	Read(itemType string, name string) ([]byte, error)

	// Delete a named item of the optional type.
	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