Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions langchain_postgres/chat_message_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This client provides support for both sync and async via psycopg 3.
"""

from __future__ import annotations

import json
Expand Down Expand Up @@ -370,3 +371,12 @@ async def aclear(self) -> None:
async with self._aconnection.cursor() as cursor:
await cursor.execute(query, {"session_id": self._session_id})
await self._aconnection.commit()

def update_session_id(self, new_session_id: str) -> None:
"""Update the session ID for the current instance and in the database"""
update_query = (
f"UPDATE {self._table_name} SET session_id = %s WHERE session_id = %s;"
)
with self._connection.cursor() as cursor:
cursor.execute(update_query, (new_session_id, self._session_id))
self._connection.commit()