Documentation ¶
Overview ¶
Package storage ...
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidTodoID = errors.New("invalid todo ID")
ErrInvalidTodoID is returned when the ID sent for fetching/updating/etc a Todo is not a valid Todo in our datastore.
Functions ¶
This section is empty.
Types ¶
type Db ¶
Db provides a set of methods for interacting with our database.
func NewDB ¶
NewDB creates a connection with our postgres database and returns it, otherwise an error.
func (*Db) CreateTodo ¶
CreateTodo handles inserting a new Todo in the database with the caller's provided content.
func (*Db) DeleteTodo ¶
DeleteTodo deletes a Todo by its ID.
func (*Db) UpdateTodo ¶
UpdateTodo finds a Todo by it's ID and updates its contents. Postgres trigger functions handle assigning a new timestamp to updated_at.
type Todo ¶
type Todo struct { ID int `json:"id,omitempty"` Content string `json:"content,omitempty" gator:"nonzero"` CreatedAt string `json:"created_at,omitempty"` UpdatedAt string `json:"updated_at,omitempty"` CompletedAt string `json:"completed_at,omitempty"` }
Todo represents a Todo in in our datastore.
type TodoRepository ¶
type TodoRepository interface { GetTodo(id string) (Todo, error) CreateTodo(content string) (int, error) UpdateTodo(id, content, completedAt string) error ListTodos() ([]Todo, error) DeleteTodo(id string) error }
TodoRepository describes the interface for interacting with our datastore. This can viewed like a plug in adapter, making testing and/or switching datastores much more trivial.