2024-10-02 15:22:50 +03:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
pub struct Database {
|
|
|
|
connection: Arc<sqlite::Connection>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Database {
|
|
|
|
// Construct new application DB
|
2024-10-02 15:39:51 +03:00
|
|
|
pub fn init(connection: Arc<sqlite::Connection>) -> Database {
|
2024-10-02 17:25:20 +03:00
|
|
|
// Init app table
|
|
|
|
if let Err(e) = connection.execute(
|
|
|
|
r"
|
|
|
|
CREATE TABLE IF NOT EXISTS `app`
|
|
|
|
(
|
|
|
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
|
|
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
)
|
|
|
|
",
|
|
|
|
) {
|
|
|
|
panic!("{e}");
|
|
|
|
}
|
2024-10-02 15:22:50 +03:00
|
|
|
|
|
|
|
// Return struct
|
2024-10-02 17:25:20 +03:00
|
|
|
Self { connection }
|
2024-10-02 15:22:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Restore previous browser session from DB
|
|
|
|
pub fn restore(&self) {
|
|
|
|
// @TODO migration test
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save browser session to DB
|
|
|
|
pub fn save(&self) {
|
|
|
|
// @TODO migration test
|
|
|
|
}
|
|
|
|
}
|