storage

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package storage provides a generic storage interface and its implementations.

Package storage provides a generic storage interface and its implementations.

Package storage provides a generic storage interface and its implementations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrToDoNotFound indicates that a requested ToDo item cannot be found.
	ErrToDoNotFound = errors.New("requested ToDo item not found")
)

Functions

func NewMariaDB

func NewMariaDB(config MariaDBConfig) (*mariaDB, error)

NewMariaDB creates a new MariaDB connection using the given configuration.

func NewMemory

func NewMemory() *memory

NewMemory creates an in-memory storage living as long as the server process.

Types

type MariaDBConfig

type MariaDBConfig struct {
	User     string
	Password string
	Address  string
	DBName   string
}

MariaDBConfig stores configuration values for connecting to the MariaDB host.

func (MariaDBConfig) URI

func (m MariaDBConfig) URI() string

URI yields a connection string in the form <user>:<password>@<host>:<port>/.

type Storage

type Storage interface {

	// Initialize initializes the storage if it hasn't been set up yet. Methods
	// like CreateToDo must be safe to call after running Initialize.
	//
	// For example, a SQL storage implementation should creates the required
	// database and tables if they don't exist yet.
	Initialize() error

	// CreateToDo stores a new ToDo item and returns the inserted entity.
	CreateToDo(toDo model.ToDo) (model.ToDo, error)

	// FindToDos returns a list of all stored ToDo items.
	FindToDos() ([]model.ToDo, error)

	// FindToDoById returns the ToDo item with the given ID. In case the item
	// cannot be found, an error will be returned.
	FindToDoByID(id int64) (model.ToDo, error)

	// UpdateToDo overwrites the ToDo item with the given ID. In case the item
	// cannot be found, an error will be returned.
	UpdateToDo(id int64, toDo model.ToDo) error

	// DeleteToDo deletes the ToDo item with the given ID. In case the item
	// cannot be found, an error will be returned.
	DeleteToDo(id int64) error

	// Remove removes the storage. It is the inverse operation of Initialize.
	// Must be called before Close when wiping a storage.
	Remove() error

	// Close closes handles and other resources like database connections.
	Close() error
}

Storage represents a storage backend.

Jump to

Keyboard shortcuts

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