A simple CLI that allows the user to access and manipulate table data in a database. It is built using python and sqlite3.
By Nehemiah Madahana.
This simple Restaurant CLI app built using python enables users to access and modify data in a table. It also allows them to sort through the tables and data in order to present a clearer picture of the data.
-
A CLI menu to enable users to access the data and modify it.
-
Persistence of data through a database.
Run:
python --versionYou should see this if python is installed:
If not consult this page on how to install python.
Run
pyenv versionsYou should see this if pyenv is installed:
If not follow the instructions this page to download pyenv.
- Clone this repository by typing the following command into your terminal:
git clone git@github.com:Zippy-sudo/restaurant_cli.gitor by downloading a ZIP file of the code.
- Navigate to the project directory:
cd /path-to/dir/restaurant-cliBe sure to replace /path-to/dir with the path to the directory into which you downloaded this repository.
- Install the required dependencies
pipenv Install- Enter the virtual environment
pipenv shell- Run the cli.py file by typing the following command into your terminal:
./lib/cli.pyThe terminal should display a menu:
The methods in this section are also applicable to Shift Manager (Option 2 on the main menu) and Worker Manager (Option 3 on the main menu).
- To exit type "0" and press Enter:
This will exit the CLI and you'll have to re-do step 5 of the installation Process.
- To add a new row to Restaurant:
- First type "1" into the terminal. This takes you to the Restaurant Manager.Each model has its own manager and the menu is similar to this one:
- From here you can add, update or delete a row from the database table associated with the manager, in this case the table is restaurants. You can also return to the main menu from this point by typing "0", but we are currently interested in adding a new Restaurant to the table, therefore we type "1":
- This causes the program to prompt us for more information about the Restaurant we are trying to add:
- Fill in the information required and you will get a success message:
- To check if the data has been persisted. Type "4" into the terminal:
- Now let's update this restaurant.
- Enter the Restaurant Manager by typing "1", then type "2" to enter the update menu:
- There are two ways to update a database entry for every Manager: by name and by id. Since we can easily remember a name as opposed to remembering an id, let's use the restaurant's name:
- Fill in the required details then press Enter:
- To confirm the data has been persisted we again type "4" then hit Enter.
- Let's delete the restaurant.
- Enter the restaurant manager by first typing "1", then enter the delete menu by typing "2" and hitting Enter.
- Here we again have an option to delete either by name or id. Now that we know the restaurant's id, let's try that path. Choose the second option by typing "2" and hitting enter, then input the restaurant's id which is "1".
- We get a confirmation message, but just to be sure, let's list all restaurants (Option 4 on the main menu)
- Woohoo! There are no restaurants in the table. It worked!
What if you knew a restaurant's Id and wanted to find more about it? Look no further than the Find by Id option.
-
Find restaurant by Id (Option 5 on the main menu) lets you find a restaurant by its Id.
-
Find shift by Id (Option 7 on the main menu) lets you find a shift by its Id.
-
Find worker by Id (Option 9 on the main menu) lets you find a worker by their Id.
Create a restaurant using the instructions from the segment on Table Managers above, then from the main menu:
- Enter "5" into the input field.
- Input the id of the restaurant in this case "1":
and Voilà!
You're probaly wondering about the More option(*). Well, let's find out what it does.
The More option enables us to extract relationship data from the tables
The queries are generally structured in this way: Get many for one.
-
Get shifts for restaurant (Option 1), can be said as "Get all the shifts associated with the restaurant Id that I pass in.
-
Get workers for restaurant (Option 2), can be said as "Get all the workers associated with the restaurant Id that I pass in.
-
Get workers for shift (Option 3), can be said as "Get all the workers associated with the shift Id that I pass in.
-
Get shifts for worker (Option 4), can be said as "Get all the shifts associated with the worker Id that I pass in.
Lets see it in action, We'll use Option 1 (Get shifts for restaurant).
- We navigate to the More Menu by typing "*" into the terminal.
- We select the First Option (Get shifts for restaurant) by typing in "1" then hitting Enter.
- We enter the restaurant Id, in this case "1" and get the result. (I'd added a new restaurant and some shifts to help demonstarate the query behaviour more clearly)
The list of all shifts by comparison:
- python3
- pyenv
- sqlite3
If you have any questions, suggestions, or need assistance, please contact:
MIT License
Copyright © 2024 Nehemiah Madahana
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.




















