models

package
v0.0.0-...-489c37e Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNotFound is returned when a resource cannot be found in the database.
	ErrNotFound     modelError = "models: resource not found"
	ErrTextRequired modelError = "models: text is required"

	// ErrIDInvalid is returned when an invalid ID is provided to a method like Update.
	ErrIDInvalid privateError = "models: ID provided was invalid"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Services

type Services struct {
	Table TableService
	// contains filtered or unexported fields
}

func NewServices

func NewServices(cfgs ...ServicesConfig) (*Services, error)

func (*Services) AutoMigrate

func (s *Services) AutoMigrate() error

AutoMigrate will attempt to automatically migrate all tables.

func (*Services) Close

func (s *Services) Close() error

Close closes the DB connections.

type ServicesConfig

type ServicesConfig func(services *Services) error

func WithGORM

func WithGORM(dsn string) ServicesConfig

func WithGORMLogMode

func WithGORMLogMode(dsn string, mode bool) ServicesConfig

func WithTable

func WithTable() ServicesConfig

type Table

type Table struct {
	ID     uuid.UUID `gorm:"type:uuid;not null;primaryKey"`
	Text   string    `gorm:"column:text;type:varchar;size:255"`
	CodeID uuid.UUID `gorm:"column:code_id;type:uuid;not null"`
	Code   uint      `gorm:"column:code;type:smallint"`
	Name   string    `gorm:"column:name;type:varchar;size:255"`
}

Table base model of data represented in DB.

type TableDB

type TableDB interface {
	SelectAll() ([]Table, error)
	ByID(id uuid.UUID) (*Table, error)
	ByCodeID(codeID uuid.UUID) ([]Table, error)
	Create(table *Table) error
	Update(table *Table) error
}

type TableService

type TableService interface {
	TableDB
}

func NewTableService

func NewTableService(db *gorm.DB) TableService

Jump to

Keyboard shortcuts

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