From b56cd19164a05a101ca869d23f4f2ea5e16ce9ac Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 26 Jul 2025 05:25:15 +0300 Subject: [PATCH] move `DateTime` type out of DB row member --- src/profile/tofu.rs | 12 ++++++++---- src/profile/tofu/database.rs | 9 ++++----- src/profile/tofu/database/row.rs | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/profile/tofu.rs b/src/profile/tofu.rs index ac7c1803..745a66e6 100644 --- a/src/profile/tofu.rs +++ b/src/profile/tofu.rs @@ -6,7 +6,7 @@ use certificate::Certificate; use database::Database; use gtk::{ gio::TlsCertificate, - glib::{GString, Uri}, + glib::{DateTime, GString, Uri}, }; use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; @@ -36,7 +36,7 @@ impl Tofu { for r in records { if m.insert( (r.host.into(), r.port), - Certificate::from_db(Some(r.id), &r.pem, r.time)?, + Certificate::from_db(Some(r.id), &r.pem, DateTime::from_unix_local(r.time)?)?, ) .is_some() { @@ -82,8 +82,12 @@ impl Tofu { pub fn save(&self) -> Result<()> { for ((host, port), certificate) in self.memory.borrow_mut().drain() { if certificate.id().is_none() { - self.database - .add(host.into(), port, certificate.time(), &certificate.pem())?; + self.database.add( + host.into(), + port, + certificate.time().to_unix(), + &certificate.pem(), + )?; } } Ok(()) diff --git a/src/profile/tofu/database.rs b/src/profile/tofu/database.rs index 261d9a66..b10888d5 100644 --- a/src/profile/tofu/database.rs +++ b/src/profile/tofu/database.rs @@ -1,7 +1,6 @@ mod row; use anyhow::Result; -use gtk::glib::DateTime; use r2d2::Pool; use r2d2_sqlite::SqliteConnectionManager; use row::Row; @@ -34,7 +33,7 @@ impl Database { /// Create new record in database /// * return last insert ID on success - pub fn add(&self, host: String, port: i32, time: &DateTime, pem: &str) -> Result { + pub fn add(&self, host: String, port: i32, time: i64, pem: &str) -> Result { let mut connection = self.pool.get()?; let tx = connection.transaction()?; let id = insert(&tx, self.profile_id, host, port, time, pem)?; @@ -68,7 +67,7 @@ pub fn insert( profile_id: i64, host: String, port: i32, - time: &DateTime, + time: i64, pem: &str, ) -> Result { tx.execute( @@ -81,7 +80,7 @@ pub fn insert( ) VALUES (?, ?, ?, ?, ?) ON CONFLICT (`host`, `port`) DO UPDATE SET `time` = `excluded`.`time`, `pem` = `excluded`.`pem`", - (profile_id, time.to_unix(), host, port, pem), + (profile_id, time, host, port, pem), )?; Ok(tx.last_insert_rowid()) } @@ -102,7 +101,7 @@ pub fn select(tx: &Transaction, profile_id: i64) -> Result> { //profile_id: row.get(1)?, host: row.get(2)?, port: row.get(3)?, - time: DateTime::from_unix_local(row.get(4)?).unwrap(), + time: row.get(4)?, pem: row.get(5)?, }) })?; diff --git a/src/profile/tofu/database/row.rs b/src/profile/tofu/database/row.rs index 91fe12d2..014a597f 100644 --- a/src/profile/tofu/database/row.rs +++ b/src/profile/tofu/database/row.rs @@ -3,5 +3,5 @@ pub struct Row { pub id: i64, pub pem: String, pub port: i32, - pub time: gtk::glib::DateTime, + pub time: i64, }