Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kl_task4_1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
arun.uday
kl_task4_1
Commits
e1eb9c50
Commit
e1eb9c50
authored
Feb 02, 2023
by
arun.uday
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v4
parent
5bd102c5
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
254 additions
and
101 deletions
+254
-101
.idea/sonarlint/issuestore/index.pb
+2
-4
scripts/core/database/mongo/mongodb_connect.py
+0
-0
scripts/core/database/mongo/queries/mongodb_queires.py
+22
-0
scripts/core/database/postgres/postgres_connect.py
+0
-0
scripts/core/database/postgres/queries/post_queries.py
+40
-0
scripts/core/handlers/data_insert.py
+6
-5
scripts/core/handlers/delete_db_data.py
+20
-6
scripts/core/handlers/get_post_columns.py
+11
-0
scripts/core/handlers/mongo_db_operations.py
+8
-16
scripts/core/handlers/postgres_data_del.py
+2
-1
scripts/core/handlers/postgres_data_insert.py
+2
-2
scripts/core/handlers/postgres_data_update.py
+31
-7
scripts/core/handlers/postgres_data_view.py
+49
-14
scripts/core/handlers/postgres_db_operations.py
+7
-5
scripts/core/handlers/postgres_table_create.py
+2
-12
scripts/core/handlers/update_mongo_db.py
+30
-9
scripts/core/handlers/view_data_db.py
+19
-17
scripts/services/access_functions.py
+3
-3
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
e1eb9c50
No preview for this file type
scripts/core/
engine
/mongodb_connect.py
→
scripts/core/
database/mongo
/mongodb_connect.py
View file @
e1eb9c50
File moved
scripts/core/database/mongo/queries/mongodb_queires.py
0 → 100644
View file @
e1eb9c50
class
MongoDBQuery
:
@staticmethod
def
insert
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
cur
=
db
.
insert_one
({
"product_id"
:
p_id
,
"product_name"
:
p_name
,
"product_category"
:
p_category
,
"retail_price"
:
retail_price
,
"discount_price"
:
discount_price
,
"description"
:
description
,
"overall_rating"
:
over_rating
})
return
cur
@staticmethod
def
update
(
db
,
condition_values
,
update_data
):
update_d
=
db
.
update_many
(
condition_values
,
update_data
)
return
update_d
@staticmethod
def
view
(
db
,
field_filter
):
view_data
=
db
.
find
(
field_filter
,
{
'_id'
:
0
})
return
view_data
@staticmethod
def
delete
(
db
,
condition_values
):
delete_data
=
db
.
delete_one
(
condition_values
)
return
delete_data
scripts/core/
engine
/postgres_connect.py
→
scripts/core/
database/postgres
/postgres_connect.py
View file @
e1eb9c50
File moved
scripts/core/database/postgres/queries/post_queries.py
0 → 100644
View file @
e1eb9c50
from
scripts.config.postgres_connect_config
import
products
class
QueriesPost
:
@staticmethod
def
create_table
():
table
=
f
"CREATE TABLE if not exists {products} "
\
f
"(Product_Id SERIAL PRIMARY KEY, Product_Name VARCHAR(255),"
\
f
"Product_Category VARCHAR(255),"
\
f
"Retail_Price INT,"
\
f
"Discounted_Price INT,"
\
f
"Description VARCHAR(255),"
\
f
"Overall_Rating INT)"
return
table
@staticmethod
def
insert_data
():
insert_data
=
f
"INSERT INTO {products} (Product_Name, Product_Category, Retail_Price, Discounted_Price,"
\
f
"Description, Overall_Rating) VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
return
insert_data
@staticmethod
def
update_data
(
updates
,
conditions
):
view_data
=
f
"UPDATE {products} SET {updates} WHERE {conditions}"
return
view_data
@staticmethod
def
fetch_conditions
(
conditions
):
fetch_data
=
f
"SELECT * FROM {products} WHERE {conditions}"
return
fetch_data
@staticmethod
def
fetch_all
():
fetch_data
=
f
"SELECT * FROM {products}"
return
fetch_data
@staticmethod
def
delete_data
(
field_name
,
del_data
):
del_val
=
f
"DELETE FROM {products} WHERE {field_name} = {del_data}"
return
del_val
scripts/core/handlers/data_insert.py
View file @
e1eb9c50
# reading user inputs
# reading user inputs
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
def
read_inputs
():
def
read_inputs
():
p_id
=
int
(
input
(
"Enter the product id: "
))
p_id
=
int
(
input
(
"Enter the product id: "
))
p_name
=
input
(
"Enter the product name: "
)
p_name
=
input
(
"Enter the product name: "
)
...
@@ -14,10 +17,8 @@ def read_inputs():
...
@@ -14,10 +17,8 @@ def read_inputs():
# inserting data to mongo
# inserting data to mongo
def
insert_data_db
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
def
insert_data_db
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
try
:
try
:
insert_res
=
db
.
insert_one
({
"Product Id"
:
p_id
,
"Product Name"
:
p_name
,
"Product category"
:
p_category
,
insert_res
=
MongoDBQuery
()
.
insert
(
db
,
p_id
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
)
"Retail price"
:
retail_price
,
"Discount Price"
:
discount_price
,
return
insert_res
"Description"
:
description
,
"Overall rating"
:
over_rating
})
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Exception occurred :"
,
e
)
print
(
"Exception occurred :"
,
e
)
return
insert_res
scripts/core/handlers/delete_db_data.py
View file @
e1eb9c50
# deleting data
# deleting data
# getting user inputs
# getting user inputs
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
def
delete_db_input
():
def
delete_db_input
():
field_name
=
input
(
"Enter the field condition: "
)
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
del_data
=
int
(
input
(
"Enter the data: "
))
'discount_price'
,
'description'
,
'overall_rating'
]
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
and
(
counter
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
int
(
field_value
)})
if
field_value
!=
''
and
(
counter
not
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
f
'{field_value}'
})
counter
+=
1
return
field_name
,
del_data
return
condition_values
# deleting the record
# deleting the record
def
db_delete
(
db
,
field_name
,
del_data
):
def
db_delete
(
db
,
condition_values
):
filter_del
=
{
field_name
:
del_data
}
cur
=
MongoDBQuery
()
.
delete
(
db
,
condition_values
)
return
db
.
delete_one
(
filter_del
)
return
cur
scripts/core/handlers/get_post_columns.py
0 → 100644
View file @
e1eb9c50
from
scripts.config.postgres_connect_config
import
products
from
scripts.core.database.postgres.postgres_connect
import
cur
def
post_columns
():
# Execute a SELECT statement to get the column names of a table
cur
.
execute
(
f
"SELECT * FROM {products} LIMIT 0"
)
# Get the column names
field_names
=
[
desc
[
0
]
for
desc
in
cur
.
description
]
return
field_names
scripts/
service
s/mongo_db_operations.py
→
scripts/
core/handler
s/mongo_db_operations.py
View file @
e1eb9c50
# class for mongodb operations
# class for mongodb operations
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.file_constants
import
exception_msg
from
scripts.core.
engine
.mongodb_connect
import
client
from
scripts.core.
database.mongo
.mongodb_connect
import
client
from
scripts.core.handlers.data_insert
import
insert_data_db
,
read_inputs
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.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.update_mongo_db
import
db_update
,
input_update_db
from
scripts.core.handlers.view_data_db
import
view_fields
,
view_cond
,
view_all
from
scripts.core.handlers.view_data_db
import
view_fields
,
view_cond
class
MongoDbStart
:
class
MongoDbStart
:
...
@@ -42,8 +42,8 @@ class MongoDbStart:
...
@@ -42,8 +42,8 @@ class MongoDbStart:
@staticmethod
@staticmethod
def
mongo_update
(
db
):
def
mongo_update
(
db
):
try
:
try
:
field_name
,
up_data
,
up_field_name
,
new_data
=
input_update_db
()
condition_values
,
update_values
=
input_update_db
()
update_check
=
db_update
(
db
,
field_name
,
up_data
,
up_field_name
,
new_data
)
update_check
=
db_update
(
db
,
condition_values
,
update_values
)
if
update_check
.
matched_count
>
0
:
if
update_check
.
matched_count
>
0
:
print
(
"Data updated"
)
print
(
"Data updated"
)
else
:
else
:
...
@@ -55,8 +55,8 @@ class MongoDbStart:
...
@@ -55,8 +55,8 @@ class MongoDbStart:
@staticmethod
@staticmethod
def
mongo_delete
(
db
):
def
mongo_delete
(
db
):
try
:
try
:
field_name
,
del_data
=
delete_db_input
()
condition_values
=
delete_db_input
()
del_check
=
db_delete
(
db
,
field_name
,
del_data
)
del_check
=
db_delete
(
db
,
condition_values
)
if
del_check
.
deleted_count
>
0
:
if
del_check
.
deleted_count
>
0
:
print
(
"Data deleted"
)
print
(
"Data deleted"
)
else
:
else
:
...
@@ -68,16 +68,8 @@ class MongoDbStart:
...
@@ -68,16 +68,8 @@ class MongoDbStart:
@staticmethod
@staticmethod
def
mongo_view
(
db
):
def
mongo_view
(
db
):
try
:
try
:
field_filter
,
data_find
=
view_cond
()
field_filter
=
view_cond
()
view_fields
(
db
,
field_filter
,
data_find
)
view_fields
(
db
,
field_filter
)
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
@staticmethod
def
mongo_view_all
(
db
):
try
:
view_all
(
db
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{exception_msg}{e}'
)
...
...
scripts/core/handlers/postgres_data_del.py
View file @
e1eb9c50
# deleting data
# deleting data
# getting user inputs
# getting user inputs
from
scripts.config.postgres_connect_config
import
products
from
scripts.config.postgres_connect_config
import
products
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
# user input
# user input
...
@@ -13,4 +14,4 @@ def delete_db_post():
...
@@ -13,4 +14,4 @@ def delete_db_post():
# deleting the record
# deleting the record
def
db_delete_post
(
cur
,
field_name
,
del_data
):
def
db_delete_post
(
cur
,
field_name
,
del_data
):
return
cur
.
execute
(
f
"DELETE FROM {products} WHERE {field_name} = {del_data}"
)
return
cur
.
execute
(
QueriesPost
()
.
delete_data
(
field_name
,
del_data
)
)
scripts/core/handlers/postgres_data_insert.py
View file @
e1eb9c50
# reading user inputs
# reading user inputs
from
scripts.config.postgres_connect_config
import
products
from
scripts.config.postgres_connect_config
import
products
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.file_constants
import
exception_msg
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
# user inputs
# user inputs
...
@@ -20,8 +21,7 @@ def read_inputs_post():
...
@@ -20,8 +21,7 @@ def read_inputs_post():
def
insert_data_post
(
cur
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
def
insert_data_post
(
cur
,
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
):
try
:
try
:
val_data
=
[
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
]
val_data
=
[
p_name
,
p_category
,
retail_price
,
discount_price
,
description
,
over_rating
]
cur
.
execute
(
f
"INSERT INTO {products} (Product_Name, Product_Category, Retail_Price, Discounted_Price, "
cur
.
execute
(
QueriesPost
()
.
insert_data
(),
val_data
)
f
"Description, Overall_Rating) VALUES (
%
s,
%
s,
%
s,
%
s,
%
s,
%
s)"
,
val_data
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{exception_msg},{e}'
)
return
False
return
False
...
...
scripts/core/handlers/postgres_data_update.py
View file @
e1eb9c50
# updating the db
# updating the db
from
scripts.config.postgres_connect_config
import
products
from
scripts.config.postgres_connect_config
import
products
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
from
scripts.core.handlers.get_post_columns
import
post_columns
# user data
# user data
def
input_update_post
():
def
input_update_post
():
field_name
=
input
(
"Enter the field condition: "
)
columns_
=
post_columns
()
up_data
=
int
(
input
(
"Enter the data: "
))
counter
=
0
up_field_name
=
input
(
"Enter the field to update: "
)
condition_values
=
{}
new_data
=
input
(
"Enter the new data: "
)
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
:
condition_values
.
update
({
columns_
[
counter
]:
field_value
})
counter
+=
1
return
field_name
,
up_data
,
up_field_name
,
new_data
counter
=
1
update_values
=
{}
print
(
"New values"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
:
update_values
.
update
({
columns_
[
counter
]:
field_value
})
counter
+=
1
return
condition_values
,
update_values
# updating the database
# updating the database
def
db_update_post
(
cur
,
field_name
,
up_data
,
up_field_name
,
new_data
):
def
db_update_post
(
cur
,
condition_values
,
update_values
):
return
cur
.
execute
(
f
"UPDATE {products} SET {up_field_name} = '{new_data}' WHERE {field_name} = '{up_data}'"
)
conditions
=
[
f
"{field} = '{value}'"
for
field
,
value
in
condition_values
.
items
()]
conditions
=
"and "
.
join
(
conditions
)
updates
=
[
f
"{field} = '{value}'"
for
field
,
value
in
update_values
.
items
()]
updates
=
", "
.
join
(
updates
)
if
conditions
and
updates
:
cur
=
cur
.
execute
(
QueriesPost
()
.
update_data
())
else
:
cur
=
None
return
cur
scripts/core/handlers/postgres_data_view.py
View file @
e1eb9c50
...
@@ -3,21 +3,56 @@
...
@@ -3,21 +3,56 @@
import
pandas
as
pd
import
pandas
as
pd
from
scripts.config.postgres_connect_config
import
products
from
scripts.config.postgres_connect_config
import
products
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
from
scripts.core.handlers.get_post_columns
import
post_columns
# user input for fetch
def
input_view_post
():
columns_
=
post_columns
()
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
:
condition_values
.
update
({
columns_
[
counter
]:
field_value
})
counter
+=
1
return
condition_values
# view the data
# view the data
def
view_fields_post
(
cur
):
def
view_fields_post
(
cur
,
condition_values
):
cur
.
execute
(
f
"SELECT * FROM {products}"
)
conditions
=
[
f
"{field} = '{value}'"
for
field
,
value
in
condition_values
.
items
()]
cursor_data
=
cur
.
fetchall
()
conditions
=
" and "
.
join
(
conditions
)
if
cursor_data
is
not
None
:
if
conditions
:
print
(
"Data collected...."
)
cur
.
execute
(
QueriesPost
()
.
fetch_conditions
())
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
[
'Product Id'
,
cursor_data
=
cur
.
fetchall
()
'Product_Name'
,
if
cursor_data
:
'Product_Category'
,
print
(
"Data collected...."
)
'Retail_Price'
,
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
[
'Product Id'
,
'Discounted_Price'
,
'Product_Name'
,
'Description'
,
'Product_Category'
,
'Overall_Rating'
])
'Retail_Price'
,
print
(
view_data
)
'Discounted_Price'
,
'Description'
,
'Overall_Rating'
])
print
(
view_data
)
else
:
print
(
"Data fetching failed"
)
else
:
else
:
print
(
"Data fetching failed"
)
cur
.
execute
(
QueriesPost
()
.
fetch_all
())
cursor_data
=
cur
.
fetchall
()
if
cursor_data
:
print
(
"Data collected...."
)
view_data
=
pd
.
DataFrame
((
view_data_record
for
view_data_record
in
cursor_data
),
columns
=
[
'Product Id'
,
'Product_Name'
,
'Product_Category'
,
'Retail_Price'
,
'Discounted_Price'
,
'Description'
,
'Overall_Rating'
])
print
(
view_data
)
else
:
print
(
"Data fetching failed"
)
scripts/
service
s/postgres_db_operations.py
→
scripts/
core/handler
s/postgres_db_operations.py
View file @
e1eb9c50
# class for postgresSql
# class for postgresSql
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.file_constants
import
exception_msg
from
scripts.core.
engine
.postgres_connect
import
cur
,
postgres_client
from
scripts.core.
database.postgres
.postgres_connect
import
cur
,
postgres_client
from
scripts.core.handlers.postgres_data_del
import
delete_db_post
,
db_delete_post
from
scripts.core.handlers.postgres_data_del
import
delete_db_post
,
db_delete_post
from
scripts.core.handlers.postgres_data_insert
import
read_inputs_post
,
insert_data_post
from
scripts.core.handlers.postgres_data_insert
import
read_inputs_post
,
insert_data_post
from
scripts.core.handlers.postgres_data_update
import
input_update_post
,
db_update_post
from
scripts.core.handlers.postgres_data_update
import
input_update_post
,
db_update_post
from
scripts.core.handlers.postgres_data_view
import
view_fields_post
from
scripts.core.handlers.postgres_data_view
import
view_fields_post
,
input_view_post
from
scripts.core.handlers.postgres_table_create
import
create_table
from
scripts.core.handlers.postgres_table_create
import
create_table
...
@@ -40,8 +40,8 @@ class PostgresStart:
...
@@ -40,8 +40,8 @@ class PostgresStart:
@staticmethod
@staticmethod
def
post_update
():
def
post_update
():
try
:
try
:
field_name
,
up_data
,
up_field_name
,
new_data
=
input_update_post
()
condition_values
,
update_values
=
input_update_post
()
update_check
=
db_update_post
(
cur
,
field_name
,
up_data
,
up_field_name
,
new_data
)
update_check
=
db_update_post
(
cur
,
condition_values
,
update_values
)
if
update_check
is
None
:
if
update_check
is
None
:
print
(
"Data updated"
)
print
(
"Data updated"
)
else
:
else
:
...
@@ -64,7 +64,8 @@ class PostgresStart:
...
@@ -64,7 +64,8 @@ class PostgresStart:
@staticmethod
@staticmethod
def
post_view
():
def
post_view
():
try
:
try
:
view_fields_post
(
cur
)
condition_values
=
input_view_post
()
view_fields_post
(
cur
,
condition_values
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
'{exception_msg}{e}'
)
print
(
f
'{exception_msg}{e}'
)
...
@@ -74,3 +75,4 @@ class PostgresStart:
...
@@ -74,3 +75,4 @@ class PostgresStart:
# Close the cursor and connection
# Close the cursor and connection
cur
.
close
()
cur
.
close
()
postgres_client
.
close
()
postgres_client
.
close
()
scripts/core/handlers/postgres_table_create.py
View file @
e1eb9c50
# creating a table
# creating a table
from
scripts.config.postgres_connect_config
import
products
from
scripts.config.postgres_connect_config
import
products
from
scripts.constants.file_constants
import
exception_msg
from
scripts.constants.file_constants
import
exception_msg
from
scripts.core.database.postgres.queries.post_queries
import
QueriesPost
# create table if exist or not
# create table if exist or not
def
create_table
(
cur
):
def
create_table
(
cur
):
try
:
try
:
cursor_db
=
cur
cursor_db
=
cur
cursor_db
.
execute
(
f
"SELECT * FROM information_schema.tables WHERE table_name = '{products}'"
)
cursor_db
.
execute
(
QueriesPost
()
.
create_table
())
if
cursor_db
.
fetchone
():
print
(
"Table exist"
)
else
:
# Create the table if it does not exist
cursor_db
.
execute
(
f
"CREATE TABLE {products} "
f
"(Product_Id SERIAL PRIMARY KEY, Product_Name VARCHAR(255),"
f
"Product_Category VARCHAR(255),"
f
"Retail_Price INT,"
f
"Discounted_Price INT,"
f
"Description VARCHAR(255),"
f
"Overall_Rating INT)"
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
'{exception_msg},{e}'
)
print
(
f
'{exception_msg},{e}'
)
return
False
return
False
...
...
scripts/core/handlers/update_mongo_db.py
View file @
e1eb9c50
# updating the db
# updating the db
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
# user data
# user data
def
input_update_db
():
def
input_update_db
():
field_name
=
input
(
"Enter the field condition: "
)
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
up_data
=
int
(
input
(
"Enter the data: "
))
'discount_price'
,
'description'
,
'overall_rating'
]
up_field_name
=
input
(
"Enter the field to update: "
)
integer_val
=
[
0
,
3
,
4
,
6
]
new_data
=
input
(
"Enter the new data: "
)
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
and
(
counter
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
int
(
field_value
)})
if
field_value
!=
''
and
(
counter
not
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
f
'{field_value}'
})
counter
+=
1
return
field_name
,
up_data
,
up_field_name
,
new_data
counter
=
1
update_values
=
{}
print
(
"New values"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
and
(
counter
in
integer_val
):
update_values
.
update
({
f
'{columns_[counter]}'
:
int
(
field_value
)})
if
field_value
!=
''
and
(
counter
not
in
integer_val
):
update_values
.
update
({
f
'{columns_[counter]}'
:
f
'{field_value}'
})
counter
+=
1
return
condition_values
,
update_values
# updating the database
# updating the database
def
db_update
(
db
,
field_name
,
up_data
,
up_field_name
,
new_data
):
def
db_update
(
db
,
condition_values
,
update_values
):
cond_data
=
{
field_name
:
up_data
}
update_data
=
{
"$set"
:
update_values
}
update_data
=
{
"$set"
:
{
up_field_name
:
new_data
}}
cur
=
MongoDBQuery
()
.
update
(
db
,
condition_values
,
update_data
)
return
db
.
update_many
(
cond_data
,
update_data
)
return
cur
scripts/core/handlers/view_data_db.py
View file @
e1eb9c50
...
@@ -2,33 +2,35 @@
...
@@ -2,33 +2,35 @@
# display conditions
# display conditions
import
pandas
as
pd
import
pandas
as
pd
from
scripts.core.database.mongo.queries.mongodb_queires
import
MongoDBQuery
# display conditions
# display conditions
def
view_cond
():
def
view_cond
():
field_filter
=
input
(
"Enter the field name: "
)
columns_
=
[
'product_id'
,
'product_name'
,
'product_category'
,
'retail_price'
,
data_find
=
int
(
input
(
"Enter the data to find: "
))
'discount_price'
,
'description'
,
'overall_rating'
]
integer_val
=
[
0
,
3
,
4
,
6
]
counter
=
0
condition_values
=
{}
print
(
"Conditions"
)
while
counter
<
len
(
columns_
):
field_value
=
input
(
f
"Enter the {columns_[counter]} data: "
)
if
field_value
!=
''
and
(
counter
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
int
(
field_value
)})
if
field_value
!=
''
and
(
counter
not
in
integer_val
):
condition_values
.
update
({
f
'{columns_[counter]}'
:
f
'{field_value}'
})
counter
+=
1
return
field_filter
,
data_find
return
condition_values
# view the data
# view the data
def
view_fields
(
db
,
field_filter
,
data_find
):
def
view_fields
(
db
,
field_filter
):
filter_data
=
{
field_filter
:
data_find
}
view_data_cursor
=
MongoDBQuery
()
.
view
(
db
,
field_filter
)
view_data_cursor
=
db
.
find
(
filter_data
,
{
'_id'
:
0
})
view_cursor_count
=
db
.
count_documents
(
field_filter
)
view_cursor_count
=
db
.
count_documents
(
filter_data
)
if
view_cursor_count
>
0
:
if
view_cursor_count
>
0
:
print
(
"Data collected...."
)
print
(
"Data collected...."
)
view_data
=
pd
.
json_normalize
((
view_data_record
for
view_data_record
in
view_data_cursor
))
view_data
=
pd
.
json_normalize
((
view_data_record
for
view_data_record
in
view_data_cursor
))
print
(
view_data
)
print
(
view_data
)
else
:
else
:
print
(
"Data fetching failed"
)
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"
)
scripts/services/access_functions.py
View file @
e1eb9c50
# access class functions
# access class functions
from
scripts.
service
s.mongo_db_operations
import
MongoDbStart
from
scripts.
core.handler
s.mongo_db_operations
import
MongoDbStart
from
scripts.
service
s.postgres_db_operations
import
PostgresStart
from
scripts.
core.handler
s.postgres_db_operations
import
PostgresStart
# mongo access
# mongo access
...
@@ -9,7 +9,7 @@ def mongo_db_access_op():
...
@@ -9,7 +9,7 @@ def mongo_db_access_op():
db_created
=
db_class
.
mongo_create
()
db_created
=
db_class
.
mongo_create
()
while
True
:
while
True
:
try
:
try
:
user_query
=
input
(
"Enter insert/ update/ delete/ view/
view-all/
quit : "
)
user_query
=
input
(
"Enter insert/ update/ delete/ view/ quit : "
)
if
user_query
==
'insert'
:
if
user_query
==
'insert'
:
db_class
.
mongo_insert
(
db_created
)
db_class
.
mongo_insert
(
db_created
)
elif
user_query
==
'update'
:
elif
user_query
==
'update'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment