storage

package
v0.0.0-...-510a38a Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SQLITE   = "sqlite3"
	POSTGRES = "postgres"
)

Variables

This section is empty.

Functions

func Close

func Close(db *sqlx.DB) error

func ExecFile

func ExecFile(db *sqlx.DB, filePath string) error

Read SQL file from embed and execute

func MigrateDown

func MigrateDown(m *migrate.Migrate) error

func MigrateUp

func MigrateUp(dsn string) (*migrate.Migrate, error)

func Open

func Open(path string) (*sqlx.DB, error)

func OpenAndMigrateUp

func OpenAndMigrateUp(dsn string) (*sqlx.DB, error)

func Tx

func Tx(db *sqlx.DB, ctx context.Context, fn txFn) error

Functional Tx helper for multiple statements Does not allow return of objects

Types

type AuthorStore

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

func (*AuthorStore) Create

func (s *AuthorStore) Create(a *teal.Author) (*teal.Author, error)

func (*AuthorStore) Delete

func (s *AuthorStore) Delete(id int64) error

func (*AuthorStore) Get

func (s *AuthorStore) Get(id int64) (*teal.Author, error)

func (*AuthorStore) GetAll

func (s *AuthorStore) GetAll() ([]*teal.Author, error)

func (*AuthorStore) GetAllNames

func (s *AuthorStore) GetAllNames() ([]string, error)

func (*AuthorStore) GetByName

func (s *AuthorStore) GetByName(name string) (*teal.Author, error)

func (*AuthorStore) Update

func (s *AuthorStore) Update(id int64, a *teal.Author) (*teal.Author, error)

type BookQuery

type BookQuery struct {
	*teal.Book
	TotalCount   int             `db:"total_count"`
	AuthorString string          `db:"author_string"`
	GenreString  teal.NullString `db:"genre_string"`
	TagString    teal.NullString `db:"tag_string"`
}

type BookStore

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

func (*BookStore) Create

func (bs *BookStore) Create(b *teal.Book) (*teal.Book, error)

Create a book entry in books, author entries in authors and establishes the necessary book author relationships

func (*BookStore) Delete

func (bs *BookStore) Delete(id int64) error

func (*BookStore) Get

func (bs *BookStore) Get(id int64) (*teal.Book, error)

func (*BookStore) GetAll

func (bs *BookStore) GetAll(filters teal.BookFilters) ([]*teal.Book, int, error)

func (*BookStore) GetByISBN

func (bs *BookStore) GetByISBN(isbn string) (*teal.Book, error)

func (*BookStore) Update

func (bs *BookStore) Update(id int64, b *teal.Book) (*teal.Book, error)

Update book details. For authors, a new author row is created for each new author No authors are deleted, unless it has no relationship with any books

type GenreStore

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

func (*GenreStore) Create

func (s *GenreStore) Create(a *teal.Genre) (*teal.Genre, error)

func (*GenreStore) Delete

func (s *GenreStore) Delete(id int64) error

func (*GenreStore) Get

func (s *GenreStore) Get(id int64) (*teal.Genre, error)

func (*GenreStore) GetAll

func (s *GenreStore) GetAll() ([]*teal.Genre, error)

func (*GenreStore) GetAllNames

func (s *GenreStore) GetAllNames() ([]string, error)

func (*GenreStore) GetByName

func (s *GenreStore) GetByName(name string) (*teal.Genre, error)

func (*GenreStore) Update

func (s *GenreStore) Update(id int64, a *teal.Genre) (*teal.Genre, error)

type Store

type Store struct {
	Books   *BookStore
	Authors *AuthorStore
	Users   *UserStore
	Genres  *GenreStore
	Tags    *TagStore
}

func NewStore

func NewStore(db *sqlx.DB) *Store

func (*Store) GetDB

func (s *Store) GetDB() *sqlx.DB

type TagStore

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

func (*TagStore) Create

func (s *TagStore) Create(a *teal.Tag) (*teal.Tag, error)

func (*TagStore) Delete

func (s *TagStore) Delete(id int64) error

func (*TagStore) Get

func (s *TagStore) Get(id int64) (*teal.Tag, error)

func (*TagStore) GetAll

func (s *TagStore) GetAll() ([]*teal.Tag, error)

func (*TagStore) GetAllNames

func (s *TagStore) GetAllNames() ([]string, error)

func (*TagStore) GetByName

func (s *TagStore) GetByName(name string) (*teal.Tag, error)

func (*TagStore) Update

func (s *TagStore) Update(id int64, a *teal.Tag) (*teal.Tag, error)

type UserStore

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

func (*UserStore) Create

func (s *UserStore) Create(u *teal.User) (*teal.User, error)

func (*UserStore) Delete

func (s *UserStore) Delete(id int64) error

func (*UserStore) Get

func (s *UserStore) Get(id int64) (*teal.User, error)

func (*UserStore) GetByUsername

func (s *UserStore) GetByUsername(name string) (*teal.User, error)

func (*UserStore) Update

func (s *UserStore) Update(id int64, u *teal.User) (*teal.User, error)

Jump to

Keyboard shortcuts

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