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

33 lines
729 B
Rust
Raw Normal View History

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 {
in_dir: PathBuf,
out_file: PathBuf,
}
#[tokio::main]
async fn main() -> Result<()> {
let opt = Opt::parse();
// 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?;
// Migrate that shit
sqlx::migrate!().run(&pool).await?;
println!("Hello, world!");
Ok(())
}