2023-06-07 09:52:19 +03:00
|
|
|
use sqlx::sqlite::SqliteConnectOptions;
|
2023-06-27 10:40:37 +03:00
|
|
|
use std::fs;
|
2023-06-07 09:52:19 +03:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<(), std::io::Error> {
|
|
|
|
dotenv::dotenv().ok();
|
2023-03-27 09:59:36 +03:00
|
|
|
|
2023-06-27 10:40:37 +03:00
|
|
|
// always start with a fresh database to have
|
|
|
|
// latest db schema
|
|
|
|
let db_path = "../../affine.db";
|
|
|
|
|
|
|
|
// check if db exists and then remove file
|
|
|
|
if fs::metadata(db_path).is_ok() {
|
|
|
|
fs::remove_file(db_path)?;
|
|
|
|
}
|
|
|
|
|
2023-03-27 09:59:36 +03:00
|
|
|
napi_build::setup();
|
2023-06-07 09:52:19 +03:00
|
|
|
let options = SqliteConnectOptions::new()
|
2023-06-27 10:40:37 +03:00
|
|
|
.filename(db_path)
|
2023-06-07 09:52:19 +03:00
|
|
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Off)
|
|
|
|
.locking_mode(sqlx::sqlite::SqliteLockingMode::Exclusive)
|
|
|
|
.create_if_missing(true);
|
|
|
|
let pool = sqlx::sqlite::SqlitePoolOptions::new()
|
|
|
|
.max_connections(1)
|
|
|
|
.connect_with(options)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
sqlx::query(affine_schema::SCHEMA)
|
|
|
|
.execute(&pool)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-05-10 12:16:48 +03:00
|
|
|
Ok(())
|
2023-03-27 09:59:36 +03:00
|
|
|
}
|