exoplanet/room/src/main.rs

42 lines
895 B
Rust

use std::ffi::c_int;
use std::path::PathBuf;
use anyhow::Result;
use clap::Parser;
use log::{debug, error, info, trace, warn};
use rusqlite::Connection;
/// Exoplanet room hosting daemon.
#[derive(Parser, Debug)]
pub struct Args {
/// Port to host the room on.
#[arg(short, long)]
pub port: u16,
/// Path to the room database file.
#[arg(short, long)]
pub db: PathBuf,
}
fn sqlite_logger(error_code: c_int, message: &str) {
error!(target: "sqlite", "({}) {}", error_code, message);
}
fn main() -> Result<()> {
let args = Args::parse();
env_logger::init();
unsafe {
rusqlite::trace::config_log(Some(sqlite_logger))?;
}
info!("Opening room database at {:?}...", args.db);
let db = Connection::open(&args.db)?;
info!("Successfully opened sqlite3 connection.");
db.execute(include_str!("db-init.sql"), ())?;
Ok(())
}