model

package
v0.0.0-...-7f8a11e Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilDatabase error = errors.New("database connection is nil")
)

Functions

func Initialize

func Initialize(dbConn *gorm.DB) (err error)

func UUIDToBIN

func UUIDToBIN(s string) ([]byte, error)

Types

type Author

type Author struct {
	Base
	Name  string `json:"name" gorm:"unique"`
	Books []Book `json:"books,omitempty" gorm:"many2many:author_books;"`
}

func (Author) All

func (Author) All() (authors []Author, err error)

func (Author) FindByID

func (Author) FindByID(id UUID) (author Author, err error)

type AuthorBook

type AuthorBook struct {
	AuthorID  UUID           `gorm:"primaryKey"`
	BookID    UUID           `gorm:"primaryKey"`
	CreatedAt time.Time      `gorm:"not null"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

func (AuthorBook) Create

func (AuthorBook) Create(authorID, bookID UUID) (err error)

type Base

type Base struct {
	ID        UUID           `json:"id" gorm:"primary_key;"`
	CreatedAt time.Time      `json:"-"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

func (*Base) BeforeCreate

func (b *Base) BeforeCreate(tx *gorm.DB) error

type Book

type Book struct {
	Base
	Name            string   `json:"name" gorm:"unique"`
	Edition         string   `json:"edition"`
	PublicationYear int      `json:"publication_year"`
	Authors         []Author `json:"authors,omitempty" gorm:"many2many:author_books;"`
}

func (Book) All

func (Book) All() (books []Book, err error)

func (*Book) Create

func (b *Book) Create() (err error)

func (*Book) Delete

func (b *Book) Delete() (err error)

func (Book) FindByID

func (Book) FindByID(id string) (book Book, err error)

func (*Book) Update

func (b *Book) Update() (err error)

type UUID

type UUID uuid.UUID

func ParseUUID

func ParseUUID(id string) UUID

func (UUID) GormDataType

func (field UUID) GormDataType() string

func (UUID) MarshalJSON

func (field UUID) MarshalJSON() ([]byte, error)

func (*UUID) Scan

func (field *UUID) Scan(value interface{}) (err error)

func (UUID) String

func (field UUID) String() string

func (*UUID) UnmarshalJSON

func (field *UUID) UnmarshalJSON(bytes []byte) (err error)

func (UUID) Value

func (field UUID) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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