houhou/src-tauri/database-maker/src/main.rs

38 lines
805 B
Rust
Raw Normal View History

2023-06-11 20:08:15 +00:00
pub mod kradfile;
2023-06-11 20:07:06 +00:00
use std::{path::PathBuf, str::FromStr};
use anyhow::Result;
use clap::Parser;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
#[derive(Debug, Parser)]
struct Opt {
2023-06-11 20:08:15 +00:00
in_dir: PathBuf,
out_file: PathBuf,
2023-06-11 20:07:06 +00:00
}
#[tokio::main]
async fn main() -> Result<()> {
2023-06-11 20:08:15 +00:00
let opt = Opt::parse();
2023-06-11 20:07:06 +00:00
2023-06-11 20:08:15 +00:00
// Open sqlite db
let uri = format!("sqlite:{}", opt.out_file.display());
println!("Opening {}...", uri);
let options = SqliteConnectOptions::from_str(&uri)?.create_if_missing(true);
let pool = SqlitePoolOptions::new()
.max_connections(5)
.connect_with(options)
.await?;
2023-06-11 20:07:06 +00:00
2023-06-11 20:08:15 +00:00
// Migrate that shit
sqlx::migrate!().run(&pool).await?;
2023-06-11 20:07:06 +00:00
2023-06-11 20:08:15 +00:00
// Kradfile
kradfile::process_kradfile(&pool, opt.in_dir.join("kradfile.utf8")).await?;
2023-06-11 20:08:15 +00:00
println!("Hello, world!");
2023-06-11 20:07:06 +00:00
2023-06-11 20:08:15 +00:00
Ok(())
2023-06-11 20:07:06 +00:00
}