fix: replace upsert syntax to support SQLite lower version

This commit is contained in:
zhayujie
2026-02-26 10:44:04 +08:00
parent 9917552b4b
commit 925d728a86

View File

@@ -341,19 +341,21 @@ class ConversationStore:
conn = self._connect() conn = self._connect()
try: try:
with conn: with conn:
# Upsert session row. # INSERT OR IGNORE creates the row on first visit;
# channel_type is set only on INSERT (first time); subsequent # the UPDATE always refreshes last_active.
# appends just update last_active to avoid overwriting the value. # Avoids ON CONFLICT...DO UPDATE (requires SQLite >= 3.24).
conn.execute( conn.execute(
""" """
INSERT INTO sessions INSERT OR IGNORE INTO sessions
(session_id, channel_type, created_at, last_active, msg_count) (session_id, channel_type, created_at, last_active, msg_count)
VALUES (?, ?, ?, ?, 0) VALUES (?, ?, ?, ?, 0)
ON CONFLICT(session_id) DO UPDATE SET
last_active = excluded.last_active
""", """,
(session_id, channel_type, now, now), (session_id, channel_type, now, now),
) )
conn.execute(
"UPDATE sessions SET last_active = ? WHERE session_id = ?",
(now, session_id),
)
# Determine starting seq for the new batch. # Determine starting seq for the new batch.
row = conn.execute( row = conn.execute(