goctests0 commited on
Commit
0212283
·
verified ·
1 Parent(s): 2020fa0

Update database.py

Browse files
Files changed (1) hide show
  1. 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, nlu_summary, timestamp):
95
- with get_connection() as connection:
96
- return _insert_and_get_id(
97
- connection,
98
- """INSERT INTO interaction
99
- (user_id, input_text, detected_language, translated_text, nlu_summary, timestamp)
100
- VALUES (?, ?, ?, ?, ?, ?)""",
101
- (user_id, input_text, detected_language, translated_text, nlu_summary, timestamp),
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):