Update database.py
Browse files- database.py +26 -9
database.py
CHANGED
|
@@ -91,15 +91,32 @@ def end_session(session_id, end_time):
|
|
| 91 |
_run(connection, "UPDATE session SET end_time = ? WHERE id = ?", (end_time, session_id))
|
| 92 |
|
| 93 |
|
| 94 |
-
def add_interaction(user_id, input_text, detected_language, translated_text,
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
def get_interactions_for_user(user_id):
|
|
|
|
| 91 |
_run(connection, "UPDATE session SET end_time = ? WHERE id = ?", (end_time, session_id))
|
| 92 |
|
| 93 |
|
| 94 |
+
def add_interaction(user_id, input_text, detected_language, translated_text,
|
| 95 |
+
nlu_summary, timestamp):
|
| 96 |
+
p = _placeholder()
|
| 97 |
+
|
| 98 |
+
sql = (
|
| 99 |
+
f"INSERT INTO interaction "
|
| 100 |
+
f"(user_id, input_text, detected_language, translated_text, nlu_summary, timestamp) "
|
| 101 |
+
f"VALUES ({p}, {p}, {p}, {p}, {p}, {p})"
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
params = (
|
| 105 |
+
user_id,
|
| 106 |
+
input_text,
|
| 107 |
+
detected_language,
|
| 108 |
+
translated_text,
|
| 109 |
+
nlu_summary,
|
| 110 |
+
timestamp
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
with _connection() as conn:
|
| 114 |
+
if DATABASE_URL:
|
| 115 |
+
cursor = _run(conn, sql + " RETURNING id", params)
|
| 116 |
+
return cursor.fetchone()["id"]
|
| 117 |
+
else:
|
| 118 |
+
cursor = _run(conn, sql, params)
|
| 119 |
+
return cursor.lastrowid
|
| 120 |
|
| 121 |
|
| 122 |
def get_interactions_for_user(user_id):
|