micodus_server/src/db/mod.rs

78 lines
1.7 KiB
Rust

//pub mod libsql_engine;
pub mod sqlite_engine;
pub enum SQLEngine {
SQLite(sqlite_engine::SQLiteEngine),
//LibSQL(libsql_engine::LibSQLEngine),
}
pub trait Engine {
fn connect(&mut self);
fn init(&mut self);
fn insert(&mut self, dblog: &DbLog);
}
impl Engine for SQLEngine {
fn connect(&mut self) {
match self {
Self::SQLite(engine) => engine.connect(),
//Self::LibSQL(engine) => engine.connect(),
}
}
fn init(&mut self) {
match self {
Self::SQLite(engine) => engine.init(),
//Self::LibSQL(engine) => engine.connect(),
}
}
fn insert(&mut self, dblog: &DbLog) {
match self {
Self::SQLite(engine) => engine.insert(&dblog),
//Self::LibSQL(engine) => engine.connect(),
}
}
}
impl From<sqlite_engine::SQLiteEngine> for SQLEngine {
fn from(store: sqlite_engine::SQLiteEngine) -> Self {
Self::SQLite(store)
}
}
/*impl From<libsql_engine::LibSQLEngine> for SQLEngine {
fn from(store: libsql_engine::LibSQLEngine) -> Self {
Self::LibSQL(store)
}
}*/
#[derive(Default, Clone)]
pub struct DbLog {
pub time: String,
pub latitude: f64,
pub longitude: f64,
pub speed: u16,
pub height: u16,
pub direction: u16,
pub serial: u16,
pub is_satellite: bool,
}
impl std::fmt::Display for DbLog {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{} {} {} {} {} {} {} {} ",
self.time,
self.latitude,
self.longitude,
self.speed,
self.height,
self.direction,
self.serial,
self.is_satellite,
)
}
}