Skip to content

Commit 235eb90

Browse files
committed
db script fix
1 parent 6215474 commit 235eb90

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

crates/db-script/src/lib.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,31 @@ pub mod conversation_to_words {
2424
}
2525

2626
pub async fn run(conn: &libsql::Connection) {
27-
let mut rows = conn
27+
let mut rows = match conn
2828
.query("SELECT id, conversations FROM sessions", ())
2929
.await
30-
.unwrap();
30+
{
31+
Ok(rows) => rows,
32+
Err(_) => return,
33+
};
3134

3235
let mut sessions = Vec::new();
3336

34-
while let Some(row) = rows.next().await.unwrap() {
35-
let id = row.get_str(0).expect("id").to_string();
36-
let conversations_str = row.get_str(8).expect("conversations").to_string();
37+
while let Some(row_result) = rows.next().await.transpose() {
38+
let row = match row_result {
39+
Ok(row) => row,
40+
Err(_) => continue,
41+
};
42+
43+
let id = match row.get_str(0) {
44+
Ok(id) => id.to_string(),
45+
Err(_) => continue,
46+
};
47+
48+
let conversations_str = match row.get_str(8) {
49+
Ok(convs) => convs.to_string(),
50+
Err(_) => continue,
51+
};
3752

3853
let conversations: Vec<hypr_listener_interface::ConversationChunk> =
3954
serde_json::from_str(&conversations_str).unwrap_or_default();
@@ -48,19 +63,25 @@ pub mod conversation_to_words {
4863

4964
let words = transform(conversations);
5065

51-
conn.execute(
52-
"UPDATE sessions SET words = ? WHERE id = ?",
53-
(serde_json::to_string(&words).unwrap(), id.clone()),
54-
)
55-
.await
56-
.unwrap();
66+
if let Err(_) = conn
67+
.execute(
68+
"UPDATE sessions SET words = ? WHERE id = ?",
69+
(
70+
serde_json::to_string(&words).unwrap_or_default(),
71+
id.clone(),
72+
),
73+
)
74+
.await
75+
{
76+
continue;
77+
}
5778

58-
conn.execute(
59-
"UPDATE sessions SET conversations = ? WHERE id = ?",
60-
("[]", id),
61-
)
62-
.await
63-
.unwrap();
79+
let _ = conn
80+
.execute(
81+
"UPDATE sessions SET conversations = ? WHERE id = ?",
82+
("[]", id),
83+
)
84+
.await;
6485
}
6586
}
6687
}

0 commit comments

Comments
 (0)