Add ability to set database folder, and port.

This commit is contained in:
Ethan O'Brien
2024-07-03 11:49:52 -05:00
parent 6575ea1eb0
commit ec8aad5fde
4 changed files with 53 additions and 20 deletions

View File

@@ -1,6 +1,8 @@
use rusqlite::{Connection, params, ToSql};
use std::sync::Mutex;
use json::{JsonValue, array};
use clap::Parser;
use std::fs;
use crate::router::clear_rate::Live;
@@ -11,7 +13,9 @@ pub struct SQLite {
impl SQLite {
pub fn new(path: &str, setup: fn(&SQLite)) -> SQLite {
let conn = Connection::open(path).unwrap();
let args = crate::Args::parse();
fs::create_dir_all(&args.path).unwrap();
let conn = Connection::open(format!("{}/{}", args.path, path)).unwrap();
conn.execute("PRAGMA foreign_keys = ON;", ()).unwrap();
let instance = SQLite {
engine: Mutex::new(conn),