Update database.py
Browse files- database.py +12 -2
database.py
CHANGED
|
@@ -142,15 +142,25 @@ def end_session(session_id, end_time):
|
|
| 142 |
def add_interaction(user_id, input_text, detected_language, translated_text,
|
| 143 |
nlu_summary, timestamp):
|
| 144 |
p = _placeholder()
|
|
|
|
| 145 |
sql = (
|
| 146 |
f"INSERT INTO interaction "
|
| 147 |
f"(user_id, input_text, detected_language, translated_text, nlu_summary, timestamp) "
|
| 148 |
f"VALUES ({p}, {p}, {p}, {p}, {p}, {p})"
|
| 149 |
)
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
with _connection() as conn:
|
| 152 |
if DATABASE_URL:
|
| 153 |
-
cursor = _run(conn, sql
|
| 154 |
return cursor.fetchone()["id"]
|
| 155 |
else:
|
| 156 |
cursor = _run(conn, sql, params)
|
|
|
|
| 142 |
def add_interaction(user_id, input_text, detected_language, translated_text,
|
| 143 |
nlu_summary, timestamp):
|
| 144 |
p = _placeholder()
|
| 145 |
+
|
| 146 |
sql = (
|
| 147 |
f"INSERT INTO interaction "
|
| 148 |
f"(user_id, input_text, detected_language, translated_text, nlu_summary, timestamp) "
|
| 149 |
f"VALUES ({p}, {p}, {p}, {p}, {p}, {p})"
|
| 150 |
)
|
| 151 |
+
|
| 152 |
+
params = (
|
| 153 |
+
user_id,
|
| 154 |
+
input_text,
|
| 155 |
+
detected_language,
|
| 156 |
+
translated_text,
|
| 157 |
+
nlu_summary,
|
| 158 |
+
timestamp
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
with _connection() as conn:
|
| 162 |
if DATABASE_URL:
|
| 163 |
+
cursor = _run(conn, sql + " RETURNING id", params)
|
| 164 |
return cursor.fetchone()["id"]
|
| 165 |
else:
|
| 166 |
cursor = _run(conn, sql, params)
|