change sqlite wrapper to rusqlite, update database api

This commit is contained in:
yggverse 2024-10-02 20:00:08 +03:00
parent 7b9937eac1
commit 490338930d
4 changed files with 19 additions and 20 deletions

View File

@ -10,8 +10,9 @@ categories = ["network-programming", "gui"]
repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4" repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4"
# homepage = "https://yggverse.github.io" # homepage = "https://yggverse.github.io"
[dependencies] [dependencies.sqlite]
sqlite = "0.36.1" package = "rusqlite"
version = "0.32.1"
[dependencies.gtk] [dependencies.gtk]
package = "gtk4" package = "gtk4"

View File

@ -75,10 +75,10 @@ impl App {
// Init events // Init events
app.connect_activate({ app.connect_activate({
let database = database.clone(); // let database = database.clone();
move |application| { move |application| {
// Restore previous session // Restore previous session
database.restore(); // @TODO
// Init components // Init components
let browser = Arc::new(Browser::new( let browser = Arc::new(Browser::new(

View File

@ -10,13 +10,12 @@ impl Database {
pub fn init(connection: Arc<Connection>) -> Database { pub fn init(connection: Arc<Connection>) -> Database {
// Init app table // Init app table
if let Err(error) = connection.execute( if let Err(error) = connection.execute(
r" "CREATE TABLE IF NOT EXISTS `app`
CREATE TABLE IF NOT EXISTS `app` (
( `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP )",
) [],
",
) { ) {
panic!("{error}"); panic!("{error}");
} }
@ -25,13 +24,11 @@ impl Database {
Self { connection } Self { connection }
} }
// Restore previous browser session from DB pub fn add(&self) -> i64 {
pub fn restore(&self) { if let Err(error) = self.connection.execute("INSERT INTO `app`", []) {
// @TODO migration test panic!("{error}");
} }
// Save browser session to DB self.connection.last_insert_rowid()
pub fn save(&self) {
// @TODO migration test
} }
} }

View File

@ -2,6 +2,7 @@ mod app;
use app::App; use app::App;
use gtk::glib::{user_config_dir, ExitCode}; use gtk::glib::{user_config_dir, ExitCode};
use sqlite::Connection;
use std::{fs::create_dir_all, sync::Arc}; use std::{fs::create_dir_all, sync::Arc};
fn main() -> ExitCode { fn main() -> ExitCode {
@ -20,8 +21,8 @@ fn main() -> ExitCode {
profile_database_path.push("database.sqlite3"); profile_database_path.push("database.sqlite3");
// Init database connection // Init database connection
let profile_database_connection = match sqlite::open(profile_database_path) { let profile_database_connection = match Connection::open(profile_database_path) {
Ok(profile_database_connection) => Arc::new(profile_database_connection), Ok(connection) => Arc::new(connection),
Err(error) => panic!("Failed to connect profile database: {error}"), Err(error) => panic!("Failed to connect profile database: {error}"),
}; };