Documentation
¶
Index ¶
- func CreateTable(db *sql.DB) error
- func Get(diet models.DietType) models.Recipe
- func GetAllRecipesFromDB(db *sql.DB) ([]models.Recipe, error)
- func GetRecipeByIDFromDB(db *sql.DB, recipeID uuid.UUID) (*models.Recipe, error)
- func Save(db *sql.DB, recipe models.Recipe) error
- func SaveMany(db *sql.DB, recipes []models.Recipe) error
- func Update(db *sql.DB, recipe models.Recipe) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTable ¶
func GetAllRecipesFromDB ¶
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 ¶
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.
Types ¶
This section is empty.