Browse Source

make transactionable mathods static

master
yggverse 2 months ago
parent
commit
a1f2d57b6d
  1. 15
      src/app.rs
  2. 16
      src/app/browser.rs
  3. 12
      src/app/browser/database.rs
  4. 15
      src/app/browser/widget.rs
  5. 11
      src/app/browser/widget/database.rs
  6. 20
      src/app/browser/window.rs
  7. 12
      src/app/browser/window/database.rs
  8. 15
      src/app/browser/window/tab.rs
  9. 15
      src/app/browser/window/tab/database.rs
  10. 22
      src/app/browser/window/tab/label.rs
  11. 15
      src/app/browser/window/tab/label/database.rs
  12. 12
      src/app/database.rs

15
src/app.rs

@ -37,9 +37,6 @@ impl App {
profile_database_connection: Arc<RwLock<Connection>>, profile_database_connection: Arc<RwLock<Connection>>,
profile_path: PathBuf, profile_path: PathBuf,
) -> Self { ) -> Self {
// Init database
let database = Arc::new(Database::new());
// Init actions // Init actions
let action_tool_debug = Action::new("win", true); let action_tool_debug = Action::new("win", true);
let action_tool_profile_directory = Action::new("win", true); let action_tool_profile_directory = Action::new("win", true);
@ -111,7 +108,6 @@ impl App {
gobject.connect_startup({ gobject.connect_startup({
let browser = browser.clone(); let browser = browser.clone();
let database = database.clone();
let profile_database_connection = profile_database_connection.clone(); let profile_database_connection = profile_database_connection.clone();
move |this| { move |this| {
// Init readable connection // Init readable connection
@ -121,7 +117,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) => {
for record in records { for record in records {
browser.restore(&transaction, &record.id); browser.restore(&transaction, &record.id);
@ -147,7 +143,6 @@ impl App {
gobject.connect_shutdown({ gobject.connect_shutdown({
// let browser = browser.clone(); // let browser = browser.clone();
let profile_database_connection = profile_database_connection.clone(); let profile_database_connection = profile_database_connection.clone();
let database = database.clone();
let browser = browser.clone(); let browser = browser.clone();
move |_| { move |_| {
// Init writable connection // Init writable connection
@ -156,11 +151,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
browser.clean(&transaction, &record.id); browser.clean(&transaction, &record.id);
@ -170,12 +165,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
browser.save( browser.save(
&transaction, &transaction,
&database.last_insert_id(&transaction), &Database::last_insert_id(&transaction),
); );
} }
Err(e) => todo!("{e}"), Err(e) => todo!("{e}"),

16
src/app/browser.rs

@ -17,8 +17,6 @@ use sqlite::Transaction;
use std::{path::PathBuf, sync::Arc}; use std::{path::PathBuf, sync::Arc};
pub struct Browser { pub struct Browser {
// Extras
database: Arc<Database>,
// Components // Components
// header: Arc<Header>, // header: Arc<Header>,
window: Arc<Window>, window: Arc<Window>,
@ -44,9 +42,6 @@ impl Browser {
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_tab_pin: Arc<SimpleAction>, action_tab_pin: Arc<SimpleAction>,
) -> Browser { ) -> Browser {
// Init database
let database = Arc::new(Database::new());
// Init components // Init components
let header = Arc::new(Header::new( let header = Arc::new(Header::new(
action_tool_debug.clone(), action_tool_debug.clone(),
@ -189,7 +184,6 @@ impl Browser {
// Return new activated Browser struct // Return new activated Browser struct
Self { Self {
database,
widget, widget,
// header, // header,
window, window,
@ -198,10 +192,10 @@ impl Browser {
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_id: &i64) { pub fn clean(&self, tx: &Transaction, app_id: &i64) {
match self.database.records(tx, app_id) { match Database::records(tx, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match self.database.delete(tx, &record.id) { match Database::delete(tx, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// @TODO // @TODO
@ -218,7 +212,7 @@ impl Browser {
} }
pub fn restore(&self, tx: &Transaction, app_id: &i64) { pub fn restore(&self, tx: &Transaction, app_id: &i64) {
match self.database.records(tx, app_id) { match Database::records(tx, app_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Delegate restore action to childs // Delegate restore action to childs
@ -233,10 +227,10 @@ impl Browser {
} }
pub fn save(&self, tx: &Transaction, app_id: &i64) { pub fn save(&self, tx: &Transaction, app_id: &i64) {
match self.database.add(tx, app_id) { match Database::add(tx, app_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
let id = self.database.last_insert_id(tx); let id = Database::last_insert_id(tx);
// @TODO // @TODO
// self.header.save(id); // self.header.save(id);

12
src/app/browser/database.rs

@ -10,10 +10,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app_browser` "CREATE TABLE IF NOT EXISTS `app_browser`
@ -25,11 +21,11 @@ impl Database {
) )
} }
pub fn add(&self, 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(&self, 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| {
@ -49,11 +45,11 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, 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(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} }
} }

15
src/app/browser/widget.rs

@ -4,7 +4,6 @@ use database::Database;
use gtk::{prelude::GtkWindowExt, ApplicationWindow, Box, HeaderBar}; use gtk::{prelude::GtkWindowExt, ApplicationWindow, Box, HeaderBar};
use sqlite::Transaction; use sqlite::Transaction;
use std::sync::Arc;
// Default options // Default options
const DEFAULT_HEIGHT: i32 = 480; const DEFAULT_HEIGHT: i32 = 480;
@ -12,16 +11,12 @@ const DEFAULT_WIDTH: i32 = 640;
const MAXIMIZED: bool = false; const MAXIMIZED: bool = false;
pub struct Widget { pub struct Widget {
database: Arc<Database>,
gobject: ApplicationWindow, gobject: ApplicationWindow,
} }
impl Widget { impl Widget {
// Construct // Construct
pub fn new(titlebar: &HeaderBar, child: &Box) -> Self { pub fn new(titlebar: &HeaderBar, child: &Box) -> Self {
// Init database
let database = Arc::new(Database::new());
// Init GTK // Init GTK
let gobject = ApplicationWindow::builder() let gobject = ApplicationWindow::builder()
.titlebar(titlebar) .titlebar(titlebar)
@ -32,15 +27,15 @@ impl Widget {
.build(); .build();
// Return new struct // Return new struct
Self { database, gobject } Self { gobject }
} }
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.records(tx, app_browser_id) { match Database::records(tx, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match self.database.delete(tx, &record.id) { match Database::delete(tx, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// nothing yet.. // nothing yet..
@ -54,7 +49,7 @@ impl Widget {
} }
pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.records(tx, app_browser_id) { match Database::records(tx, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
// Restore widget // Restore widget
@ -71,7 +66,7 @@ impl Widget {
} }
pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { pub fn save(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.add( match Database::add(
tx, tx,
app_browser_id, app_browser_id,
&self.gobject.default_width(), &self.gobject.default_width(),

11
src/app/browser/widget/database.rs

@ -13,10 +13,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app_browser_widget` "CREATE TABLE IF NOT EXISTS `app_browser_widget`
@ -32,7 +28,6 @@ impl Database {
} }
pub fn add( pub fn add(
&self,
tx: &Transaction, tx: &Transaction,
app_browser_id: &i64, app_browser_id: &i64,
default_width: &i32, default_width: &i32,
@ -55,7 +50,7 @@ impl Database {
) )
} }
pub fn records(&self, 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`,
@ -84,12 +79,12 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, tx: &Transaction, id: &i64) -> Result<usize, Error> { pub fn delete(tx: &Transaction, id: &i64) -> Result<usize, Error> {
tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id]) tx.execute("DELETE FROM `app_browser_widget` WHERE `id` = ?", [id])
} }
/* not in use /* not in use
pub fn last_insert_id(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} */ } */
} }

20
src/app/browser/window.rs

@ -12,7 +12,6 @@ use std::sync::Arc;
use gtk::{gio::SimpleAction, glib::GString, Box}; use gtk::{gio::SimpleAction, glib::GString, Box};
pub struct Window { pub struct Window {
database: Arc<Database>,
tab: Arc<Tab>, tab: Arc<Tab>,
widget: Arc<Widget>, widget: Arc<Widget>,
} }
@ -27,9 +26,6 @@ impl Window {
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
) -> Self { ) -> Self {
// Init database
let database = Arc::new(Database::new());
// Init components // Init components
let tab = Arc::new(Tab::new( let tab = Arc::new(Tab::new(
action_tab_page_navigation_base, action_tab_page_navigation_base,
@ -44,11 +40,7 @@ impl Window {
let widget = Arc::new(Widget::new(tab.gobject())); let widget = Arc::new(Widget::new(tab.gobject()));
// Init struct // Init struct
Self { Self { tab, widget }
database,
tab,
widget,
}
} }
// Actions // Actions
@ -89,10 +81,10 @@ impl Window {
} }
pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) { pub fn clean(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.records(tx, app_browser_id) { match Database::records(tx, app_browser_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match self.database.delete(tx, &record.id) { match Database::delete(tx, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
self.tab.clean(tx, &record.id); self.tab.clean(tx, &record.id);
@ -106,7 +98,7 @@ impl Window {
} }
pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) { pub fn restore(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.records(tx, app_browser_id) { match Database::records(tx, 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
@ -118,10 +110,10 @@ impl Window {
} }
pub fn save(&self, tx: &Transaction, app_browser_id: &i64) { pub fn save(&self, tx: &Transaction, app_browser_id: &i64) {
match self.database.add(tx, app_browser_id) { match Database::add(tx, app_browser_id) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
self.tab.save(tx, &self.database.last_insert_id(tx)); self.tab.save(tx, &Database::last_insert_id(tx));
} }
Err(e) => todo!("{e}"), Err(e) => todo!("{e}"),
} }

12
src/app/browser/window/database.rs

@ -10,10 +10,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app_browser_window` "CREATE TABLE IF NOT EXISTS `app_browser_window`
@ -25,14 +21,14 @@ impl Database {
) )
} }
pub fn add(&self, 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(&self, 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`
@ -56,11 +52,11 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, 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(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} }
} }

15
src/app/browser/window/tab.rs

@ -26,7 +26,6 @@ pub struct TabItem {
// Main // Main
pub struct Tab { pub struct Tab {
database: Arc<Database>,
// Actions // Actions
action_tab_page_navigation_base: Arc<SimpleAction>, action_tab_page_navigation_base: Arc<SimpleAction>,
action_tab_page_navigation_history_back: Arc<SimpleAction>, action_tab_page_navigation_history_back: Arc<SimpleAction>,
@ -49,9 +48,6 @@ impl Tab {
action_tab_page_navigation_reload: Arc<SimpleAction>, action_tab_page_navigation_reload: Arc<SimpleAction>,
action_update: Arc<SimpleAction>, action_update: Arc<SimpleAction>,
) -> Self { ) -> Self {
// Init database
let database = Arc::new(Database::new());
// Init empty HashMap index as no tabs appended yet // Init empty HashMap index as no tabs appended yet
let index = RefCell::new(HashMap::new()); let index = RefCell::new(HashMap::new());
@ -60,7 +56,6 @@ impl Tab {
// Return non activated struct // Return non activated struct
Self { Self {
database,
// Define action links // Define action links
action_tab_page_navigation_base, action_tab_page_navigation_base,
action_tab_page_navigation_history_back, action_tab_page_navigation_history_back,
@ -219,10 +214,10 @@ impl Tab {
} }
pub fn clean(&self, tx: &Transaction, app_browser_window_id: &i64) { pub fn clean(&self, tx: &Transaction, app_browser_window_id: &i64) {
match self.database.records(tx, app_browser_window_id) { match Database::records(tx, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match self.database.delete(tx, &record.id) { match Database::delete(tx, &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() {
@ -239,7 +234,7 @@ impl Tab {
} }
pub fn restore(&self, tx: &Transaction, app_browser_window_id: &i64) { pub fn restore(&self, tx: &Transaction, app_browser_window_id: &i64) {
match self.database.records(tx, app_browser_window_id) { match Database::records(tx, app_browser_window_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
let item = self.append(None, record.is_current); let item = self.append(None, record.is_current);
@ -256,7 +251,7 @@ impl Tab {
let mut page_number = 0; let mut page_number = 0;
for (_, item) in self.index.borrow().iter() { for (_, item) in self.index.borrow().iter() {
match self.database.add( match Database::add(
tx, tx,
app_browser_window_id, app_browser_window_id,
&match self.widget.gobject().current_page() { &match self.widget.gobject().current_page() {
@ -266,7 +261,7 @@ impl Tab {
) { ) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
let id = self.database.last_insert_id(tx); let id = Database::last_insert_id(tx);
item.label.save(tx, &id); item.label.save(tx, &id);

15
src/app/browser/window/tab/database.rs

@ -11,10 +11,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app_browser_window_tab` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
@ -28,7 +24,6 @@ impl Database {
} }
pub fn add( pub fn add(
&self,
tx: &Transaction, tx: &Transaction,
app_browser_window_id: &i64, app_browser_window_id: &i64,
is_current: &bool, is_current: &bool,
@ -42,11 +37,7 @@ impl Database {
) )
} }
pub fn records( pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> {
&self,
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`, `app_browser_window_id`,
@ -72,11 +63,11 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, 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(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} }
} }

22
src/app/browser/window/tab/label.rs

@ -13,7 +13,6 @@ use gtk::{glib::GString, Box};
use std::sync::Arc; use std::sync::Arc;
pub struct Label { pub struct Label {
database: Arc<Database>,
// Components // Components
pin: Arc<Pin>, pin: Arc<Pin>,
title: Arc<Title>, title: Arc<Title>,
@ -24,9 +23,6 @@ pub struct Label {
impl Label { impl Label {
// Construct // Construct
pub fn new(name: GString, is_pinned: bool) -> Label { pub fn new(name: GString, is_pinned: bool) -> Label {
// Init database
let database = Arc::new(Database::new());
// Components // Components
let pin = Arc::new(Pin::new(is_pinned)); let pin = Arc::new(Pin::new(is_pinned));
let title = Arc::new(Title::new()); let title = Arc::new(Title::new());
@ -35,20 +31,15 @@ impl Label {
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject())); let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject()));
// Result // Result
Self { Self { pin, title, widget }
database,
pin,
title,
widget,
}
} }
// Actions // Actions
pub fn clean(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn clean(&self, tx: &Transaction, app_browser_window_tab_id: &i64) {
match self.database.records(tx, app_browser_window_tab_id) { match Database::records(tx, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
match self.database.delete(tx, &record.id) { match Database::delete(tx, &record.id) {
Ok(_) => { Ok(_) => {
// Delegate clean action to childs // Delegate clean action to childs
// nothing yet.. // nothing yet..
@ -62,7 +53,7 @@ impl Label {
} }
pub fn restore(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn restore(&self, tx: &Transaction, app_browser_window_tab_id: &i64) {
match self.database.records(tx, app_browser_window_tab_id) { match Database::records(tx, app_browser_window_tab_id) {
Ok(records) => { Ok(records) => {
for record in records { for record in records {
self.pin(record.is_pinned); self.pin(record.is_pinned);
@ -76,10 +67,7 @@ impl Label {
} }
pub fn save(&self, tx: &Transaction, app_browser_window_tab_id: &i64) { pub fn save(&self, tx: &Transaction, app_browser_window_tab_id: &i64) {
match self match Database::add(tx, app_browser_window_tab_id, &self.is_pinned()) {
.database
.add(tx, app_browser_window_tab_id, &self.is_pinned())
{
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs
// nothing yet.. // nothing yet..

15
src/app/browser/window/tab/label/database.rs

@ -11,10 +11,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app_browser_window_tab_label` "CREATE TABLE IF NOT EXISTS `app_browser_window_tab_label`
@ -28,7 +24,6 @@ impl Database {
} }
pub fn add( pub fn add(
&self,
tx: &Transaction, tx: &Transaction,
app_browser_window_tab_id: &i64, app_browser_window_tab_id: &i64,
is_pinned: &bool, is_pinned: &bool,
@ -42,11 +37,7 @@ impl Database {
) )
} }
pub fn records( pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
&self,
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`,
@ -72,7 +63,7 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, 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_label` WHERE `id` = ?", "DELETE FROM `app_browser_window_tab_label` WHERE `id` = ?",
[id], [id],
@ -80,7 +71,7 @@ impl Database {
} }
/* not in use /* not in use
pub fn last_insert_id(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} */ } */
} }

12
src/app/database.rs

@ -9,10 +9,6 @@ pub struct Database {
} }
impl Database { impl Database {
pub fn new() -> Self {
Self {}
}
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 `app` "CREATE TABLE IF NOT EXISTS `app`
@ -23,11 +19,11 @@ impl Database {
) )
} }
pub fn add(&self, 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(&self, 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)? }))?;
@ -41,11 +37,11 @@ impl Database {
Ok(records) Ok(records)
} }
pub fn delete(&self, 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(&self, tx: &Transaction) -> i64 { pub fn last_insert_id(tx: &Transaction) -> i64 {
tx.last_insert_rowid() tx.last_insert_rowid()
} }
} }

Loading…
Cancel
Save