#python #postgresql #sql-delete #delete-row
Вопрос:
колба, которую я получаю, объект dict не имеет атрибута ниже, когда я передаю это для метода удаления в postman
def delete_package():
try:
data = request.json
#converting json object to dataframe
df = pd.DataFrame([data])
#extracting table_name,where clause attributes and value of the where clause attributes
table_name = df.filter(items=['table_name'],axis=1).values[0][0].lower()
where = df.filter(items=['where'],axis=1).values[0][0].lower()
value = df.filter(items=['value'],axis=1).values[0][0]
#checking if the value is of string type to lower() the input else if it is of interger value will be unchanged
if isinstance(value,str)==True:
value = value.lower()
args=get_args()
connection,_,_ = get_db_connection(args,psycopg2)#module name should be user input
status = delete_records(table_name, where, value, connection)
if status == True:
return {"status": "success", "message": 'successfully deleted'}
else:
return status
except Exception as err:
return {"status": "failed", "message": 'Exception occurred- ' str(err)}
postgres.py
это код для postgres.py
def delete_records(table, unique_identifier, uniqueid, connection):#put a check if the data is present #put similar check here
'''
deletes record from database
Params:
table - tablename where deletion will occur
unique_identifier - column associated with 'where' clause
uniqueid - value of the column associated with where clause
connection - database connection
'''
col_name_list = get_columnname_fromdb(table,connection)
if unique_identifier in col_name_list:
# query = ''' DELETE FROM test_docker."{table_name}" where "{column_name}" = '{uique_id}'; '''.format(table_name=table,
# column_name = unique_identifier,
# uique_id = uniqueid)
query = ''' DELETE FROM "{table_name}" where "{column_name}" = '{uique_id}'; '''.format(table_name=table,
column_name = unique_identifier,
uique_id = uniqueid)
connection.cursor().execute(query)
connection.commit()
return True
else:
return ({"status": "failed", "message": 'check data for where clause. Also check the spelling'})
почтальон
когда я передаю это
{
"table_name":"body_detail",
"where":{"job_name":"tight", "help_name":"name", "condition":"hehehee"},
"value":"True"
}
я получаю ошибку объект dict не имеет атрибута ниже
, что я должен передать почтальону для успешного удаления