This commit is contained in:
2025-04-20 07:28:59 +02:00
parent eccea1ad04
commit 0051754c65
11 changed files with 251 additions and 93 deletions

View File

@@ -43,6 +43,8 @@ pub struct OurDBConfig {
/// - 4: For databases with < 4,294,967,296 records (single file)
/// - 6: For large databases requiring multiple files (default)
pub keysize: Option<u8>,
/// Whether to reset the database if it exists (default: false)
pub reset: Option<bool>,
}
/// Arguments for setting a value in OurDB
@@ -56,6 +58,11 @@ pub struct OurDBSetArgs<'a> {
impl OurDB {
/// Creates a new OurDB instance with the given configuration
pub fn new(config: OurDBConfig) -> Result<Self, Error> {
// If reset is true and the path exists, remove it first
if config.reset.unwrap_or(false) && config.path.exists() {
std::fs::remove_dir_all(&config.path)?;
}
// Create directory if it doesn't exist
std::fs::create_dir_all(&config.path)?;