store

package
v0.0.0-...-d7d6a54 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package store implements a data store for items.

Index

Constants

View Source
const (
	MovieType  = "Movie"
	TvShowType = "Tv Show"
)

Show types used to classify shows.

Variables

This section is empty.

Functions

This section is empty.

Types

type DbStore

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

DbStore wraps a database into a Store.

func New

func New(path string) (*DbStore, error)

New creates a store that uses an SQLite db. If the tables do not already exist on the db, they will be created.

func (*DbStore) All

func (s *DbStore) All() ([]*Item, error)

All returns a slice containing all the items in the store. If there are no items, the slice will have length 0.

func (*DbStore) Close

func (s *DbStore) Close() error

Close closes the store. Should be deferred. Closing the store multiple times has no effect.

func (*DbStore) Create

func (s *DbStore) Create(item *Item) error

Create adds the given item to the store.

func (*DbStore) Delete

func (s *DbStore) Delete(id uint) error

Delete deletes the item with the given id. If there is no such item, it will return an error.

func (*DbStore) Get

func (s *DbStore) Get(id uint) (*Item, error)

Get returns the item found with the given id, or an error if there is no such item.

type Item

type Item struct {
	ID     uint
	Type   string
	ShowID int
}

Item represents an item of the show list.

type Store

type Store interface {
	Close() error
	All() ([]*Item, error)
	Get(id uint) (*Item, error)
	Create(item *Item) error
	Delete(id uint) error
}

Store represents a generic data store, which can be a database, a file, and so on. The Close method should always be called to close the store.

Jump to

Keyboard shortcuts

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