Add container simulation with PostgreSQL and SQLite support

This commit is contained in:
GW_MC
2025-11-11 20:53:20 +08:00
parent 54080eb0c9
commit 6b3172d88b
14 changed files with 2818 additions and 0 deletions

36
apps/container/src/env.rs Normal file
View 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");
}
}