Skip to content
Merged
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
16 changes: 11 additions & 5 deletions crates/goose/src/session/session_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@ impl SessionStorage {
}

async fn add_message(&self, session_id: &str, message: &Message) -> Result<()> {
let mut tx = self.pool.begin().await?;

let metadata_json = serde_json::to_string(&message.metadata)?;

sqlx::query(
Expand All @@ -983,14 +985,15 @@ impl SessionStorage {
.bind(serde_json::to_string(&message.content)?)
.bind(message.created)
.bind(metadata_json)
.execute(&self.pool)
.execute(&mut *tx)
.await?;

sqlx::query("UPDATE sessions SET updated_at = datetime('now') WHERE id = ?")
.bind(session_id)
.execute(&self.pool)
.execute(&mut *tx)
.await?;

tx.commit().await?;
Ok(())
}

Expand Down Expand Up @@ -1049,10 +1052,12 @@ impl SessionStorage {
}

async fn delete_session(&self, session_id: &str) -> Result<()> {
let mut tx = self.pool.begin().await?;

let exists =
sqlx::query_scalar::<_, bool>("SELECT EXISTS(SELECT 1 FROM sessions WHERE id = ?)")
.bind(session_id)
.fetch_one(&self.pool)
.fetch_one(&mut *tx)
.await?;

if !exists {
Expand All @@ -1061,14 +1066,15 @@ impl SessionStorage {

sqlx::query("DELETE FROM messages WHERE session_id = ?")
.bind(session_id)
.execute(&self.pool)
.execute(&mut *tx)
.await?;

sqlx::query("DELETE FROM sessions WHERE id = ?")
.bind(session_id)
.execute(&self.pool)
.execute(&mut *tx)
.await?;

tx.commit().await?;
Ok(())
}

Expand Down