Commit b2154dbb by rakipv

done

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (mongo_python_crud_fastapi)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mongo_python_crud_fastapi.iml" filepath="$PROJECT_DIR$/.idea/mongo_python_crud_fastapi.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from scripts.services.main import main
print("Welcome to perform Mongodb CRUD operations")
main()
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/
from pymongo import MongoClient
try:
client = MongoClient('localhost', 27017)
print("Connected Successfully!")
except Exception as e:
print("Error is >> ", e)
from scripts.config.config import client
# accessing db
database = client["student"]
# accessing collection
collection = database["student_details"]
# print("Successfully connected!")
from scripts.core.engine.database import collection
# Function to insert the data into mongodb
def create():
try:
student_id = int(input("enter student id"))
student_name = input("enter student name >> ")
student_year = int(input("enter student ease year >> "))
student_genre = input("enter student genre >> ")
collection.insert_one(
{
"student_id": student_id,
"student_name": student_name,
"student_year": student_year,
"student_genre": student_genre
}
)
print("\nInserted data into the database!")
except Exception as e:
print("Error details >> ", e)
from scripts.core.engine.database import collection
# Function to insert the data into mongodb
def delete():
try:
student_id = int(input("enter student id to delete >> "))
collection.delete_many({"student_id": student_id})
print("\nDeleted data from the database!")
except Exception as e:
print("Error details >> ", e)
from scripts.core.engine.database import collection
def read():
try:
read_data = collection.find()
print('\n All data from student Database \n')
for read in read_data:
print("student details are >> ", read)
except Exception as e:
print("Error details >> ", e)
from scripts.core.engine.database import collection
# Function to insert the data into mongodb
def update():
try:
student_id = int(input("enter student id >> "))
student_name = input("enter student name >> ")
student_year = int(input("enter student year "))
student_genre = input("enter student genre >> ")
collection.update_one(
{"student_id": student_id},
{
"$set": {
"student_id": student_id,
"student_name": student_name,
"student_year": student_year,
"student_genre": student_genre
}
}
)
print("\nRecords updated successfully!")
except Exception as e:
print("Error details >> ", e)
from scripts.core.handlers.create_operation import create
from scripts.core.handlers.update_operation import update
from scripts.core.handlers.read_operation import read
from scripts.core.handlers.delete_operation import delete
def main():
while 1:
# Select your option
selection = input(
'\nSelect 1 to insert data, 2 to read data, 3 to update data, 4 to delete data, 5 to Stop CRUD'
' operations >> \n')
if selection == '1':
create()
elif selection == '2':
read()
elif selection == '3':
update()
elif selection == '4':
delete()
elif selection == '5':
print("Successfully stopped CRUD Operations!")
quit()
else:
print('\n INVALID SELECTION!\n -- Try Again! --\n')
main()
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