Skip to content

Commit 133cad0

Browse files
committed
fix calendar ops
1 parent 42a7f01 commit 133cad0

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

crates/db-user/src/calendars_ops.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@ use super::{Calendar, UserDatabase};
33
impl UserDatabase {
44
pub async fn get_calendar(
55
&self,
6-
calendar_id: impl AsRef<str>,
7-
) -> Result<Calendar, crate::Error> {
6+
id: impl AsRef<str>,
7+
) -> Result<Option<Calendar>, crate::Error> {
88
let conn = self.conn()?;
99

1010
let mut rows = conn
11-
.query(
12-
"SELECT * FROM calendars WHERE id = ?",
13-
vec![calendar_id.as_ref()],
14-
)
11+
.query("SELECT * FROM calendars WHERE id = ?", vec![id.as_ref()])
1512
.await?;
16-
let row = rows.next().await?.unwrap();
17-
let calendar: Calendar = libsql::de::from_row(&row)?;
18-
Ok(calendar)
13+
14+
match rows.next().await? {
15+
Some(row) => {
16+
let calendar: Calendar = libsql::de::from_row(&row)?;
17+
Ok(Some(calendar))
18+
}
19+
None => Ok(None),
20+
}
1921
}
2022

2123
pub async fn list_calendars(

plugins/db/js/bindings.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async getEvent(id: string) : Promise<Event | null> {
1313
async listEvents(filter: ListEventFilter | null) : Promise<Event[]> {
1414
return await TAURI_INVOKE("plugin:db|list_events", { filter });
1515
},
16-
async getCalendar(calendarId: string) : Promise<Calendar> {
16+
async getCalendar(calendarId: string) : Promise<Calendar | null> {
1717
return await TAURI_INVOKE("plugin:db|get_calendar", { calendarId });
1818
},
1919
async listCalendars(userId: string) : Promise<Calendar[]> {

plugins/db/src/commands/calendars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pub async fn get_calendar(
55
state: tauri::State<'_, crate::ManagedState>,
66
calendar_id: String,
7-
) -> Result<hypr_db_user::Calendar, String> {
7+
) -> Result<Option<hypr_db_user::Calendar>, String> {
88
let guard = state.lock().await;
99

1010
let db = guard

0 commit comments

Comments
 (0)