Add container simulation with PostgreSQL and SQLite support
This commit is contained in:
36
apps/container/src/env.rs
Normal file
36
apps/container/src/env.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::io::Write;
|
||||
|
||||
use shared::db_type::DBType;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum EnvFileType {
|
||||
DotEnv,
|
||||
Yaml,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EnvFile {
|
||||
pub file_type: EnvFileType,
|
||||
pub db_type: DBType,
|
||||
pub db_url: String,
|
||||
}
|
||||
|
||||
impl EnvFile {
|
||||
pub fn write(self, path: impl AsRef<std::path::Path>) {
|
||||
let path_ref = path.as_ref();
|
||||
println!("Config file path: {}", path_ref.display());
|
||||
let mut config_file =
|
||||
std::fs::File::create(path_ref).expect("Failed to create config file");
|
||||
//
|
||||
self._write_line(&mut config_file, "DB_TYPE", &self.db_type.to_string());
|
||||
self._write_line(&mut config_file, "DATABASE_URL", &self.db_url.to_string())
|
||||
}
|
||||
|
||||
fn _write_line(&self, file: &mut std::fs::File, key: &str, value: &str) {
|
||||
match self.file_type {
|
||||
EnvFileType::DotEnv => writeln!(file, "{}={}", key, value),
|
||||
EnvFileType::Yaml => writeln!(file, "{}: \"{}\"", key, value),
|
||||
}
|
||||
.expect("Failed to write to config file");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user