diff --git a/src/db.rs b/src/db.rs index f4f27a7..6f0c131 100644 --- a/src/db.rs +++ b/src/db.rs @@ -83,14 +83,14 @@ pub fn insert(conn: &Connection, dblog: &DbLog) -> Result<()> { Ok(()) } -struct DbLog { - serial: u16, - time: String, - latitude: f64, - longitude: f64, - speed: u16, - height: u16, - direction: u16, +pub struct DbLog { + pub serial: u16, + pub time: String, + pub latitude: f64, + pub longitude: f64, + pub speed: u16, + pub height: u16, + pub direction: u16, } impl ToSql for DbLog { @@ -98,18 +98,3 @@ impl ToSql for DbLog { Ok(self.time.to_sql().unwrap()) } } - -impl DbLog { - fn to_params(&self) -> &[&dyn ToSql; 7] { - let res = params![ - self.time, - self.serial, - self.latitude, - self.longitude, - self.speed, - self.height, - self.direction - ]; - res - } -} diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 46e3113..80ac0f8 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -323,17 +323,16 @@ impl Message { }*/ let conn = connectdb().unwrap(); - insert( - &conn, - &inmsg.header.serial_number, - &t.time.format("%Y-%m-%d %H:%M:%S").to_string(), - &t.latitude, - &t.longitude, - &t.speed, - &t.height, - &t.direction, - ) - .unwrap(); + let dblog = crate::db::DbLog { + serial: inmsg.header.serial_number, + time: t.time.format("%Y-%m-%d %H:%M:%S").to_string(), + latitude: t.latitude, + longitude: t.longitude, + speed: t.speed, + height: t.height, + direction: t.direction, + }; + insert(&conn, &dblog).unwrap(); } _ => {} }