Commit 83558508 by mohammed.shibili

updates done

parent 756e82db
# delete for mongodb
def deleting(id_to_delete, coll_name):
def deleting(coll_name):
id_to_delete = input("enter the id to deleted")
try:
coll_name.delete_many({'id': id_to_delete})
except Exception as e:
......
# view for mongodb
def finding(id_to_find, coll_name):
def finding(coll_name):
id_to_find = int(input("enter the id to find"))
try:
element_found = coll_name.find_one({"emp_id": id_to_find}, {"_id": 0})
print(element_found)
......
# insertion for mongodb
def inserting(datas_list, coll_name):
employee = datas_list
def inserting(coll_name):
fields = int(input("enter the number of fields"))
data_list = []
datas_to_insert = {}
while fields > 0:
key = input("enter the colum heading")
value = input("enter the value")
datas_to_insert[key] = value
fields = fields - 1
data_list.append(datas_to_insert)
try:
coll_name.insert_many(employee)
coll_name.insert_many(data_list)
except Exception as e:
print(e, "data not inserted")
......
from script.core.handlers.deleting import deleting, post_delete
from script.core.handlers.finding import finding, postgres_search
from script.core.handlers.inserting import inserting, post_insert
from script.core.handlers.update import updating, post_update
def to_mongo(coll_name):
print("1.insert \n2.update\n3.delete\n4.read")
operation = int(input("enter the operation to perform"))
# inserting operation
if operation == 1:
inserting(coll_name)
# update operation
elif operation == 2:
updating(coll_name)
# delete operation
elif operation == 3:
deleting(coll_name)
# view operation
elif operation == 4:
finding(coll_name)
def to_postgres(connection, cursor_name):
print("1.insert \n2.update\n3.delete\n4.read")
operation = int(input("enter the operation to perform"))
# creating table on postgresql
query = """
CREATE TABLE emp_table11 (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INTEGER NOT NULL,
salary INTEGER NOT NULL
);
"""
# accepting operation to be performed
cursor_name.execute(query)
connection.commit()
if operation == 1:
post_insert(connection, cursor_name)
elif operation == 2:
post_update(connection, cursor_name)
elif operation == 3:
post_delete(connection, cursor_name)
elif operation == 4:
postgres_search(connection, cursor_name)
\ No newline at end of file
# update for mongodb
def updating(id_to_search, field_to_update, element_tobe_updated, coll_name):
def updating(coll_name):
id_to_search = int(input("enter the id to search"))
field_to_update = input("enter the field to update")
element_tobe_updated = input("enter the value to be updated")
update = {"$set": {field_to_update: element_tobe_updated}}
try:
coll_name.update_one({"emp_id": id_to_search}, update)
......
from script.core.handlers.deleting import deleting, post_delete
from script.core.handlers.finding import finding, postgres_search
from script.core.handlers.inserting import inserting, post_insert
from script.core.handlers.update import updating, post_update
from script.core.handlers.operation_to_perform import to_mongo, to_postgres
# function for operation of mongodb
def user_data(coll_name):
print("1.insert \n2.update\n3.delete\n4.read")
operation = int(input("enter the operation to perform"))
# inserting operation
if operation == 1:
fields = int(input("enter the number of fields"))
data_list = []
datas_to_insert = {}
while fields > 0:
key = input("enter the colum heading")
value = input("enter the value")
datas_to_insert[key] = value
fields = fields - 1
data_list.append(datas_to_insert)
inserting(data_list, coll_name)
# update operation
elif operation == 2:
id_to_search = int(input("enter the id to search"))
field_to_update = input("enter the field to update")
element_tobe_updated = input("enter the value to be updated")
updating(id_to_search, field_to_update, element_tobe_updated, coll_name)
# delete operation
elif operation == 3:
id_to_delete = input("enter the id to deleted")
deleting(id_to_delete, coll_name)
# view operation
elif operation == 4:
id_to_find = int(input("enter the id to find"))
finding(id_to_find, coll_name)
to_mongo(coll_name)
# function for operation of mongodb
def user_postgres(connection, cursor_name):
print("1.insert \n2.update\n3.delete\n4.read")
operation = int(input("enter the operation to perform"))
# creating table on postgresql
query = """
CREATE TABLE emp_table11 (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INTEGER NOT NULL,
salary INTEGER NOT NULL
);
"""
# accepting operation to be performed
cursor_name.execute(query)
connection.commit()
if operation == 1:
post_insert(connection, cursor_name)
elif operation == 2:
post_update(connection, cursor_name)
elif operation == 3:
post_delete(connection, cursor_name)
elif operation == 4:
postgres_search(connection, cursor_name)
to_postgres(connection, cursor_name)
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