feat:增加查询用户历史消息功能
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import sqlite3
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
from model import SessionMessageResponse
|
||||
|
||||
|
||||
def init_db():
|
||||
@@ -20,6 +23,34 @@ def init_db():
|
||||
conn.close()
|
||||
|
||||
|
||||
def query_session_messages(username: str) -> List[SessionMessageResponse]:
|
||||
conn = sqlite3.connect(os.getenv("SQLITE_DB_PATH"))
|
||||
conn.row_factory = sqlite3.Row
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT username, title, thread_id
|
||||
FROM session
|
||||
WHERE username = ?
|
||||
ORDER BY created_time DESC
|
||||
""",
|
||||
(username,)
|
||||
)
|
||||
|
||||
rows = cursor.fetchall()
|
||||
conn.close()
|
||||
|
||||
return [
|
||||
SessionMessageResponse(
|
||||
username=row["username"],
|
||||
title=row["title"],
|
||||
thread_id=row["thread_id"],
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
|
||||
|
||||
def exists_session(thread_id: str, username: str) -> bool:
|
||||
conn = sqlite3.connect(os.getenv("SQLITE_DB_PATH"))
|
||||
cursor = conn.cursor()
|
||||
|
||||
Reference in New Issue
Block a user