repo

package
v0.0.0-...-6621fb8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect() (*gorm.DB, error)

Connect to the database If the database does not exist it will be created

func Migrate

func Migrate(db *gorm.DB) error

Migrate perform database migrations

Types

type Ingredient

type Ingredient struct {
	Amount string
	Name   string
}

type Ingredients

type Ingredients map[string]Ingredient

func (*Ingredients) Scan

func (i *Ingredients) Scan(src any) error

Scan implements sql.Scanner

func (Ingredients) Value

func (i Ingredients) Value() (driver.Value, error)

Value implements driver.Valuer

type Recipe

type Recipe struct {
	juniper.Model

	Slug        string `gorm:"uniqueIndex"`
	Title       string
	Description string `gorm:"type:text"`
	Image       string
	PrepTime    time.Duration
	CookTime    time.Duration

	Ingredients Ingredients
	Steps       RecipeSteps
}

Recipe is the database model for recipes

type RecipeRepo

type RecipeRepo interface {
	FindById(ctx context.Context, id any) (*Recipe, error)
	FindBySlug(ctx context.Context, slug string) (*Recipe, error)
	Create(ctx context.Context, recipe *Recipe) error
	Update(ctx context.Context, recipe *Recipe) error
}

func NewRecipeSqlRepo

func NewRecipeSqlRepo(fallbackDB *gorm.DB) RecipeRepo

NewRecipeSqlRepo creates a new instance of the RecipeSqlRepo struct

type RecipeSqlRepo

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

func (RecipeSqlRepo) Create

func (r RecipeSqlRepo) Create(ctx context.Context, recipe *Recipe) error

Create adds a new recipe to the database

func (RecipeSqlRepo) FindById

func (r RecipeSqlRepo) FindById(ctx context.Context, id any) (*Recipe, error)

FindById finds a recipe by its unique id

func (RecipeSqlRepo) FindBySlug

func (r RecipeSqlRepo) FindBySlug(ctx context.Context, slug string) (*Recipe, error)

FindBySlug finds a recipe by its unique slug

func (RecipeSqlRepo) Update

func (r RecipeSqlRepo) Update(ctx context.Context, recipe *Recipe) error

Update updates a recipe in the database

type RecipeStep

type RecipeStep struct {
	Ingredients []string
	Time        time.Duration
	Text        string
}

type RecipeSteps

type RecipeSteps []RecipeStep

func (*RecipeSteps) Scan

func (r *RecipeSteps) Scan(src any) error

Scan implements sql.Scanner

func (RecipeSteps) Value

func (r RecipeSteps) Value() (driver.Value, error)

Value implements driver.Valuer

Jump to

Keyboard shortcuts

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