models

package
v0.0.0-...-749cb02 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteBook

func DeleteBook(id int, db *gorm.DB) error

DeleteBook deletes a book from the DB by given ID

func GetBooks

func GetBooks(db *gorm.DB) (*[]Book, error)

GetBooks returns all the books

Types

type Book

type Book struct {
	gorm.Model
	Title  string `gorm:"size:100;not null;unique" json:"title"`
	Author string `gorm:"not null" json:"author"`
	Year   string `gorm:"not null" json:"year"`
}

Book model

func GetBookByID

func GetBookByID(id int, db *gorm.DB) (*Book, error)

GetBookByID returns a book by its ID

func (*Book) GetBook

func (b *Book) GetBook(db *gorm.DB) (*Book, error)

GetBook returns the book

func (*Book) Prepare

func (b *Book) Prepare()

Prepare strips book inputs of any white space

func (*Book) Save

func (b *Book) Save(db *gorm.DB) (*Book, error)

Save stores the book object in the DB

func (*Book) UpdateBook

func (b *Book) UpdateBook(id int, db *gorm.DB) (*Book, error)

UpdateBook updates the provided book in the DB

func (*Book) Validate

func (b *Book) Validate() error

Validate validates the inputs

Jump to

Keyboard shortcuts

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