-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27eae2d
commit 302ede3
Showing
3 changed files
with
36 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
use hashbrown::HashMap; | ||
use std::{fs::File, path::Path}; | ||
|
||
use crate::stores::container; | ||
use crate::{stores::container, values::key::Key}; | ||
|
||
use super::container::Container; | ||
|
||
pub struct Database { | ||
filename: String, | ||
collections: Vec<container::Container>, | ||
pub filename: String, | ||
pub containers: Vec<HashMap<String, Container>>, | ||
} | ||
|
||
impl Database { | ||
fn read_collections() -> Vec<container::Container> { | ||
unimplemented!() | ||
} | ||
|
||
pub fn create_collection() { | ||
unimplemented!() | ||
} | ||
pub fn delete_collection() { | ||
unimplemented!() | ||
} | ||
|
||
pub(crate) fn new(filename: String) -> Database { | ||
if !Path::new(&filename).exists() { | ||
File::create(&filename).expect("Unable to Database create file"); | ||
} | ||
|
||
Database { | ||
filename, | ||
collections: Vec::new(), | ||
containers: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn get_container(&self, name: &str) -> Option<&Container> { | ||
for container in &self.containers { | ||
if let Some(container) = container.get(name) { | ||
return Some(container); | ||
} | ||
} | ||
|
||
None | ||
} | ||
|
||
pub fn create_container(&mut self, name: String) { | ||
let mut container = HashMap::new(); | ||
container.insert(name.clone(), Container::new(name)); | ||
self.containers.push(container); | ||
} | ||
} |