implement tab restore feature

This commit is contained in:
yggverse 2024-10-11 04:37:06 +03:00
parent d074ef17fe
commit 09c08b2b6f
7 changed files with 58 additions and 72 deletions

View file

@ -3,6 +3,7 @@ use sqlite::{Error, Transaction};
pub struct Table {
pub id: i64,
// pub app_browser_window_tab_id: i64, not in use
pub is_selected: bool,
}
pub struct Database {
@ -16,7 +17,8 @@ impl Database {
(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`app_browser_window_tab_id` INTEGER NOT NULL,
`page_number` INTEGER NOT NULL
`page_position` INTEGER NOT NULL,
`is_selected` INTEGER NOT NULL
)",
[],
)
@ -25,29 +27,38 @@ impl Database {
pub fn add(
tx: &Transaction,
app_browser_window_tab_id: &i64,
page_number: &u32,
page_position: &i32,
is_selected: &bool,
) -> Result<usize, Error> {
tx.execute(
"INSERT INTO `app_browser_window_tab_item` (
`app_browser_window_tab_id`,
`page_number`
) VALUES (?, ?)",
[app_browser_window_tab_id, &(*page_number as i64)],
`page_position`,
`is_selected`
) VALUES (?, ?, ?)",
[
app_browser_window_tab_id,
&(*page_position as i64),
&(*is_selected as i64),
],
)
}
pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare(
"SELECT `id`,
`app_browser_window_tab_id` FROM `app_browser_window_tab_item`
WHERE `app_browser_window_tab_id` = ?
ORDER BY `page_number` ASC", // just order by, no store in struct wanted
`app_browser_window_tab_id`,
`is_selected`
FROM `app_browser_window_tab_item`
WHERE `app_browser_window_tab_id` = ?
ORDER BY `page_position` ASC", // just order by, no store in struct wanted
)?;
let result = stmt.query_map([app_browser_window_tab_id], |row| {
Ok(Table {
id: row.get(0)?,
// app_browser_window_tab_id: row.get(1)?, not in use
is_selected: row.get(2)?,
})
})?;