recipe

package
v0.0.0-...-5ac2c70 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateTable

func CreateTable(db *sql.DB) error

func Get

func Get(diet models.DietType) models.Recipe

func GetAllRecipesFromDB

func GetAllRecipesFromDB(db *sql.DB) ([]models.Recipe, error)

GetAllRecipesFromDB function executes a SQL SELECT statement to fetch all rows from the recipes table. It iterates over the rows, scans the values into a Recipe struct, and unmarshals the ingredientsJSON and directionsJSON into their respective fields. The function appends each recipe to a slice of recipes, which is then returned.

func GetRecipeByIDFromDB

func GetRecipeByIDFromDB(db *sql.DB, recipeID uuid.UUID) (*models.Recipe, error)

GetRecipeByIDFromDB fetches a recipe from the database by its ID. It executes a SQL query to retrieve the recipe's name, description, ingredients, and directions. The recipe ID is used as a parameter in the query to filter the results. The ingredients and directions are stored as JSON in the database and are unmarshaled into slices. If the recipe is found, it returns the recipe object with the populated fields. If an error occurs during the query execution or unmarshaling process, it returns an error.

func Save

func Save(db *sql.DB, recipe models.Recipe) error

func SaveMany

func SaveMany(db *sql.DB, recipes []models.Recipe) error

func Update

func Update(db *sql.DB, recipe models.Recipe) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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