Technologies: Python3.8+, Postgresql, https://www.sqlalchemy.org/ Description:
- Install postgres
- Create below table on Postgresql Table Name: users
| Column Name | Type |
|---|---|
| name | Text |
| Text | |
| phone_number | Text |
| age | Number |
| gender | Text |
| salary | Number |
| created_date | Timestamp |
- Write python code to insert into this table
- Write python code to update row in this table
- Write python code to find row in this table
- Write python code to delete row in this table
- Clone the project
- cd into the project directory
- Create a new virtual environment and activate it
virtualenv env && source env/bin/activate
- Create a file called env.py in the root, and add the following line into it:
DB_URL = "postgresql+psycopg2://" + DB_USER + ":" + DB_PASS + "@db" + "/" + DB_NAME
- Install Docker in your system and start the app
- Run the following command
docker pull postgres
- Run the files runPostgres.sh and runServer.sh in different terminal tabs, after adding your own password in runPostgres.sh
- Run the following commands in another terminal:
docker network create -d bridge <YOUR BRIDGE NAME>
docker network connect <YOUR BRIDGE NAME> db
docker network connect <YOUR BRIDGE NAME> web
-
Access pgAdmin4 on the postgres url, and create the table with the schema provided above, else all endpoints other than "/" will throw "NO TABLE" error.
-
Test the following endpoints on POSTMAN with their respective methods:
| ENDPOINT | METHOD | USE |
|---|---|---|
| / | GET | Root |
| /users | GET | Get all data present in table |
| /user | POST | Enter data into the table |
| /user/{user_id} | GET | Get a single row |
| /user/{user_id} | PUT | Update a single row |
| /user/{user_id} | DELETE | Delete a single row |