use arc for db connection

This commit is contained in:
yggverse 2024-09-22 12:30:32 +03:00
parent db43289e24
commit 998e3170fb
2 changed files with 6 additions and 5 deletions

View file

@ -9,13 +9,13 @@ use gtk::{
Application, ApplicationWindow, Application, ApplicationWindow,
}; };
use sqlite::Connection;
pub struct Browser { pub struct Browser {
db: Arc<sqlite::Connection>,
pub widget: Arc<gtk::ApplicationWindow>, pub widget: Arc<gtk::ApplicationWindow>,
pub main: Arc<main::Main>, pub main: Arc<main::Main>,
} }
pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Browser { pub fn new(app: &Application, db: Arc<sqlite::Connection>, width: i32, height: i32) -> Browser {
// Init components // Init components
let main = Arc::new(main::new()); let main = Arc::new(main::new());
@ -55,5 +55,5 @@ pub fn new(app: &Application, db: &Connection, width: i32, height: i32) -> Brows
widget.add_action_entries([action_tab_append, action_debug, action_quit]); widget.add_action_entries([action_tab_append, action_debug, action_quit]);
// Done // Done
Browser { widget, main } Browser { db, widget, main }
} }

View file

@ -1,6 +1,7 @@
mod browser; mod browser;
use std::fs; use std::fs;
use std::sync::Arc;
use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt}; use gtk::prelude::{ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt};
@ -35,12 +36,12 @@ fn main() -> glib::ExitCode {
db.push("database.sqlite3"); db.push("database.sqlite3");
let db = match sqlite::open(db) { let db = match sqlite::open(db) {
Ok(db) => db, Ok(db) => Arc::new(db),
Err(e) => panic!("Failed to connect profile database: {e}"), Err(e) => panic!("Failed to connect profile database: {e}"),
}; };
move |this| { move |this| {
browser::new(&this, &db, 640, 480).widget.present(); browser::new(&this, db.clone(), 640, 480).widget.present();
} }
}); });