handle errors, drop version from struct

This commit is contained in:
yggverse 2024-10-02 17:25:20 +03:00
parent afd9bc3134
commit b60ac5fb3f

View file

@ -2,33 +2,26 @@ use std::sync::Arc;
pub struct Database {
connection: Arc<sqlite::Connection>,
// Autostart migrate feature on app and db versions mismatch
version: i32,
}
impl Database {
// Construct new application DB
pub fn init(connection: Arc<sqlite::Connection>) -> Database {
// 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 */
// 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}");
}
// Return struct
Self {
connection,
version: 1, // @TODO
}
Self { connection }
}
// Restore previous browser session from DB