|
|
|
@ -3,6 +3,7 @@ use sqlite::{Error, Transaction};
@@ -3,6 +3,7 @@ use sqlite::{Error, Transaction};
|
|
|
|
|
pub struct Table { |
|
|
|
|
pub id: i64, |
|
|
|
|
// pub app_browser_window_id: i64, not in use
|
|
|
|
|
pub is_current: bool, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub struct Database { |
|
|
|
@ -15,7 +16,8 @@ impl Database {
@@ -15,7 +16,8 @@ impl Database {
|
|
|
|
|
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab` |
|
|
|
|
( |
|
|
|
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, |
|
|
|
|
`app_browser_window_id` INTEGER NOT NULL |
|
|
|
|
`app_browser_window_id` INTEGER NOT NULL, |
|
|
|
|
`is_current` INTEGER NOT NULL |
|
|
|
|
)", |
|
|
|
|
[], |
|
|
|
|
)?; |
|
|
|
@ -23,10 +25,18 @@ impl Database {
@@ -23,10 +25,18 @@ impl Database {
|
|
|
|
|
Ok(Self {}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn add(&self, tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> { |
|
|
|
|
pub fn add( |
|
|
|
|
&self, |
|
|
|
|
tx: &Transaction, |
|
|
|
|
app_browser_window_id: &i64, |
|
|
|
|
is_current: &bool, |
|
|
|
|
) -> Result<usize, Error> { |
|
|
|
|
tx.execute( |
|
|
|
|
"INSERT INTO `app_browser_window_tab` (`app_browser_window_id`) VALUES (?)", |
|
|
|
|
[app_browser_window_id], |
|
|
|
|
"INSERT INTO `app_browser_window_tab` ( |
|
|
|
|
`app_browser_window_id`, |
|
|
|
|
`is_current` |
|
|
|
|
) VALUES (?,?)", |
|
|
|
|
[app_browser_window_id, &(*is_current as i64)], |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -35,14 +45,18 @@ impl Database {
@@ -35,14 +45,18 @@ impl Database {
|
|
|
|
|
tx: &Transaction, |
|
|
|
|
app_browser_window_id: &i64, |
|
|
|
|
) -> Result<Vec<Table>, Error> { |
|
|
|
|
let mut stmt = tx.prepare("SELECT `id`, |
|
|
|
|
`app_browser_window_id` FROM `app_browser_window_tab` |
|
|
|
|
WHERE `app_browser_window_id` = ?")?; |
|
|
|
|
let mut stmt = tx.prepare( |
|
|
|
|
"SELECT `id`, |
|
|
|
|
`app_browser_window_id`, |
|
|
|
|
`is_current` FROM `app_browser_window_tab` |
|
|
|
|
WHERE `app_browser_window_id` = ?", |
|
|
|
|
)?; |
|
|
|
|
|
|
|
|
|
let result = stmt.query_map([app_browser_window_id], |row| { |
|
|
|
|
Ok(Table { |
|
|
|
|
id: row.get(0)?, |
|
|
|
|
// app_browser_window_id: row.get(1)?, not in use
|
|
|
|
|
is_current: row.get(2)?, |
|
|
|
|
}) |
|
|
|
|
})?; |
|
|
|
|
|
|
|
|
@ -60,7 +74,8 @@ impl Database {
@@ -60,7 +74,8 @@ impl Database {
|
|
|
|
|
tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* not in use
|
|
|
|
|
pub fn last_insert_id(&self, tx: &Transaction) -> i64 { |
|
|
|
|
tx.last_insert_rowid() |
|
|
|
|
} |
|
|
|
|
} */ |
|
|
|
|
} |
|
|
|
|