sprinklers_rs/src/main.rs

44 lines
1003 B
Rust

use color_eyre::eyre::Result;
use rusqlite::Connection as DbConnection;
use rusqlite::NO_PARAMS;
use tracing::info;
mod db;
mod migrations;
mod model;
mod section_interface;
mod section_runner;
#[cfg(test)]
mod trace_listeners;
use model::Section;
fn setup_db() -> Result<DbConnection> {
// let conn = DbConnection::open_in_memory()?;
let mut conn = DbConnection::open("test.db")?;
let migs = db::create_migrations();
migs.apply(&mut conn)?;
Ok(conn)
}
fn query_sections(conn: &DbConnection) -> Result<Vec<Section>> {
let mut statement = conn.prepare_cached("SELECT id, name, interface_id FROM sections;")?;
let rows = statement.query_map(NO_PARAMS, Section::from_sql)?;
Ok(rows.collect::<Result<Vec<_>, _>>()?)
}
fn main() -> Result<()> {
env_logger::init();
color_eyre::install()?;
let conn = setup_db()?;
let sections = query_sections(&conn)?;
for sec in sections {
info!(section = debug(&sec), "read section");
}
Ok(())
}