Cooking Recipe Database Project Sql

By | April 27, 2023

Cooking Recipe Database Project Sql – Being a real adult (and now, in quarantine) means joining r/MealPrepSundays and recreating all the meal prep recipes. As my repertoire of recipes grew, so did my storage needs.

First I kept track of all the recipes I tried in a spreadsheet, carefully organized first by food, then by main ingredient. I’ve also included other features I like to keep in mind, including cuisine, difficulty, and any dietary restrictions in the recipe. But increasing the number of rows also means increasing the time spent sorting and searching. I need a new, more powerful storage unit. That’s when I started researching the spreadsheet’s lightweight (though less attractive, UI-wise) cousin, the SQLite relational database.

Cooking Recipe Database Project Sql

Cooking Recipe Database Project Sql

In the end, my recipe database accomplished all of these goals. Is it the most user friendly/useful option? Probably not, and I know SQLite is probably not the best choice for a project like this. However, I created some of the basic building blocks of a recipe database and developed a new appreciation for existing spreadsheet applications. If you are interested in seeing how SQLite and python pandas can be used in the context of recipes, let’s move on to practicality.

The Ultimate Fastapi Tutorial Part 7

. I use a Jupyter notebook for easy viewing, but feel free to split it into labeled files.

The first criterion that I want to meet in my database is to increase the space for growth, which directly affects its structure. As the database expands, it becomes increasingly important to minimize redundancies that affect storage performance. This concept is called generalization.

While different forms of normalization have their own specific rules, normalization generally involves breaking a large table into smaller ones and maintaining the association between them. The structure of these small tables is determined by the relationships in the underlying data, of which there are three types: one-to-one, one-to-many, and many-to-many.

The simplest database relationship is one-to-one. This occurs when a record in table A is linked to one and only one record in table B. In a recipe database, a recipe and its instructions have a one-to-one relationship, as that is never possible for two recipes. Exactly the same instructions. So the table of recipe names and the table of recipe instructions contain a row with a recipe name that corresponds to only one row of recipe instructions.

Doing Power Bi The Right Way: 4. Power Query Design Best Practices

For most other recipe attributes (eg, difficulty, cuisine, course, and food type), there is a one-to-many relationship. A record in table A is linked to (you guessed it!) several records in table B. For example, a difficulty level (eg “easy”) may have many recipes associated with it, since there are many “easy” recipes. The reverse isn’t true though – a recipe can’t be both “easy” and “difficult” (unless my cooking ability varies from day to day).

The last type between tables is many-to-many. In a recipe database, a recipe can have multiple ingredients, and an ingredient can be used in multiple recipes.

Implementing many-to-many relationships requires a third junction table to follow generalization rules. Between my recipe table and ingredients table, I have created a junction table named Recipe_Ingredient. This third table breaks the many-to-many relationship into two one-to-many relationships.

Cooking Recipe Database Project Sql

On the right side of the drawing, you will see that there is not just one table of ingredients, but four separate tables, including a unit table, a quantity table, and a preparation method table. This framework takes advantage of many-to-many relationships of ingredients, quantities, and preparation methods with a single recipe. While I could have used one-to-many relationships between ingredients and individual units, quantities, and preparation methods, I prefer to gather all information related to ingredients in one place in the recipe_ingredients table.

Solution: Bbq Recipe App User Flow Diagram

Now that the tables are split, the question is how to join them. All previous schema diagrams have arrows, which lead from one particular table to the corresponding “id” column in another table. The base of the arrow indicates the primary key or its unique identifier of a row in a particular table. An arrowhead points to a reference to a foreign key or primary key.

These keys not only help in establishing relationships, but also in reducing redundancy. When making changes, if I want to change “easy” to “effortless”, I just need to change the difficulty table. If the primary foreign key relationship does not exist, I have to go through all the rows with “simple” and do the conversion one by one. Establishing this link further preserves orphaned records by preventing any deletion of primary keys with dependent foreign keys. For more information on SQLite foreign keys, see the documentation here.

A database management system, or DBMS, is a catch-all phrase for systems that help manage databases. A subset of these can handle relations, classifying them under RDBMS, with an additional R for relations. Since I needed to manage the relationship, I chose SQLite, an RDBMS, for its ease of setup and lack of servers.

The Cursor object comes in handy later when we want to interact with the Python database and process SQL queries. More information can be found in the Python docs here.

Using Sql Server Extended Events To Debug Applications

While I won’t cover simple SQL syntax, I will explain tips and tricks I’ve found useful when implementing the database structure I created at the beginning of this article.

The primary and foreign keys established earlier can now be implemented as we create our table. Below is an example of a recipe table:

A table is linked to another table by a primary key. For example, if a row is entered in

Cooking Recipe Database Project Sql

For the keywords we use, we don’t need to enter explicit values ​​for our primary key in the table. Just enter a value for the row, and the table will automatically generate a unique integer number for it.

Pdf) Modeling Recipes For Online Search

This way statement ensures that I can find the correct matching primary key, even if I don’t know the unique integer off the top of my head.

I want the row entries that are not primary or foreign keys to be user supplied values. Fortunately, SQL provides us with prepared statements for entering values ​​that we don’t already know. With prepared statements, we can specify parameters as queries using the question mark as syntax. It is used instead of traditional Python string formatting to protect itself from SQL injection. In the following task, I use a prepared statement to enter instructions for a recipe.

For certain attributes, such as cuisine, I know that there is a high probability that the entered value will be one that is already in the database of previous entries. Keeping with the functionality theme, I want to prevent checking if iterations exist. In selected tables I use a

While most of my tables contain rows based on user input, I want two of my tables,

Clarity Cookbook: Objectives And Key Results (okrs)

As a lookup value when I use my select method to insert the foreign key. So I chose to put “None” as the value so that recipes can be defined without dietary restrictions.

, which can be used to insert multiple rows at once. Be sure to pass the rows you want to insert as a

The biggest challenge when organizing this recipe database is the management of ingredients, because only one ingredient has four attributes: name, quantity, unit, and method of preparation. In the end I chose to group these features as a dictionary per component. It resembles a natural spreadsheet in Python, with each column translated into a key.

Cooking Recipe Database Project Sql

While a dictionary like this is painful to type manually, a good user interface can manage it.

How To Create A Recipe Database

Must find and view recipes for use. To achieve my second and third goals for this database, I created two functions in view.py: one to view the selected recipes, and another to gather the overall list of ingredients.

. I want to filter and select recipes based on selected criteria and implement this “search” function with keyword arguments that I format in SQL.

The query keyword arg has range as key and select range as value. Since the arguments are not static, I can pass multiple parameters if necessary.

SQL queries in Python are unfortunately hard strings, so the rest of the function is dedicated to formatting the arguments. In case of multiple arguments, I decided to combine the search criteria into one

Analyze Recipes And Nutrition With Apilayer Food Apis

. This is because I know most of my finds are ingredients from last week that I want to use. To find recipes that include all the ingredients I want to use, I need combinations of ingredients, not intersections. If you’re looking for something that requires the intersection of your criteria, change it to one

After all the string formatting, you’ll be rewarded with a function that outputs a dataframe of the recipes you selected in your keyword arguments. Now it’s time to make a shopping list.

When there are ingredients

Cooking Recipe Database Project Sql

Library management system project sql database code, visual studio sql database project, how to deploy sql server database project, vs sql server database project, database management system project in sql, sql database project, sql database project tutorial, visual studio sql server database project, sql database sample project, sql database project ideas, sql server database project, asp net project with sql database