A digital life memoir of your life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

mod domain;
use std::path::Path;
use std::sync::Arc;
use axum::routing::post;
use axum::Router;
use clap::Parser;
use sqlx::sqlite::SqliteConnectOptions;
use sqlx::sqlite::SqlitePoolOptions;
use sqlx::SqlitePool;
use tracing_subscriber::fmt;
use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
use crate::domain::options::Options;
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
dotenv::dotenv().ok();
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init();
let options = Options::parse();
let pool = init_db(&options.working_directory).await?;
let state = Arc::new(pool);
Ok(())
}
/// Initialize the database.
async fn init_db(wd: &Path) -> Result<SqlitePool, sqlx::Error> {
tracing::debug!("Migrating...");
let pool = SqlitePoolOptions::new()
.connect_with(
SqliteConnectOptions::new()
.filename(wd.join("memoirs.sqlite"))
.create_if_missing(true),
)
.await?;
sqlx::migrate!("./migrations").run(&pool).await?;
tracing::debug!("Migration done.");
Ok(pool)
}
/// Start the server.
async fn serve(state: Arc<SqlitePool>, addr: &str) {
let app = Router::new().route("/", post(add_entry));
tracing::info!(addr, "Store server up");
axum::Server::bind(&addr.parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}
///
async fn add_entry(state: Arc<SqlitePool>) -> Json {}