mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
make transactionable mathods static
This commit is contained in:
parent
bd6138fced
commit
a1f2d57b6d
12 changed files with 52 additions and 128 deletions
|
|
@ -11,10 +11,6 @@ pub struct Database {
|
|||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||
|
|
@ -28,7 +24,6 @@ impl Database {
|
|||
}
|
||||
|
||||
pub fn add(
|
||||
&self,
|
||||
tx: &Transaction,
|
||||
app_browser_window_id: &i64,
|
||||
is_current: &bool,
|
||||
|
|
@ -42,11 +37,7 @@ impl Database {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn records(
|
||||
&self,
|
||||
tx: &Transaction,
|
||||
app_browser_window_id: &i64,
|
||||
) -> Result<Vec<Table>, Error> {
|
||||
pub fn records(tx: &Transaction, app_browser_window_id: &i64) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_id`,
|
||||
|
|
@ -72,11 +63,11 @@ impl Database {
|
|||
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])
|
||||
}
|
||||
|
||||
pub fn last_insert_id(&self, tx: &Transaction) -> i64 {
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use gtk::{glib::GString, Box};
|
|||
use std::sync::Arc;
|
||||
|
||||
pub struct Label {
|
||||
database: Arc<Database>,
|
||||
// Components
|
||||
pin: Arc<Pin>,
|
||||
title: Arc<Title>,
|
||||
|
|
@ -24,9 +23,6 @@ pub struct Label {
|
|||
impl Label {
|
||||
// Construct
|
||||
pub fn new(name: GString, is_pinned: bool) -> Label {
|
||||
// Init database
|
||||
let database = Arc::new(Database::new());
|
||||
|
||||
// Components
|
||||
let pin = Arc::new(Pin::new(is_pinned));
|
||||
let title = Arc::new(Title::new());
|
||||
|
|
@ -35,20 +31,15 @@ impl Label {
|
|||
let widget = Arc::new(Widget::new(name, pin.gobject(), title.gobject()));
|
||||
|
||||
// Result
|
||||
Self {
|
||||
database,
|
||||
pin,
|
||||
title,
|
||||
widget,
|
||||
}
|
||||
Self { pin, title, widget }
|
||||
}
|
||||
|
||||
// Actions
|
||||
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) => {
|
||||
for record in records {
|
||||
match self.database.delete(tx, &record.id) {
|
||||
match Database::delete(tx, &record.id) {
|
||||
Ok(_) => {
|
||||
// Delegate clean action to childs
|
||||
// nothing yet..
|
||||
|
|
@ -62,7 +53,7 @@ impl Label {
|
|||
}
|
||||
|
||||
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) => {
|
||||
for record in records {
|
||||
self.pin(record.is_pinned);
|
||||
|
|
@ -76,10 +67,7 @@ impl Label {
|
|||
}
|
||||
|
||||
pub fn save(&self, tx: &Transaction, app_browser_window_tab_id: &i64) {
|
||||
match self
|
||||
.database
|
||||
.add(tx, app_browser_window_tab_id, &self.is_pinned())
|
||||
{
|
||||
match Database::add(tx, app_browser_window_tab_id, &self.is_pinned()) {
|
||||
Ok(_) => {
|
||||
// Delegate save action to childs
|
||||
// nothing yet..
|
||||
|
|
|
|||
|
|
@ -11,10 +11,6 @@ pub struct Database {
|
|||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_label`
|
||||
|
|
@ -28,7 +24,6 @@ impl Database {
|
|||
}
|
||||
|
||||
pub fn add(
|
||||
&self,
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_id: &i64,
|
||||
is_pinned: &bool,
|
||||
|
|
@ -42,11 +37,7 @@ impl Database {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn records(
|
||||
&self,
|
||||
tx: &Transaction,
|
||||
app_browser_window_tab_id: &i64,
|
||||
) -> Result<Vec<Table>, Error> {
|
||||
pub fn records(tx: &Transaction, app_browser_window_tab_id: &i64) -> Result<Vec<Table>, Error> {
|
||||
let mut stmt = tx.prepare(
|
||||
"SELECT `id`,
|
||||
`app_browser_window_tab_id`,
|
||||
|
|
@ -72,7 +63,7 @@ impl Database {
|
|||
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_label` WHERE `id` = ?",
|
||||
[id],
|
||||
|
|
@ -80,7 +71,7 @@ impl Database {
|
|||
}
|
||||
|
||||
/* not in use
|
||||
pub fn last_insert_id(&self, tx: &Transaction) -> i64 {
|
||||
pub fn last_insert_id(tx: &Transaction) -> i64 {
|
||||
tx.last_insert_rowid()
|
||||
} */
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue