mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 01:25:27 +00:00
resolve deadlock issue, draft migration features
This commit is contained in:
parent
259ec321be
commit
366c5fad8e
12 changed files with 192 additions and 210 deletions
|
|
@ -11,7 +11,11 @@ pub struct Database {
|
|||
}
|
||||
|
||||
impl Database {
|
||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab`
|
||||
(
|
||||
|
|
@ -20,9 +24,7 @@ impl Database {
|
|||
`is_current` INTEGER NOT NULL
|
||||
)",
|
||||
[],
|
||||
)?;
|
||||
|
||||
Ok(Self {})
|
||||
)
|
||||
}
|
||||
|
||||
pub fn add(
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ mod widget;
|
|||
|
||||
use database::Database;
|
||||
use pin::Pin;
|
||||
use sqlite::{Connection, Transaction};
|
||||
use sqlite::Transaction;
|
||||
use title::Title;
|
||||
use widget::Widget;
|
||||
|
||||
use gtk::{glib::GString, Box};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct Label {
|
||||
database: Arc<Database>,
|
||||
|
|
@ -23,37 +23,9 @@ pub struct Label {
|
|||
|
||||
impl Label {
|
||||
// Construct
|
||||
pub fn new(
|
||||
profile_database_connection: Arc<RwLock<Connection>>,
|
||||
name: GString,
|
||||
is_pinned: bool,
|
||||
) -> Label {
|
||||
pub fn new(name: GString, is_pinned: bool) -> Label {
|
||||
// Init database
|
||||
let database = {
|
||||
/* @TODO init outside
|
||||
// Init writable database connection
|
||||
let mut connection = match profile_database_connection.write() {
|
||||
Ok(connection) => connection,
|
||||
Err(e) => todo!("{e}"),
|
||||
};
|
||||
|
||||
// Init new transaction
|
||||
let transaction = match connection.transaction() {
|
||||
Ok(transaction) => transaction,
|
||||
Err(e) => todo!("{e}"),
|
||||
};
|
||||
|
||||
// Init database structure
|
||||
match Database::init(&transaction) {
|
||||
Ok(database) => match transaction.commit() {
|
||||
Ok(_) => Arc::new(database),
|
||||
Err(e) => todo!("{e}"),
|
||||
},
|
||||
Err(e) => todo!("{e}"),
|
||||
} */
|
||||
|
||||
Arc::new(Database::new())
|
||||
};
|
||||
let database = Arc::new(Database::new());
|
||||
|
||||
// Components
|
||||
let pin = Arc::new(Pin::new(is_pinned));
|
||||
|
|
@ -135,4 +107,18 @@ impl Label {
|
|||
pub fn gobject(&self) -> &Box {
|
||||
&self.widget.gobject()
|
||||
}
|
||||
|
||||
// Tools
|
||||
pub fn migrate(tx: &Transaction) -> Result<(), String> {
|
||||
// Migrate self components
|
||||
if let Err(e) = Database::init(&tx) {
|
||||
return Err(e.to_string());
|
||||
}
|
||||
|
||||
// Delegate migration to childs
|
||||
// nothing yet..
|
||||
|
||||
// Success
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ impl Database {
|
|||
Self {}
|
||||
}
|
||||
|
||||
pub fn init(tx: &Transaction) -> Result<Database, Error> {
|
||||
pub fn init(tx: &Transaction) -> Result<usize, Error> {
|
||||
tx.execute(
|
||||
"CREATE TABLE IF NOT EXISTS `app_browser_window_tab_label`
|
||||
(
|
||||
|
|
@ -24,9 +24,7 @@ impl Database {
|
|||
`is_pinned` INTEGER NOT NULL
|
||||
)",
|
||||
[],
|
||||
)?;
|
||||
|
||||
Ok(Self {})
|
||||
)
|
||||
}
|
||||
|
||||
pub fn add(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue