mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
change sqlite wrapper to rusqlite, update database api
This commit is contained in:
parent
7b9937eac1
commit
490338930d
@ -10,8 +10,9 @@ categories = ["network-programming", "gui"]
|
||||
repository = "https://github.com/YGGverse/Yoda/tree/Rust-GTK4"
|
||||
# homepage = "https://yggverse.github.io"
|
||||
|
||||
[dependencies]
|
||||
sqlite = "0.36.1"
|
||||
[dependencies.sqlite]
|
||||
package = "rusqlite"
|
||||
version = "0.32.1"
|
||||
|
||||
[dependencies.gtk]
|
||||
package = "gtk4"
|
||||
|
@ -75,10 +75,10 @@ impl App {
|
||||
|
||||
// Init events
|
||||
app.connect_activate({
|
||||
let database = database.clone();
|
||||
// let database = database.clone();
|
||||
move |application| {
|
||||
// Restore previous session
|
||||
database.restore();
|
||||
// @TODO
|
||||
|
||||
// Init components
|
||||
let browser = Arc::new(Browser::new(
|
||||
|
@ -10,13 +10,12 @@ impl Database {
|
||||
pub fn init(connection: Arc<Connection>) -> Database {
|
||||
// Init app table
|
||||
if let Err(error) = connection.execute(
|
||||
r"
|
||||
CREATE TABLE IF NOT EXISTS `app`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
",
|
||||
"CREATE TABLE IF NOT EXISTS `app`
|
||||
(
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)",
|
||||
[],
|
||||
) {
|
||||
panic!("{error}");
|
||||
}
|
||||
@ -25,13 +24,11 @@ impl Database {
|
||||
Self { connection }
|
||||
}
|
||||
|
||||
// Restore previous browser session from DB
|
||||
pub fn restore(&self) {
|
||||
// @TODO migration test
|
||||
}
|
||||
pub fn add(&self) -> i64 {
|
||||
if let Err(error) = self.connection.execute("INSERT INTO `app`", []) {
|
||||
panic!("{error}");
|
||||
}
|
||||
|
||||
// Save browser session to DB
|
||||
pub fn save(&self) {
|
||||
// @TODO migration test
|
||||
self.connection.last_insert_rowid()
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ mod app;
|
||||
|
||||
use app::App;
|
||||
use gtk::glib::{user_config_dir, ExitCode};
|
||||
use sqlite::Connection;
|
||||
use std::{fs::create_dir_all, sync::Arc};
|
||||
|
||||
fn main() -> ExitCode {
|
||||
@ -20,8 +21,8 @@ fn main() -> ExitCode {
|
||||
profile_database_path.push("database.sqlite3");
|
||||
|
||||
// Init database connection
|
||||
let profile_database_connection = match sqlite::open(profile_database_path) {
|
||||
Ok(profile_database_connection) => Arc::new(profile_database_connection),
|
||||
let profile_database_connection = match Connection::open(profile_database_path) {
|
||||
Ok(connection) => Arc::new(connection),
|
||||
Err(error) => panic!("Failed to connect profile database: {error}"),
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user