|
|
|
#![feature(drain_filter)]
|
|
|
|
|
|
|
|
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<()> {
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
.with_ansi(true)
|
|
|
|
.with_env_filter(
|
|
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
|
|
)
|
|
|
|
.init();
|
|
|
|
color_eyre::install()?;
|
|
|
|
|
|
|
|
let conn = setup_db()?;
|
|
|
|
|
|
|
|
let sections = query_sections(&conn)?;
|
|
|
|
for sec in sections {
|
|
|
|
info!(section = debug(&sec), "read section");
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|