models

package
v0.0.0-...-352e712 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB() *gorm.DB

GetDB returns the connection

func InsertAuthor

func InsertAuthor(author Author)

InsertAuthor insert a new author in DB

func InsertBook

func InsertBook(book Book) error

InsertBook insert a new author in DB

Types

type Author

type Author struct {
	ID        uint   `gorm:"primary_key"`
	Firstname string `json:"FirstName"`
	Lastname  string `json:"LastName"`
}

Author represents an author or creator of the book

func GetAuthor

func GetAuthor(id int) (Author, error)

GetAuthor return an Author given its id

func GetAuthors

func GetAuthors() []Author

GetAuthors return all the books existing in DB

func (*Author) TableName

func (*Author) TableName() string

TableName change the by-dafault name of the table

type Book

type Book struct {
	Isbn     string `gorm:"primary_key" json:"ISBN"`
	Name     string `json:"name"`
	Author   Author `gorm:"foreignkey:AuthorID" json:",omitempty"`
	AuthorID uint   `json:"-"`
}

Book entity

func GetBook

func GetBook(id int) (Book, error)

GetBook return an Author given its ISBN

func GetBooks

func GetBooks() []Book

GetBooks return all the books existing in DB

func (*Book) TableName

func (*Book) TableName() string

TableName change the by-dafault name of the table

Jump to

Keyboard shortcuts

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