Skip to content

Commit

Permalink
Fix wrong data insert
Browse files Browse the repository at this point in the history
  • Loading branch information
yo1frenchtoast committed Apr 24, 2020
1 parent d90209d commit 34443a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions api/dbdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ def insert(table, data):
cursor = connection.cursor()

columns = ', '.join(data.keys())
placeholders = ', '.join(["%s"]*len(data))
values = ''
for key in data.keys():
values += "\"{}\", ".format(data[key])
values = values[:-2]

query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, placeholders)
query = "INSERT INTO {}({}) VALUES ({})".format(table, columns, values)

try:
cursor.execute(query, data.values())
cursor.execute(query)
connection.commit()
return "Data inserted successfully", None
except mysql.connector.Error as e:
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
env_file:
- .env
deploy:
replicas: 3
replicas: 1

web:
image: 127.0.0.1:5000/hermod-api
Expand All @@ -52,3 +52,5 @@ services:
- 9090:9090
# cap_add:
# - SYS_PTRACE
# deploy:
# replicas: 1

0 comments on commit 34443a3

Please sign in to comment.