move static methods out of main db struct implementation

This commit is contained in:
yggverse 2024-11-12 17:22:07 +02:00
parent 5b3e091f2b
commit da33fa053e
28 changed files with 828 additions and 931 deletions

View file

@ -2,7 +2,6 @@ mod browser;
mod database; mod database;
use browser::Browser; use browser::Browser;
use database::Database;
use crate::profile::Profile; use crate::profile::Profile;
use adw::Application; use adw::Application;
@ -51,7 +50,7 @@ impl App {
match connection.unchecked_transaction() { match connection.unchecked_transaction() {
Ok(transaction) => { Ok(transaction) => {
// Restore previous session from DB // Restore previous session from DB
match Database::records(&transaction) { match database::records(&transaction) {
Ok(records) => { Ok(records) => {
// Restore child components // Restore child components
for record in records { for record in records {
@ -92,11 +91,11 @@ impl App {
// Create transaction // Create transaction
match connection.transaction() { match connection.transaction() {
Ok(transaction) => { Ok(transaction) => {
match Database::records(&transaction) { match database::records(&transaction) {
Ok(records) => { Ok(records) => {
// Cleanup previous session records // Cleanup previous session records
for record in records { for record in records {
match Database::delete(&transaction, &record.id) { match database::delete(&transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
if let Err(e) = if let Err(e) =
@ -110,12 +109,12 @@ impl App {
} }
// Save current session to DB // Save current session to DB
match Database::add(&transaction) { match database::add(&transaction) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
if let Err(e) = browser.save( if let Err(e) = browser.save(
&transaction, &transaction,
&Database::last_insert_id(&transaction), &database::last_insert_id(&transaction),
) { ) {
todo!("{e}") todo!("{e}")
} }
@ -268,7 +267,7 @@ impl App {
// Tools // Tools
fn migrate(tx: &Transaction) -> Result<(), String> { fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -6,7 +6,6 @@ mod window;
use about::About; use about::About;
use action::Action; use action::Action;
use database::Database;
use widget::Widget; use widget::Widget;
use window::Window; use window::Window;
@ -101,10 +100,10 @@ impl Browser {
// Actions // Actions
pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { pub fn clean(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_id) { match database::records(transaction, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
self.window.clean(transaction, &record.id)?; self.window.clean(transaction, &record.id)?;
@ -124,7 +123,7 @@ impl Browser {
} }
pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { pub fn restore(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_id) { match database::records(transaction, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
@ -142,9 +141,9 @@ impl Browser {
} }
pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> {
match Database::add(transaction, app_id) { match database::add(transaction, app_id) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
self.widget.save(transaction, &id)?; self.widget.save(transaction, &id)?;
@ -185,7 +184,7 @@ impl Browser {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_id: i64, not in use // pub app_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser` "CREATE TABLE IF NOT EXISTS `app_browser`
( (
@ -19,13 +14,13 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, app_id: &i64) -> Result<usize, Error> { pub fn add(tx: &Transaction, app_id: &i64) -> Result<usize, Error> {
tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id]) tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id])
} }
pub fn records(tx: &Transaction, app_id: &i64) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, app_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?; let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?;
let result = stmt.query_map([app_id], |row| { let result = stmt.query_map([app_id], |row| {
@ -43,13 +38,12 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id])
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -1,5 +1,4 @@
mod database; mod database;
use database::Database;
use adw::ApplicationWindow; use adw::ApplicationWindow;
use gtk::{ use gtk::{
@ -43,10 +42,10 @@ impl Widget {
// Actions // Actions
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) { match database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// nothing yet.. // nothing yet..
@ -62,7 +61,7 @@ impl Widget {
} }
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) { match database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Restore widget // Restore widget
@ -81,7 +80,7 @@ impl Widget {
} }
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::add( match database::add(
transaction, transaction,
app_browser_id, app_browser_id,
&self.gobject.default_width(), &self.gobject.default_width(),
@ -108,7 +107,7 @@ impl Widget {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -8,12 +8,7 @@ pub struct Table {
pub is_maximized: bool, pub is_maximized: bool,
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_widget` "CREATE TABLE IF NOT EXISTS `app_browser_widget`
( (
@ -25,15 +20,15 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_id: &i64, app_browser_id: &i64,
default_width: &i32, default_width: &i32,
default_height: &i32, default_height: &i32,
is_maximized: &bool, is_maximized: &bool,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_widget` ( "INSERT INTO `app_browser_widget` (
`app_browser_id`, `app_browser_id`,
@ -48,9 +43,9 @@ impl Database {
&(*is_maximized as i64), &(*is_maximized as i64),
], ],
) )
} }
pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_id`, `app_browser_id`,
@ -77,14 +72,13 @@ impl Database {
} }
Ok(records) Ok(records)
}
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])
}
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])
}
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */

View file

@ -5,7 +5,6 @@ mod tab;
mod widget; mod widget;
use action::Action; use action::Action;
use database::Database;
use header::Header; use header::Header;
use sqlite::Transaction; use sqlite::Transaction;
use tab::Tab; use tab::Tab;
@ -107,10 +106,10 @@ impl Window {
} }
pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn clean(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) { match database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
self.tab.clean(transaction, &record.id)?; self.tab.clean(transaction, &record.id)?;
@ -126,7 +125,7 @@ impl Window {
} }
pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn restore(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::records(transaction, app_browser_id) { match database::records(transaction, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
@ -140,12 +139,12 @@ impl Window {
} }
pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> {
match Database::add(transaction, app_browser_id) { match database::add(transaction, app_browser_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
if let Err(e) = self if let Err(e) = self
.tab .tab
.save(transaction, &Database::last_insert_id(transaction)) .save(transaction, &database::last_insert_id(transaction))
{ {
return Err(e.to_string()); return Err(e.to_string());
} }
@ -174,7 +173,7 @@ impl Window {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_browser_id: i64, not in use // pub app_browser_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window` "CREATE TABLE IF NOT EXISTS `app_browser_window`
( (
@ -19,16 +14,16 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> { pub fn add(tx: &Transaction, app_browser_id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)", "INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)",
[app_browser_id], [app_browser_id],
) )
} }
pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_id` FROM `app_browser_window` `app_browser_id` FROM `app_browser_window`
@ -50,13 +45,12 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id])
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -3,7 +3,6 @@ mod item;
mod menu; mod menu;
mod widget; mod widget;
use database::Database;
use item::Item; use item::Item;
use menu::Menu; use menu::Menu;
use widget::Widget; use widget::Widget;
@ -239,10 +238,10 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_id) { match database::records(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
@ -264,7 +263,7 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_id) { match database::records(transaction, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Item::restore( match Item::restore(
@ -297,10 +296,10 @@ impl Tab {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::add(transaction, app_browser_window_id) { match database::add(transaction, app_browser_window_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Read collected HashMap index // Read collected HashMap index
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
@ -339,7 +338,7 @@ impl Tab {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_browser_window_id: i64, not in use // pub app_browser_window_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
( (
@ -19,18 +14,18 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> { pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab` ( "INSERT INTO `app_browser_window_tab` (
`app_browser_window_id` `app_browser_window_id`
) VALUES (?)", ) VALUES (?)",
[app_browser_window_id], [app_browser_window_id],
) )
} }
pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_id` FROM `app_browser_window_tab` `app_browser_window_id` FROM `app_browser_window_tab`
@ -52,13 +47,12 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id])
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -4,7 +4,6 @@ mod page;
mod widget; mod widget;
use action::Action; use action::Action;
use database::Database;
use page::Page; use page::Page;
use widget::Widget; use widget::Widget;
@ -111,10 +110,10 @@ impl Item {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_id) { match database::records(transaction, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
self.page.clean(transaction, &record.id)?; self.page.clean(transaction, &record.id)?;
@ -142,7 +141,7 @@ impl Item {
) -> Result<Vec<Rc<Item>>, String> { ) -> Result<Vec<Rc<Item>>, String> {
let mut items = Vec::new(); let mut items = Vec::new();
match Database::records(transaction, app_browser_window_tab_id) { match database::records(transaction, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Construct new item object // Construct new item object
@ -185,7 +184,7 @@ impl Item {
is_selected: &bool, is_selected: &bool,
is_attention: &bool, is_attention: &bool,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::add( match database::add(
transaction, transaction,
app_browser_window_tab_id, app_browser_window_tab_id,
page_position, page_position,
@ -194,7 +193,7 @@ impl Item {
is_attention, is_attention,
) { ) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
self.page.save(transaction, &id)?; self.page.save(transaction, &id)?;
@ -224,7 +223,7 @@ impl Item {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -8,12 +8,7 @@ pub struct Table {
pub is_attention: bool, pub is_attention: bool,
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item`
( (
@ -26,16 +21,16 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
page_position: &i32, page_position: &i32,
is_pinned: &bool, is_pinned: &bool,
is_selected: &bool, is_selected: &bool,
is_attention: &bool, is_attention: &bool,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item` ( "INSERT INTO `app_browser_window_tab_item` (
`app_browser_window_tab_id`, `app_browser_window_tab_id`,
@ -52,9 +47,9 @@ impl Database {
&(*is_attention as i64), &(*is_attention as i64),
], ],
) )
} }
pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_id`, `app_browser_window_tab_id`,
@ -84,16 +79,15 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item` WHERE `id` = ?",
[id], [id],
) )
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -6,7 +6,6 @@ mod navigation;
mod widget; mod widget;
use content::Content; use content::Content;
use database::Database;
use input::Input; use input::Input;
use meta::{Meta, Status}; use meta::{Meta, Status};
use navigation::Navigation; use navigation::Navigation;
@ -297,10 +296,10 @@ impl Page {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_id) { match database::records(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
self.meta.clean(transaction, &record.id)?; self.meta.clean(transaction, &record.id)?;
@ -325,7 +324,7 @@ impl Page {
self.meta.set_status(Status::SessionRestore); self.meta.set_status(Status::SessionRestore);
// Begin page restore // Begin page restore
match Database::records(transaction, app_browser_window_tab_item_id) { match database::records(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -347,9 +346,9 @@ impl Page {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::add(transaction, app_browser_window_tab_item_id) { match database::add(transaction, app_browser_window_tab_item_id) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
self.meta.save(transaction, &id)?; self.meta.save(transaction, &id)?;
@ -931,7 +930,7 @@ impl Page {
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_browser_window_tab_item_id: i64, not in use // pub app_browser_window_tab_item_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page`
( (
@ -19,21 +14,21 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usize, Error> { pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page` ( "INSERT INTO `app_browser_window_tab_item_page` (
`app_browser_window_tab_item_id` `app_browser_window_tab_item_id`
) VALUES (?)", ) VALUES (?)",
[app_browser_window_tab_item_id], [app_browser_window_tab_item_id],
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_id` `app_browser_window_tab_item_id`
@ -56,16 +51,15 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?",
[id], [id],
) )
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -1,7 +1,6 @@
mod database; mod database;
mod redirect; mod redirect;
use database::Database;
use redirect::Redirect; use redirect::Redirect;
use gtk::glib::GString; use gtk::glib::GString;
@ -112,10 +111,10 @@ impl Meta {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_page_id: &i64, app_browser_window_tab_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_page_id) { match database::records(transaction, app_browser_window_tab_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
// nothing yet.. // nothing yet..
@ -135,7 +134,7 @@ impl Meta {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_page_id: &i64, app_browser_window_tab_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_page_id) { match database::records(transaction, app_browser_window_tab_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Record value can be stored as NULL // Record value can be stored as NULL
@ -161,7 +160,7 @@ impl Meta {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let title = self.title(); let title = self.title();
match Database::add( match database::add(
transaction, transaction,
app_browser_window_tab_page_id, app_browser_window_tab_page_id,
match title.is_empty() { match title.is_empty() {
@ -170,7 +169,7 @@ impl Meta {
}, },
) { ) {
Ok(_) => { Ok(_) => {
// let id = Database::last_insert_id(transaction); // let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
// nothing yet.. // nothing yet..
@ -185,7 +184,7 @@ impl Meta {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -6,12 +6,7 @@ pub struct Table {
pub title: Option<String>, // can be stored as NULL pub title: Option<String>, // can be stored as NULL
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_meta` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_meta`
( (
@ -21,13 +16,13 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
title: Option<&str>, title: Option<&str>,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_meta` ( "INSERT INTO `app_browser_window_tab_item_page_meta` (
`app_browser_window_tab_item_page_id`, `app_browser_window_tab_item_page_id`,
@ -35,12 +30,12 @@ impl Database {
) VALUES (?, ?)", ) VALUES (?, ?)",
(app_browser_window_tab_item_page_id, title), (app_browser_window_tab_item_page_id, title),
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_page_id`, `app_browser_window_tab_item_page_id`,
@ -65,17 +60,16 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_page_meta` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_page_meta` WHERE `id` = ?",
[id], [id],
) )
}
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */
} }
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */

View file

@ -7,7 +7,6 @@ mod request;
mod widget; mod widget;
use bookmark::Bookmark; use bookmark::Bookmark;
use database::Database;
use history::History; use history::History;
use home::Home; use home::Home;
use reload::Reload; use reload::Reload;
@ -79,10 +78,10 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_page_id) { match database::records(transaction, app_browser_window_tab_item_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
self.request.clean(transaction, &record.id)?; self.request.clean(transaction, &record.id)?;
@ -102,7 +101,7 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_page_id) { match database::records(transaction, app_browser_window_tab_item_page_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -120,9 +119,9 @@ impl Navigation {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::add(transaction, app_browser_window_tab_item_page_id) { match database::add(transaction, app_browser_window_tab_item_page_id) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
self.request.save(transaction, &id)?; self.request.save(transaction, &id)?;
@ -165,7 +164,7 @@ impl Navigation {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_browser_window_tab_item_page_id: i64, not in use // pub app_browser_window_tab_item_page_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation`
( (
@ -19,24 +14,21 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result<usize, Error> {
tx: &Transaction,
app_browser_window_tab_item_page_id: &i64,
) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_navigation` ( "INSERT INTO `app_browser_window_tab_item_page_navigation` (
`app_browser_window_tab_item_page_id` `app_browser_window_tab_item_page_id`
) VALUES (?)", ) VALUES (?)",
[app_browser_window_tab_item_page_id], [app_browser_window_tab_item_page_id],
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_id: &i64, app_browser_window_tab_item_page_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_page_id` `app_browser_window_tab_item_page_id`
@ -59,16 +51,15 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?",
[id], [id],
) )
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -1,7 +1,6 @@
mod database; mod database;
mod widget; mod widget;
use database::Database;
use widget::Widget; use widget::Widget;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
@ -39,10 +38,10 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) { match database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
self.widget.clean(transaction, &record.id)?; self.widget.clean(transaction, &record.id)?;
@ -62,7 +61,7 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_page_navigation_id) { match database::records(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to the item childs // Delegate restore action to the item childs
@ -80,9 +79,9 @@ impl Request {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::add(transaction, app_browser_window_tab_item_page_navigation_id) { match database::add(transaction, app_browser_window_tab_item_page_navigation_id) {
Ok(_) => { Ok(_) => {
let id = Database::last_insert_id(transaction); let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
self.widget.save(transaction, &id)?; self.widget.save(transaction, &id)?;
@ -110,7 +109,7 @@ impl Request {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -5,12 +5,7 @@ pub struct Table {
// pub app_browser_window_tab_item_page_navigation_id: i64, not in use // pub app_browser_window_tab_item_page_navigation_id: i64, not in use
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request`
( (
@ -19,24 +14,24 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_navigation_request` ( "INSERT INTO `app_browser_window_tab_item_page_navigation_request` (
`app_browser_window_tab_item_page_navigation_id` `app_browser_window_tab_item_page_navigation_id`
) VALUES (?)", ) VALUES (?)",
[app_browser_window_tab_item_page_navigation_id], [app_browser_window_tab_item_page_navigation_id],
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_id: &i64, app_browser_window_tab_item_page_navigation_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_page_navigation_id` `app_browser_window_tab_item_page_navigation_id`
@ -59,16 +54,15 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?",
[id], [id],
) )
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -1,7 +1,5 @@
mod database; mod database;
use database::Database;
use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction};
use gtk::{ use gtk::{
glib::{timeout_add_local, ControlFlow, SourceId}, glib::{timeout_add_local, ControlFlow, SourceId},
@ -82,13 +80,13 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records( match database::records(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
) { ) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
// nothing yet.. // nothing yet..
@ -108,7 +106,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records( match database::records(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
) { ) {
@ -136,7 +134,7 @@ impl Widget {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let text = self.gobject.text(); let text = self.gobject.text();
match Database::add( match database::add(
transaction, transaction,
app_browser_window_tab_item_page_navigation_request_id, app_browser_window_tab_item_page_navigation_request_id,
match text.is_empty() { match text.is_empty() {
@ -145,7 +143,7 @@ impl Widget {
}, },
) { ) {
Ok(_) => { Ok(_) => {
// let id = Database::last_insert_id(transaction); // let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
// nothing yet.. // nothing yet..
@ -211,7 +209,7 @@ impl Widget {
// Tools // Tools
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -6,12 +6,7 @@ pub struct Table {
pub text: Option<String>, // can be stored as NULL pub text: Option<String>, // can be stored as NULL
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request_widget` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request_widget`
( (
@ -21,13 +16,13 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
text: Option<&str>, text: Option<&str>,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_page_navigation_request_widget` ( "INSERT INTO `app_browser_window_tab_item_page_navigation_request_widget` (
`app_browser_window_tab_item_page_navigation_request_id`, `app_browser_window_tab_item_page_navigation_request_id`,
@ -35,12 +30,12 @@ impl Database {
) VALUES (?, ?)", ) VALUES (?, ?)",
(app_browser_window_tab_item_page_navigation_request_id, text), (app_browser_window_tab_item_page_navigation_request_id, text),
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_page_navigation_request_id: &i64, app_browser_window_tab_item_page_navigation_request_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_page_navigation_request_id`, `app_browser_window_tab_item_page_navigation_request_id`,
@ -68,17 +63,16 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_page_navigation_request_widget` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_page_navigation_request_widget` WHERE `id` = ?",
[id], [id],
) )
}
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */
} }
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */

View file

@ -1,7 +1,5 @@
mod database; mod database;
use database::Database;
use crate::app::browser::window::action::Position; use crate::app::browser::window::action::Position;
use adw::{TabPage, TabView}; use adw::{TabPage, TabView};
use gtk::prelude::IsA; use gtk::prelude::IsA;
@ -62,10 +60,10 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_id) { match database::records(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match Database::delete(transaction, &record.id) { match database::delete(transaction, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to the item childs // Delegate clean action to the item childs
// nothing yet.. // nothing yet..
@ -85,7 +83,7 @@ impl Widget {
transaction: &Transaction, transaction: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<(), String> { ) -> Result<(), String> {
match Database::records(transaction, app_browser_window_tab_item_id) { match database::records(transaction, app_browser_window_tab_item_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Record value can be stored as NULL // Record value can be stored as NULL
@ -111,7 +109,7 @@ impl Widget {
// Keep value in memory until operation complete // Keep value in memory until operation complete
let title = self.gobject.title(); let title = self.gobject.title();
match Database::add( match database::add(
transaction, transaction,
app_browser_window_tab_item_id, app_browser_window_tab_item_id,
match title.is_empty() { match title.is_empty() {
@ -120,7 +118,7 @@ impl Widget {
}, },
) { ) {
Ok(_) => { Ok(_) => {
// let id = Database::last_insert_id(transaction); // let id = database::last_insert_id(transaction);
// Delegate save action to childs // Delegate save action to childs
// nothing yet.. // nothing yet..
@ -142,7 +140,7 @@ impl Widget {
pub fn migrate(tx: &Transaction) -> Result<(), String> { pub fn migrate(tx: &Transaction) -> Result<(), String> {
// Migrate self components // Migrate self components
if let Err(e) = Database::init(tx) { if let Err(e) = database::init(tx) {
return Err(e.to_string()); return Err(e.to_string());
} }

View file

@ -6,12 +6,7 @@ pub struct Table {
pub title: Option<String>, // can be stored as NULL pub title: Option<String>, // can be stored as NULL
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_widget` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_widget`
( (
@ -21,13 +16,13 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add( pub fn add(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
title: Option<&str>, title: Option<&str>,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `app_browser_window_tab_item_widget` ( "INSERT INTO `app_browser_window_tab_item_widget` (
`app_browser_window_tab_item_id`, `app_browser_window_tab_item_id`,
@ -35,12 +30,12 @@ impl Database {
) VALUES (?, ?)", ) VALUES (?, ?)",
(app_browser_window_tab_item_id, title), (app_browser_window_tab_item_id, title),
) )
} }
pub fn records( pub fn records(
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_item_id: &i64, app_browser_window_tab_item_id: &i64,
) -> Result<Vec<Table>, Error> { ) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare( let mut stmt = tx.prepare(
"SELECT `id`, "SELECT `id`,
`app_browser_window_tab_item_id`, `app_browser_window_tab_item_id`,
@ -65,17 +60,16 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute( tx.execute(
"DELETE FROM `app_browser_window_tab_item_widget` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_item_widget` WHERE `id` = ?",
[id], [id],
) )
}
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */
} }
/* not in use
pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid()
} */

View file

@ -4,12 +4,7 @@ pub struct Table {
pub id: i64, pub id: i64,
} }
pub struct Database { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Database {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `app` "CREATE TABLE IF NOT EXISTS `app`
( (
@ -17,13 +12,13 @@ impl Database {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction) -> Result<usize, Error> { pub fn add(tx: &Transaction) -> Result<usize, Error> {
tx.execute("INSERT INTO `app` DEFAULT VALUES", []) tx.execute("INSERT INTO `app` DEFAULT VALUES", [])
} }
pub fn records(tx: &Transaction) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction) -> Result<Vec<Table>, Error> {
let mut stmt = tx.prepare("SELECT `id` FROM `app`")?; let mut stmt = tx.prepare("SELECT `id` FROM `app`")?;
let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?; let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?;
@ -35,13 +30,12 @@ impl Database {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `app` WHERE `id` = ?", [id])
} }
pub fn last_insert_id(tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
}
} }

View file

@ -2,10 +2,6 @@ mod bookmark;
mod history; mod history;
mod identity; mod identity;
use bookmark::Bookmark;
use history::History;
use identity::Identity;
use sqlite::{Connection, Error}; use sqlite::{Connection, Error};
use std::{ use std::{
path::Path, path::Path,
@ -56,9 +52,9 @@ fn init(mut connection: RwLockWriteGuard<'_, Connection>) -> Result<(), Error> {
let transaction = connection.transaction()?; let transaction = connection.transaction()?;
// Init profile components // Init profile components
Bookmark::init(&transaction)?; bookmark::init(&transaction)?;
History::init(&transaction)?; history::init(&transaction)?;
Identity::init(&transaction)?; identity::init(&transaction)?;
// Apply changes // Apply changes
transaction.commit()?; transaction.commit()?;

View file

@ -11,8 +11,7 @@ pub struct Bookmark {
// nothing yet.. // nothing yet..
} }
impl Bookmark { pub fn init(tx: &Transaction) -> Result<usize, Error> {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `bookmark` "CREATE TABLE IF NOT EXISTS `bookmark`
( (
@ -22,9 +21,9 @@ impl Bookmark {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result<usize, Error> { pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `bookmark` ( "INSERT INTO `bookmark` (
`time`, `time`,
@ -32,9 +31,9 @@ impl Bookmark {
) VALUES (?, ?)", ) VALUES (?, ?)",
(time.to_unix(), request), (time.to_unix(), request),
) )
} }
pub fn records(tx: &Transaction, request: Option<&str>) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, request: Option<&str>) -> Result<Vec<Table>, Error> {
let mut stmt = let mut stmt =
tx.prepare("SELECT `id`, `time`, `request` FROM `bookmark` WHERE `request` LIKE ?")?; tx.prepare("SELECT `id`, `time`, `request` FROM `bookmark` WHERE `request` LIKE ?")?;
@ -59,9 +58,8 @@ impl Bookmark {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `bookmark` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `bookmark` WHERE `id` = ?", [id])
}
} }

View file

@ -11,8 +11,7 @@ pub struct History {
// nothing yet.. // nothing yet..
} }
impl History { pub fn init(tx: &Transaction) -> Result<usize, Error> {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `history` "CREATE TABLE IF NOT EXISTS `history`
( (
@ -22,9 +21,9 @@ impl History {
)", )",
[], [],
) )
} }
pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result<usize, Error> { pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result<usize, Error> {
tx.execute( tx.execute(
"INSERT INTO `history` ( "INSERT INTO `history` (
`time`, `time`,
@ -32,9 +31,9 @@ impl History {
) VALUES (?, ?)", ) VALUES (?, ?)",
(time.to_unix(), request), (time.to_unix(), request),
) )
} }
pub fn records(tx: &Transaction, request: Option<&str>) -> Result<Vec<Table>, Error> { pub fn records(tx: &Transaction, request: Option<&str>) -> Result<Vec<Table>, Error> {
let mut stmt = let mut stmt =
tx.prepare("SELECT `id`, `time`, `request` FROM `history` WHERE `request` LIKE ?")?; tx.prepare("SELECT `id`, `time`, `request` FROM `history` WHERE `request` LIKE ?")?;
@ -59,9 +58,8 @@ impl History {
} }
Ok(records) Ok(records)
} }
pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `history` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `history` WHERE `id` = ?", [id])
}
} }

View file

@ -2,15 +2,10 @@ use sqlite::{Error, Transaction};
pub struct Table { pub struct Table {
pub id: i64, pub id: i64,
// pub app_id: i64, not in use // pub app_id: i64,
} }
pub struct Identity { pub fn init(tx: &Transaction) -> Result<usize, Error> {
// nothing yet..
}
impl Identity {
pub fn init(tx: &Transaction) -> Result<usize, Error> {
tx.execute( tx.execute(
"CREATE TABLE IF NOT EXISTS `identity` "CREATE TABLE IF NOT EXISTS `identity`
( (
@ -22,5 +17,4 @@ impl Identity {
)", )",
[], [],
) )
}
} }