Yoda/src/app/database.rs

44 lines
1.1 KiB
Rust
Raw Normal View History

2024-10-02 15:22:50 +03:00
use std::sync::Arc;
pub struct Database {
connection: Arc<sqlite::Connection>,
// Autostart migrate feature on app and db versions mismatch
2024-10-02 15:39:51 +03:00
version: i32,
2024-10-02 15:22:50 +03:00
}
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 15:22:50 +03:00
// Create app table if not exist yet
/*
connection
.execute(
r"
CREATE TABLE IF NOT EXISTS `app`
(
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`time` INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP,
`version` VARCHAR NOT NULL
)
",
)
.unwrap(); // @TODO handle errors */
// Return struct
Self {
connection,
2024-10-02 15:39:51 +03:00
version: 1, // @TODO
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
}
}