From da33fa053e89717fe698d9f11780ae2cc1a250ff Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 12 Nov 2024 17:22:07 +0200 Subject: [PATCH] move static methods out of main db struct implementation --- src/app.rs | 13 +- src/app/browser.rs | 13 +- src/app/browser/database.rs | 84 +++++----- src/app/browser/widget.rs | 11 +- src/app/browser/widget/database.rs | 136 ++++++++-------- src/app/browser/window.rs | 13 +- src/app/browser/window/database.rs | 98 ++++++----- src/app/browser/window/tab.rs | 13 +- src/app/browser/window/tab/database.rs | 102 ++++++------ src/app/browser/window/tab/item.rs | 13 +- src/app/browser/window/tab/item/database.rs | 152 +++++++++--------- src/app/browser/window/tab/item/page.rs | 13 +- .../browser/window/tab/item/page/database.rs | 108 ++++++------- src/app/browser/window/tab/item/page/meta.rs | 13 +- .../window/tab/item/page/meta/database.rs | 124 +++++++------- .../window/tab/item/page/navigation.rs | 13 +- .../tab/item/page/navigation/database.rs | 111 ++++++------- .../tab/item/page/navigation/request.rs | 13 +- .../item/page/navigation/request/database.rs | 114 +++++++------ .../item/page/navigation/request/widget.rs | 14 +- .../navigation/request/widget/database.rs | 130 +++++++-------- src/app/browser/window/tab/item/widget.rs | 14 +- .../window/tab/item/widget/database.rs | 124 +++++++------- src/app/database.rs | 70 ++++---- src/profile/database.rs | 10 +- src/profile/database/bookmark.rs | 104 ++++++------ src/profile/database/history.rs | 104 ++++++------ src/profile/database/identity.rs | 32 ++-- 28 files changed, 828 insertions(+), 931 deletions(-) diff --git a/src/app.rs b/src/app.rs index 9cff49c2..18cc033d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,7 +2,6 @@ mod browser; mod database; use browser::Browser; -use database::Database; use crate::profile::Profile; use adw::Application; @@ -51,7 +50,7 @@ impl App { match connection.unchecked_transaction() { Ok(transaction) => { // Restore previous session from DB - match Database::records(&transaction) { + match database::records(&transaction) { Ok(records) => { // Restore child components for record in records { @@ -92,11 +91,11 @@ impl App { // Create transaction match connection.transaction() { Ok(transaction) => { - match Database::records(&transaction) { + match database::records(&transaction) { Ok(records) => { // Cleanup previous session records for record in records { - match Database::delete(&transaction, &record.id) { + match database::delete(&transaction, &record.id) { Ok(_) => { // Delegate clean action to childs if let Err(e) = @@ -110,12 +109,12 @@ impl App { } // Save current session to DB - match Database::add(&transaction) { + match database::add(&transaction) { Ok(_) => { // Delegate save action to childs if let Err(e) = browser.save( &transaction, - &Database::last_insert_id(&transaction), + &database::last_insert_id(&transaction), ) { todo!("{e}") } @@ -268,7 +267,7 @@ impl App { // Tools fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser.rs b/src/app/browser.rs index f195414f..dccf1644 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -6,7 +6,6 @@ mod window; use about::About; use action::Action; -use database::Database; use widget::Widget; use window::Window; @@ -101,10 +100,10 @@ impl Browser { // Actions 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) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs self.window.clean(transaction, &record.id)?; @@ -124,7 +123,7 @@ impl Browser { } 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) => { for record in records { // Delegate restore action to childs @@ -142,9 +141,9 @@ impl Browser { } pub fn save(&self, transaction: &Transaction, app_id: &i64) -> Result<(), String> { - match Database::add(transaction, app_id) { + match database::add(transaction, app_id) { Ok(_) => { - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Delegate save action to childs self.widget.save(transaction, &id)?; @@ -185,7 +184,7 @@ impl Browser { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/database.rs b/src/app/browser/database.rs index fba87236..5d4362b4 100644 --- a/src/app/browser/database.rs +++ b/src/app/browser/database.rs @@ -5,51 +5,45 @@ pub struct Table { // pub app_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_id` INTEGER NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction, app_id: &i64) -> Result { - tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id]) - } - - pub fn records(tx: &Transaction, app_id: &i64) -> Result, Error> { - let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?; - - let result = stmt.query_map([app_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_id: row.get(1)?, not in use - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id]) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } +pub fn add(tx: &Transaction, app_id: &i64) -> Result { + tx.execute("INSERT INTO `app_browser` (`app_id`) VALUES (?)", [app_id]) +} + +pub fn records(tx: &Transaction, app_id: &i64) -> Result, Error> { + let mut stmt = tx.prepare("SELECT `id`, `app_id` FROM `app_browser` WHERE `app_id` = ?")?; + + let result = stmt.query_map([app_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_id: row.get(1)?, not in use + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `app_browser` WHERE `id` = ?", [id]) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/widget.rs b/src/app/browser/widget.rs index 1b153217..fa97bb4a 100644 --- a/src/app/browser/widget.rs +++ b/src/app/browser/widget.rs @@ -1,5 +1,4 @@ mod database; -use database::Database; use adw::ApplicationWindow; use gtk::{ @@ -43,10 +42,10 @@ impl Widget { // Actions 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) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs // nothing yet.. @@ -62,7 +61,7 @@ impl Widget { } 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) => { for record in records { // Restore widget @@ -81,7 +80,7 @@ impl Widget { } pub fn save(&self, transaction: &Transaction, app_browser_id: &i64) -> Result<(), String> { - match Database::add( + match database::add( transaction, app_browser_id, &self.gobject.default_width(), @@ -108,7 +107,7 @@ impl Widget { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/widget/database.rs b/src/app/browser/widget/database.rs index 7e1948ef..d1514d10 100644 --- a/src/app/browser/widget/database.rs +++ b/src/app/browser/widget/database.rs @@ -8,83 +8,77 @@ pub struct Table { pub is_maximized: bool, } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_widget` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_id` INTEGER NOT NULL, + `default_width` INTEGER NOT NULL, + `default_height` INTEGER NOT NULL, + `is_maximized` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_widget` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_id` INTEGER NOT NULL, - `default_width` INTEGER NOT NULL, - `default_height` INTEGER NOT NULL, - `is_maximized` INTEGER NOT NULL - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_id: &i64, + default_width: &i32, + default_height: &i32, + is_maximized: &bool, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_widget` ( + `app_browser_id`, + `default_width`, + `default_height`, + `is_maximized` + ) VALUES (?, ?, ?, ?)", + [ + app_browser_id, + &(*default_width as i64), + &(*default_height as i64), + &(*is_maximized as i64), + ], + ) +} - pub fn add( - tx: &Transaction, - app_browser_id: &i64, - default_width: &i32, - default_height: &i32, - is_maximized: &bool, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_widget` ( +pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_id`, `default_width`, `default_height`, - `is_maximized` - ) VALUES (?, ?, ?, ?)", - [ - app_browser_id, - &(*default_width as i64), - &(*default_height as i64), - &(*is_maximized as i64), - ], - ) + `is_maximized` FROM `app_browser_widget` WHERE `app_browser_id` = ?", + )?; + + let result = stmt.query_map([app_browser_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_id: row.get(1)?, not in use + default_width: row.get(2)?, + default_height: row.get(3)?, + is_maximized: row.get(4)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_id`, - `default_width`, - `default_height`, - `is_maximized` FROM `app_browser_widget` WHERE `app_browser_id` = ?", - )?; - - let result = stmt.query_map([app_browser_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_id: row.get(1)?, not in use - default_width: row.get(2)?, - default_height: row.get(3)?, - is_maximized: row.get(4)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - 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() - } */ + Ok(records) } + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + 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() +} */ diff --git a/src/app/browser/window.rs b/src/app/browser/window.rs index ed5e7913..f73212b4 100644 --- a/src/app/browser/window.rs +++ b/src/app/browser/window.rs @@ -5,7 +5,6 @@ mod tab; mod widget; use action::Action; -use database::Database; use header::Header; use sqlite::Transaction; use tab::Tab; @@ -107,10 +106,10 @@ impl Window { } 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) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs self.tab.clean(transaction, &record.id)?; @@ -126,7 +125,7 @@ impl Window { } 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) => { for record in records { // Delegate restore action to childs @@ -140,12 +139,12 @@ impl Window { } 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(_) => { // Delegate save action to childs if let Err(e) = self .tab - .save(transaction, &Database::last_insert_id(transaction)) + .save(transaction, &database::last_insert_id(transaction)) { return Err(e.to_string()); } @@ -174,7 +173,7 @@ impl Window { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/database.rs b/src/app/browser/window/database.rs index 182ac3a1..01662c8b 100644 --- a/src/app/browser/window/database.rs +++ b/src/app/browser/window/database.rs @@ -5,58 +5,52 @@ pub struct Table { // pub app_browser_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_id` INTEGER NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction, app_browser_id: &i64) -> Result { - tx.execute( - "INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)", - [app_browser_id], - ) - } - - pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_id` FROM `app_browser_window` - WHERE `app_browser_id` = ?", - )?; - - let result = stmt.query_map([app_browser_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_id: row.get(1)?, not in use - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id]) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } +pub fn add(tx: &Transaction, app_browser_id: &i64) -> Result { + tx.execute( + "INSERT INTO `app_browser_window` (`app_browser_id`) VALUES (?)", + [app_browser_id], + ) +} + +pub fn records(tx: &Transaction, app_browser_id: &i64) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, + `app_browser_id` FROM `app_browser_window` + WHERE `app_browser_id` = ?", + )?; + + let result = stmt.query_map([app_browser_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_id: row.get(1)?, not in use + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `app_browser_window` WHERE `id` = ?", [id]) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab.rs b/src/app/browser/window/tab.rs index 63ee6821..c177ba15 100644 --- a/src/app/browser/window/tab.rs +++ b/src/app/browser/window/tab.rs @@ -3,7 +3,6 @@ mod item; mod menu; mod widget; -use database::Database; use item::Item; use menu::Menu; use widget::Widget; @@ -239,10 +238,10 @@ impl Tab { transaction: &Transaction, app_browser_window_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_id) { + match database::records(transaction, app_browser_window_id) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to childs for (_, item) in self.index.borrow().iter() { @@ -264,7 +263,7 @@ impl Tab { transaction: &Transaction, app_browser_window_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_id) { + match database::records(transaction, app_browser_window_id) { Ok(records) => { for record in records { match Item::restore( @@ -297,10 +296,10 @@ impl Tab { transaction: &Transaction, app_browser_window_id: &i64, ) -> Result<(), String> { - match Database::add(transaction, app_browser_window_id) { + match database::add(transaction, app_browser_window_id) { Ok(_) => { // Delegate save action to childs - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Read collected HashMap index for (_, item) in self.index.borrow().iter() { @@ -339,7 +338,7 @@ impl Tab { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/database.rs b/src/app/browser/window/tab/database.rs index e636aa87..8acd69c4 100644 --- a/src/app/browser/window/tab/database.rs +++ b/src/app/browser/window/tab/database.rs @@ -5,60 +5,54 @@ pub struct Table { // pub app_browser_window_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_id` INTEGER NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab` ( - `app_browser_window_id` - ) VALUES (?)", - [app_browser_window_id], - ) - } - - pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_id` 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 - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id]) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } +pub fn add(tx: &Transaction, app_browser_window_id: &i64) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab` ( + `app_browser_window_id` + ) VALUES (?)", + [app_browser_window_id], + ) +} + +pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, + `app_browser_window_id` 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 + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `app_browser_window_tab` WHERE `id` = ?", [id]) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index a119dbc1..835c6d7a 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -4,7 +4,6 @@ mod page; mod widget; use action::Action; -use database::Database; use page::Page; use widget::Widget; @@ -111,10 +110,10 @@ impl Item { transaction: &Transaction, app_browser_window_tab_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_id) { + match database::records(transaction, app_browser_window_tab_id) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs self.page.clean(transaction, &record.id)?; @@ -142,7 +141,7 @@ impl Item { ) -> Result>, String> { 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) => { for record in records { // Construct new item object @@ -185,7 +184,7 @@ impl Item { is_selected: &bool, is_attention: &bool, ) -> Result<(), String> { - match Database::add( + match database::add( transaction, app_browser_window_tab_id, page_position, @@ -194,7 +193,7 @@ impl Item { is_attention, ) { Ok(_) => { - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Delegate save action to childs self.page.save(transaction, &id)?; @@ -224,7 +223,7 @@ impl Item { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/database.rs b/src/app/browser/window/tab/item/database.rs index c67fdf8b..5cd832cd 100644 --- a/src/app/browser/window/tab/item/database.rs +++ b/src/app/browser/window/tab/item/database.rs @@ -8,92 +8,86 @@ pub struct Table { pub is_attention: bool, } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_id` INTEGER NOT NULL, + `page_position` INTEGER NOT NULL, + `is_pinned` INTEGER NOT NULL, + `is_selected` INTEGER NOT NULL, + `is_attention` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_id` INTEGER NOT NULL, - `page_position` INTEGER NOT NULL, - `is_pinned` INTEGER NOT NULL, - `is_selected` INTEGER NOT NULL, - `is_attention` INTEGER NOT NULL - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_window_tab_id: &i64, + page_position: &i32, + is_pinned: &bool, + is_selected: &bool, + is_attention: &bool, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item` ( + `app_browser_window_tab_id`, + `page_position`, + `is_pinned`, + `is_selected`, + `is_attention` + ) VALUES (?, ?, ?, ?, ?)", + [ + app_browser_window_tab_id, + &(*page_position as i64), + &(*is_pinned as i64), + &(*is_selected as i64), + &(*is_attention as i64), + ], + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_id: &i64, - page_position: &i32, - is_pinned: &bool, - is_selected: &bool, - is_attention: &bool, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item` ( +pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_id`, - `page_position`, `is_pinned`, `is_selected`, `is_attention` - ) VALUES (?, ?, ?, ?, ?)", - [ - app_browser_window_tab_id, - &(*page_position as i64), - &(*is_pinned as i64), - &(*is_selected as i64), - &(*is_attention as i64), - ], - ) + 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_pinned: row.get(2)?, + is_selected: row.get(3)?, + is_attention: row.get(4)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_id`, - `is_pinned`, - `is_selected`, - `is_attention` - 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_pinned: row.get(2)?, - is_selected: row.get(3)?, - is_attention: row.get(4)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item` WHERE `id` = ?", - [id], - ) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item` WHERE `id` = ?", + [id], + ) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index 3b4b99cd..6f725562 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -6,7 +6,6 @@ mod navigation; mod widget; use content::Content; -use database::Database; use input::Input; use meta::{Meta, Status}; use navigation::Navigation; @@ -297,10 +296,10 @@ impl Page { transaction: &Transaction, app_browser_window_tab_item_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_item_id) { + match database::records(transaction, app_browser_window_tab_item_id) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs self.meta.clean(transaction, &record.id)?; @@ -325,7 +324,7 @@ impl Page { self.meta.set_status(Status::SessionRestore); // 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) => { for record in records { // Delegate restore action to the item childs @@ -347,9 +346,9 @@ impl Page { transaction: &Transaction, app_browser_window_tab_item_id: &i64, ) -> Result<(), String> { - match Database::add(transaction, app_browser_window_tab_item_id) { + match database::add(transaction, app_browser_window_tab_item_id) { Ok(_) => { - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Delegate save action to childs self.meta.save(transaction, &id)?; @@ -931,7 +930,7 @@ impl Page { pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/page/database.rs b/src/app/browser/window/tab/item/page/database.rs index 94a1b41f..77ced91e 100644 --- a/src/app/browser/window/tab/item/page/database.rs +++ b/src/app/browser/window/tab/item/page/database.rs @@ -5,67 +5,61 @@ pub struct Table { // pub app_browser_window_tab_item_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_id` INTEGER NOT NULL - )", - [], - ) - } +pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_page` ( + `app_browser_window_tab_item_id` + ) VALUES (?)", + [app_browser_window_tab_item_id], + ) +} - pub fn add(tx: &Transaction, app_browser_window_tab_item_id: &i64) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_page` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_id` - ) VALUES (?)", - [app_browser_window_tab_item_id], - ) + FROM `app_browser_window_tab_item_page` + WHERE `app_browser_window_tab_item_id` = ?", + )?; + + let result = stmt.query_map([app_browser_window_tab_item_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_id: row.get(1)?, not in use + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_id` - FROM `app_browser_window_tab_item_page` - WHERE `app_browser_window_tab_item_id` = ?", - )?; - - let result = stmt.query_map([app_browser_window_tab_item_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_id: row.get(1)?, not in use - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?", - [id], - ) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_page` WHERE `id` = ?", + [id], + ) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab/item/page/meta.rs b/src/app/browser/window/tab/item/page/meta.rs index 953b683f..2b6b9c76 100644 --- a/src/app/browser/window/tab/item/page/meta.rs +++ b/src/app/browser/window/tab/item/page/meta.rs @@ -1,7 +1,6 @@ mod database; mod redirect; -use database::Database; use redirect::Redirect; use gtk::glib::GString; @@ -112,10 +111,10 @@ impl Meta { transaction: &Transaction, app_browser_window_tab_page_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_page_id) { + match database::records(transaction, app_browser_window_tab_page_id) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs // nothing yet.. @@ -135,7 +134,7 @@ impl Meta { transaction: &Transaction, app_browser_window_tab_page_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_page_id) { + match database::records(transaction, app_browser_window_tab_page_id) { Ok(records) => { for record in records { // Record value can be stored as NULL @@ -161,7 +160,7 @@ impl Meta { // Keep value in memory until operation complete let title = self.title(); - match Database::add( + match database::add( transaction, app_browser_window_tab_page_id, match title.is_empty() { @@ -170,7 +169,7 @@ impl Meta { }, ) { Ok(_) => { - // let id = Database::last_insert_id(transaction); + // let id = database::last_insert_id(transaction); // Delegate save action to childs // nothing yet.. @@ -185,7 +184,7 @@ impl Meta { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/page/meta/database.rs b/src/app/browser/window/tab/item/page/meta/database.rs index 4ce3dc6f..8b7a8033 100644 --- a/src/app/browser/window/tab/item/page/meta/database.rs +++ b/src/app/browser/window/tab/item/page/meta/database.rs @@ -6,76 +6,70 @@ pub struct Table { pub title: Option, // can be stored as NULL } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_meta` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_page_id` INTEGER NOT NULL, + `title` VARCHAR(1024) + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_meta` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_id` INTEGER NOT NULL, - `title` VARCHAR(1024) - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_window_tab_item_page_id: &i64, + title: Option<&str>, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_page_meta` ( + `app_browser_window_tab_item_page_id`, + `title` + ) VALUES (?, ?)", + (app_browser_window_tab_item_page_id, title), + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_item_page_id: &i64, - title: Option<&str>, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_page_meta` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_page_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_page_id`, `title` - ) VALUES (?, ?)", - (app_browser_window_tab_item_page_id, title), - ) + FROM `app_browser_window_tab_item_page_meta` + WHERE `app_browser_window_tab_item_page_id` = ?", + )?; + + let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_page_id: row.get(1)?, not in use + title: row.get(2)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_page_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_page_id`, - `title` - FROM `app_browser_window_tab_item_page_meta` - WHERE `app_browser_window_tab_item_page_id` = ?", - )?; - - let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_page_id: row.get(1)?, not in use - title: row.get(2)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_page_meta` WHERE `id` = ?", - [id], - ) - } - - /* not in use - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } */ + Ok(records) } + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_page_meta` WHERE `id` = ?", + [id], + ) +} + +/* not in use +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() +} */ diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index 9dafc9ee..ac50e987 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -7,7 +7,6 @@ mod request; mod widget; use bookmark::Bookmark; -use database::Database; use history::History; use home::Home; use reload::Reload; @@ -79,10 +78,10 @@ impl Navigation { transaction: &Transaction, app_browser_window_tab_item_page_id: &i64, ) -> 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) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs self.request.clean(transaction, &record.id)?; @@ -102,7 +101,7 @@ impl Navigation { transaction: &Transaction, app_browser_window_tab_item_page_id: &i64, ) -> 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) => { for record in records { // Delegate restore action to the item childs @@ -120,9 +119,9 @@ impl Navigation { transaction: &Transaction, app_browser_window_tab_item_page_id: &i64, ) -> 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(_) => { - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Delegate save action to childs self.request.save(transaction, &id)?; @@ -165,7 +164,7 @@ impl Navigation { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/page/navigation/database.rs b/src/app/browser/window/tab/item/page/navigation/database.rs index 942e5550..036e4c73 100644 --- a/src/app/browser/window/tab/item/page/navigation/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/database.rs @@ -5,70 +5,61 @@ pub struct Table { // pub app_browser_window_tab_item_page_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_page_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_id` INTEGER NOT NULL - )", - [], - ) - } +pub fn add(tx: &Transaction, app_browser_window_tab_item_page_id: &i64) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_page_navigation` ( + `app_browser_window_tab_item_page_id` + ) VALUES (?)", + [app_browser_window_tab_item_page_id], + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_item_page_id: &i64, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_page_navigation` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_page_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_page_id` - ) VALUES (?)", - [app_browser_window_tab_item_page_id], - ) + FROM `app_browser_window_tab_item_page_navigation` + WHERE `app_browser_window_tab_item_page_id` = ?", + )?; + + let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_page_id: row.get(1)?, not in use + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_page_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_page_id` - FROM `app_browser_window_tab_item_page_navigation` - WHERE `app_browser_window_tab_item_page_id` = ?", - )?; - - let result = stmt.query_map([app_browser_window_tab_item_page_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_page_id: row.get(1)?, not in use - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?", - [id], - ) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_page_navigation` WHERE `id` = ?", + [id], + ) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab/item/page/navigation/request.rs b/src/app/browser/window/tab/item/page/navigation/request.rs index bd5aad40..b473ef0a 100644 --- a/src/app/browser/window/tab/item/page/navigation/request.rs +++ b/src/app/browser/window/tab/item/page/navigation/request.rs @@ -1,7 +1,6 @@ mod database; mod widget; -use database::Database; use widget::Widget; use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; @@ -39,10 +38,10 @@ impl Request { transaction: &Transaction, app_browser_window_tab_item_page_navigation_id: &i64, ) -> 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) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs self.widget.clean(transaction, &record.id)?; @@ -62,7 +61,7 @@ impl Request { transaction: &Transaction, app_browser_window_tab_item_page_navigation_id: &i64, ) -> 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) => { for record in records { // Delegate restore action to the item childs @@ -80,9 +79,9 @@ impl Request { transaction: &Transaction, app_browser_window_tab_item_page_navigation_id: &i64, ) -> 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(_) => { - let id = Database::last_insert_id(transaction); + let id = database::last_insert_id(transaction); // Delegate save action to childs self.widget.save(transaction, &id)?; @@ -110,7 +109,7 @@ impl Request { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/page/navigation/request/database.rs b/src/app/browser/window/tab/item/page/navigation/request/database.rs index 87bc5a7a..bd7980b1 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/database.rs @@ -5,70 +5,64 @@ pub struct Table { // pub app_browser_window_tab_item_page_navigation_id: i64, not in use } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_page_navigation_id` INTEGER NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_navigation_id` INTEGER NOT NULL - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_window_tab_item_page_navigation_id: &i64, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_page_navigation_request` ( + `app_browser_window_tab_item_page_navigation_id` + ) VALUES (?)", + [app_browser_window_tab_item_page_navigation_id], + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_item_page_navigation_id: &i64, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_page_navigation_request` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_page_navigation_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_page_navigation_id` - ) VALUES (?)", - [app_browser_window_tab_item_page_navigation_id], - ) + FROM `app_browser_window_tab_item_page_navigation_request` + WHERE `app_browser_window_tab_item_page_navigation_id` = ?", + )?; + + let result = stmt.query_map([app_browser_window_tab_item_page_navigation_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_page_navigation_id: row.get(1)?, not in use + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_page_navigation_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_page_navigation_id` - FROM `app_browser_window_tab_item_page_navigation_request` - WHERE `app_browser_window_tab_item_page_navigation_id` = ?", - )?; - - let result = stmt.query_map([app_browser_window_tab_item_page_navigation_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_page_navigation_id: row.get(1)?, not in use - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?", - [id], - ) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_page_navigation_request` WHERE `id` = ?", + [id], + ) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget.rs b/src/app/browser/window/tab/item/page/navigation/request/widget.rs index 5c53cd39..cbf5bfaf 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget.rs @@ -1,7 +1,5 @@ mod database; -use database::Database; - use crate::app::browser::{window::tab::item::Action as TabAction, Action as BrowserAction}; use gtk::{ glib::{timeout_add_local, ControlFlow, SourceId}, @@ -82,13 +80,13 @@ impl Widget { transaction: &Transaction, app_browser_window_tab_item_page_navigation_request_id: &i64, ) -> Result<(), String> { - match Database::records( + match database::records( transaction, app_browser_window_tab_item_page_navigation_request_id, ) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs // nothing yet.. @@ -108,7 +106,7 @@ impl Widget { transaction: &Transaction, app_browser_window_tab_item_page_navigation_request_id: &i64, ) -> Result<(), String> { - match Database::records( + match database::records( transaction, app_browser_window_tab_item_page_navigation_request_id, ) { @@ -136,7 +134,7 @@ impl Widget { // Keep value in memory until operation complete let text = self.gobject.text(); - match Database::add( + match database::add( transaction, app_browser_window_tab_item_page_navigation_request_id, match text.is_empty() { @@ -145,7 +143,7 @@ impl Widget { }, ) { Ok(_) => { - // let id = Database::last_insert_id(transaction); + // let id = database::last_insert_id(transaction); // Delegate save action to childs // nothing yet.. @@ -211,7 +209,7 @@ impl Widget { // Tools pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs b/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs index c0b70cc6..522a8363 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/widget/database.rs @@ -6,79 +6,73 @@ pub struct Table { pub text: Option, // can be stored as NULL } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request_widget` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_page_navigation_request_id` INTEGER NOT NULL, + `text` VARCHAR(1024) + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_page_navigation_request_widget` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_page_navigation_request_id` INTEGER NOT NULL, - `text` VARCHAR(1024) - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_window_tab_item_page_navigation_request_id: &i64, + text: Option<&str>, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_page_navigation_request_widget` ( + `app_browser_window_tab_item_page_navigation_request_id`, + `text` + ) VALUES (?, ?)", + (app_browser_window_tab_item_page_navigation_request_id, text), + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_item_page_navigation_request_id: &i64, - text: Option<&str>, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_page_navigation_request_widget` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_page_navigation_request_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_page_navigation_request_id`, `text` - ) VALUES (?, ?)", - (app_browser_window_tab_item_page_navigation_request_id, text), - ) + FROM `app_browser_window_tab_item_page_navigation_request_widget` + WHERE `app_browser_window_tab_item_page_navigation_request_id` = ?", + )?; + + let result = stmt.query_map( + [app_browser_window_tab_item_page_navigation_request_id], + |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_page_navigation_request_id: row.get(1)?, not in use + text: row.get(2)?, + }) + }, + )?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_page_navigation_request_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_page_navigation_request_id`, - `text` - FROM `app_browser_window_tab_item_page_navigation_request_widget` - WHERE `app_browser_window_tab_item_page_navigation_request_id` = ?", - )?; - - let result = stmt.query_map( - [app_browser_window_tab_item_page_navigation_request_id], - |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_page_navigation_request_id: row.get(1)?, not in use - text: row.get(2)?, - }) - }, - )?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_page_navigation_request_widget` WHERE `id` = ?", - [id], - ) - } - - /* not in use - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } */ + Ok(records) } + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_page_navigation_request_widget` WHERE `id` = ?", + [id], + ) +} + +/* not in use +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() +} */ diff --git a/src/app/browser/window/tab/item/widget.rs b/src/app/browser/window/tab/item/widget.rs index 0ead6a91..8ea8fdc1 100644 --- a/src/app/browser/window/tab/item/widget.rs +++ b/src/app/browser/window/tab/item/widget.rs @@ -1,7 +1,5 @@ mod database; -use database::Database; - use crate::app::browser::window::action::Position; use adw::{TabPage, TabView}; use gtk::prelude::IsA; @@ -62,10 +60,10 @@ impl Widget { transaction: &Transaction, app_browser_window_tab_item_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_item_id) { + match database::records(transaction, app_browser_window_tab_item_id) { Ok(records) => { for record in records { - match Database::delete(transaction, &record.id) { + match database::delete(transaction, &record.id) { Ok(_) => { // Delegate clean action to the item childs // nothing yet.. @@ -85,7 +83,7 @@ impl Widget { transaction: &Transaction, app_browser_window_tab_item_id: &i64, ) -> Result<(), String> { - match Database::records(transaction, app_browser_window_tab_item_id) { + match database::records(transaction, app_browser_window_tab_item_id) { Ok(records) => { for record in records { // Record value can be stored as NULL @@ -111,7 +109,7 @@ impl Widget { // Keep value in memory until operation complete let title = self.gobject.title(); - match Database::add( + match database::add( transaction, app_browser_window_tab_item_id, match title.is_empty() { @@ -120,7 +118,7 @@ impl Widget { }, ) { Ok(_) => { - // let id = Database::last_insert_id(transaction); + // let id = database::last_insert_id(transaction); // Delegate save action to childs // nothing yet.. @@ -142,7 +140,7 @@ impl Widget { pub fn migrate(tx: &Transaction) -> Result<(), String> { // Migrate self components - if let Err(e) = Database::init(tx) { + if let Err(e) = database::init(tx) { return Err(e.to_string()); } diff --git a/src/app/browser/window/tab/item/widget/database.rs b/src/app/browser/window/tab/item/widget/database.rs index 617f3d4c..943a583a 100644 --- a/src/app/browser/window/tab/item/widget/database.rs +++ b/src/app/browser/window/tab/item/widget/database.rs @@ -6,76 +6,70 @@ pub struct Table { pub title: Option, // can be stored as NULL } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_widget` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `app_browser_window_tab_item_id` INTEGER NOT NULL, + `title` VARCHAR(1024) + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_item_widget` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `app_browser_window_tab_item_id` INTEGER NOT NULL, - `title` VARCHAR(1024) - )", - [], - ) - } +pub fn add( + tx: &Transaction, + app_browser_window_tab_item_id: &i64, + title: Option<&str>, +) -> Result { + tx.execute( + "INSERT INTO `app_browser_window_tab_item_widget` ( + `app_browser_window_tab_item_id`, + `title` + ) VALUES (?, ?)", + (app_browser_window_tab_item_id, title), + ) +} - pub fn add( - tx: &Transaction, - app_browser_window_tab_item_id: &i64, - title: Option<&str>, - ) -> Result { - tx.execute( - "INSERT INTO `app_browser_window_tab_item_widget` ( +pub fn records( + tx: &Transaction, + app_browser_window_tab_item_id: &i64, +) -> Result, Error> { + let mut stmt = tx.prepare( + "SELECT `id`, `app_browser_window_tab_item_id`, `title` - ) VALUES (?, ?)", - (app_browser_window_tab_item_id, title), - ) + FROM `app_browser_window_tab_item_widget` + WHERE `app_browser_window_tab_item_id` = ?", + )?; + + let result = stmt.query_map([app_browser_window_tab_item_id], |row| { + Ok(Table { + id: row.get(0)?, + // app_browser_window_tab_item_id: row.get(1)?, not in use + title: row.get(2)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); } - pub fn records( - tx: &Transaction, - app_browser_window_tab_item_id: &i64, - ) -> Result, Error> { - let mut stmt = tx.prepare( - "SELECT `id`, - `app_browser_window_tab_item_id`, - `title` - FROM `app_browser_window_tab_item_widget` - WHERE `app_browser_window_tab_item_id` = ?", - )?; - - let result = stmt.query_map([app_browser_window_tab_item_id], |row| { - Ok(Table { - id: row.get(0)?, - // app_browser_window_tab_item_id: row.get(1)?, not in use - title: row.get(2)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute( - "DELETE FROM `app_browser_window_tab_item_widget` WHERE `id` = ?", - [id], - ) - } - - /* not in use - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } */ + Ok(records) } + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute( + "DELETE FROM `app_browser_window_tab_item_widget` WHERE `id` = ?", + [id], + ) +} + +/* not in use +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() +} */ diff --git a/src/app/database.rs b/src/app/database.rs index dddb5d39..82e67f69 100644 --- a/src/app/database.rs +++ b/src/app/database.rs @@ -4,44 +4,38 @@ pub struct Table { pub id: i64, } -pub struct Database { - // nothing yet.. +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `app` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL + )", + [], + ) } -impl Database { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `app` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction) -> Result { - tx.execute("INSERT INTO `app` DEFAULT VALUES", []) - } - - pub fn records(tx: &Transaction) -> Result, Error> { - let mut stmt = tx.prepare("SELECT `id` FROM `app`")?; - let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `app` WHERE `id` = ?", [id]) - } - - pub fn last_insert_id(tx: &Transaction) -> i64 { - tx.last_insert_rowid() - } +pub fn add(tx: &Transaction) -> Result { + tx.execute("INSERT INTO `app` DEFAULT VALUES", []) +} + +pub fn records(tx: &Transaction) -> Result, Error> { + let mut stmt = tx.prepare("SELECT `id` FROM `app`")?; + let result = stmt.query_map([], |row| Ok(Table { id: row.get(0)? }))?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `app` WHERE `id` = ?", [id]) +} + +pub fn last_insert_id(tx: &Transaction) -> i64 { + tx.last_insert_rowid() } diff --git a/src/profile/database.rs b/src/profile/database.rs index a125ac2d..8159c0bb 100644 --- a/src/profile/database.rs +++ b/src/profile/database.rs @@ -2,10 +2,6 @@ mod bookmark; mod history; mod identity; -use bookmark::Bookmark; -use history::History; -use identity::Identity; - use sqlite::{Connection, Error}; use std::{ path::Path, @@ -56,9 +52,9 @@ fn init(mut connection: RwLockWriteGuard<'_, Connection>) -> Result<(), Error> { let transaction = connection.transaction()?; // Init profile components - Bookmark::init(&transaction)?; - History::init(&transaction)?; - Identity::init(&transaction)?; + bookmark::init(&transaction)?; + history::init(&transaction)?; + identity::init(&transaction)?; // Apply changes transaction.commit()?; diff --git a/src/profile/database/bookmark.rs b/src/profile/database/bookmark.rs index 781ddeac..956bc24d 100644 --- a/src/profile/database/bookmark.rs +++ b/src/profile/database/bookmark.rs @@ -11,57 +11,55 @@ pub struct Bookmark { // nothing yet.. } -impl Bookmark { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `bookmark` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `time` INTEGER NOT NULL, - `request` TEXT NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result { - tx.execute( - "INSERT INTO `bookmark` ( - `time`, - `request` - ) VALUES (?, ?)", - (time.to_unix(), request), - ) - } - - pub fn records(tx: &Transaction, request: Option<&str>) -> Result, Error> { - let mut stmt = - tx.prepare("SELECT `id`, `time`, `request` FROM `bookmark` WHERE `request` LIKE ?")?; - - let filter = match request { - Some(value) => value, - None => "%", - }; - - let result = stmt.query_map([filter], |row| { - Ok(Table { - id: row.get(0)?, - time: DateTime::from_unix_local(row.get(1)?).unwrap(), - request: row.get(2)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `bookmark` WHERE `id` = ?", [id]) - } +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `bookmark` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `time` INTEGER NOT NULL, + `request` TEXT NOT NULL + )", + [], + ) +} + +pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result { + tx.execute( + "INSERT INTO `bookmark` ( + `time`, + `request` + ) VALUES (?, ?)", + (time.to_unix(), request), + ) +} + +pub fn records(tx: &Transaction, request: Option<&str>) -> Result, Error> { + let mut stmt = + tx.prepare("SELECT `id`, `time`, `request` FROM `bookmark` WHERE `request` LIKE ?")?; + + let filter = match request { + Some(value) => value, + None => "%", + }; + + let result = stmt.query_map([filter], |row| { + Ok(Table { + id: row.get(0)?, + time: DateTime::from_unix_local(row.get(1)?).unwrap(), + request: row.get(2)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `bookmark` WHERE `id` = ?", [id]) } diff --git a/src/profile/database/history.rs b/src/profile/database/history.rs index e9f563b5..3564b405 100644 --- a/src/profile/database/history.rs +++ b/src/profile/database/history.rs @@ -11,57 +11,55 @@ pub struct History { // nothing yet.. } -impl History { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `history` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `time` INTEGER NOT NULL, - `request` TEXT NOT NULL - )", - [], - ) - } - - pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result { - tx.execute( - "INSERT INTO `history` ( - `time`, - `request` - ) VALUES (?, ?)", - (time.to_unix(), request), - ) - } - - pub fn records(tx: &Transaction, request: Option<&str>) -> Result, Error> { - let mut stmt = - tx.prepare("SELECT `id`, `time`, `request` FROM `history` WHERE `request` LIKE ?")?; - - let filter = match request { - Some(value) => value, - None => "%", - }; - - let result = stmt.query_map([filter], |row| { - Ok(Table { - id: row.get(0)?, - time: DateTime::from_unix_local(row.get(1)?).unwrap(), - request: row.get(2)?, - }) - })?; - - let mut records = Vec::new(); - - for record in result { - let table = record?; - records.push(table); - } - - Ok(records) - } - - pub fn delete(tx: &Transaction, id: &i64) -> Result { - tx.execute("DELETE FROM `history` WHERE `id` = ?", [id]) - } +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `history` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `time` INTEGER NOT NULL, + `request` TEXT NOT NULL + )", + [], + ) +} + +pub fn add(tx: &Transaction, time: &DateTime, request: &str) -> Result { + tx.execute( + "INSERT INTO `history` ( + `time`, + `request` + ) VALUES (?, ?)", + (time.to_unix(), request), + ) +} + +pub fn records(tx: &Transaction, request: Option<&str>) -> Result, Error> { + let mut stmt = + tx.prepare("SELECT `id`, `time`, `request` FROM `history` WHERE `request` LIKE ?")?; + + let filter = match request { + Some(value) => value, + None => "%", + }; + + let result = stmt.query_map([filter], |row| { + Ok(Table { + id: row.get(0)?, + time: DateTime::from_unix_local(row.get(1)?).unwrap(), + request: row.get(2)?, + }) + })?; + + let mut records = Vec::new(); + + for record in result { + let table = record?; + records.push(table); + } + + Ok(records) +} + +pub fn delete(tx: &Transaction, id: &i64) -> Result { + tx.execute("DELETE FROM `history` WHERE `id` = ?", [id]) } diff --git a/src/profile/database/identity.rs b/src/profile/database/identity.rs index 1e9aee2a..004892ef 100644 --- a/src/profile/database/identity.rs +++ b/src/profile/database/identity.rs @@ -2,25 +2,19 @@ use sqlite::{Error, Transaction}; pub struct Table { pub id: i64, - // pub app_id: i64, not in use + // pub app_id: i64, } -pub struct Identity { - // nothing yet.. -} - -impl Identity { - pub fn init(tx: &Transaction) -> Result { - tx.execute( - "CREATE TABLE IF NOT EXISTS `identity` - ( - `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, - `time` INTEGER NOT NULL, - `name` VARCHAR(255), - `crt` TEXT NOT NULL, - `key` TEXT NOT NULL - )", - [], - ) - } +pub fn init(tx: &Transaction) -> Result { + tx.execute( + "CREATE TABLE IF NOT EXISTS `identity` + ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + `time` INTEGER NOT NULL, + `name` VARCHAR(255), + `crt` TEXT NOT NULL, + `key` TEXT NOT NULL + )", + [], + ) }