Commit 193c06c4 by arun.uday

v3

parent 40b0b545
......@@ -2,7 +2,7 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/task4.1.iml" filepath="$PROJECT_DIR$/.idea/task4.1.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/task4.1_mongo_post.iml" filepath="$PROJECT_DIR$/.idea/task4.1_mongo_post.iml" />
</modules>
</component>
</project>
\ No newline at end of file
# main application for database task
from scripts.core.engine.postgres_connect import cur, postgres_client
from scripts.services.access_functions import mongo_db_access_op, postgres_db_access_op
# mongodb
......@@ -7,11 +6,13 @@ db_choice = input("Enter mongo or postgres")
if db_choice == 'mongo':
print("Mongo DB")
mongo_db_access_op()
else:
elif db_choice == 'postgres':
print("PostgresSQL")
result = postgres_db_access_op()
if not result:
print("Lost in atoms")
else:
print("Successful")
else:
print("Lost in atoms")
......@@ -22,3 +22,13 @@ def view_fields(db, field_filter, data_find):
print(view_data)
else:
print("Data fetching failed")
def view_all(db):
view_data_cursor = db.find({}, {'_id': 0})
if len(list(view_data_cursor.clone())) > 0:
print("Data collected....")
view_data = pd.json_normalize((view_data_record for view_data_record in view_data_cursor))
print(view_data)
else:
print("Data fetching failed")
......@@ -9,7 +9,7 @@ def mongo_db_access_op():
db_created = db_class.mongo_create()
while True:
try:
user_query = input("Enter insert/ update/ delete/ view/ quit : ")
user_query = input("Enter insert/ update/ delete/ view/view-all/ quit : ")
if user_query == 'insert':
db_class.mongo_insert(db_created)
elif user_query == 'update':
......@@ -18,6 +18,8 @@ def mongo_db_access_op():
db_class.mongo_delete(db_created)
elif user_query == 'view':
db_class.mongo_view(db_created)
elif user_query == 'view-all':
db_class.mongo_view_all(db_created)
else:
print("Exiting....")
break
......
......@@ -4,7 +4,7 @@ from scripts.core.engine.mongodb_connect import client
from scripts.core.handlers.data_insert import insert_data_db, read_inputs
from scripts.core.handlers.delete_db_data import delete_db_input, db_delete
from scripts.core.handlers.update_mongo_db import db_update, input_update_db
from scripts.core.handlers.view_data_db import view_fields, view_cond
from scripts.core.handlers.view_data_db import view_fields, view_cond, view_all
class MongoDbStart:
......@@ -74,4 +74,12 @@ class MongoDbStart:
except Exception as e:
print(f'{exception_msg}{e}')
@staticmethod
def mongo_view_all(db):
try:
view_all(db)
except Exception as e:
print(f'{exception_msg}{e}')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment