Browse Source

updated

integrate_codes_to_fields
anghenfil 2 years ago
parent
commit
a15201ea97
  1. 15
      database-planning.txt
  2. 3
      src/db_system/document.rs
  3. 9
      src/db_system/storage.rs

15
database-planning.txt

@ -1,10 +1,9 @@
Datenbank:
Internal Database consists of Documents; 1 document per survey
T_codes(p_code, survey, type, is_valid)
Example Document:
CREATE TABLE T_codes (
p_code INT NOT NULL,
survey INT NOT NULL,
type TINYINT NOT NULL,
PRIMARY KEY(p_code)
);
[
id: 1
name: Example survey
]

3
src/db_system/document.rs

@ -3,6 +3,7 @@
use std::string::ToString;
use std::collections::HashMap;
use serde::{Serialize, Deserialize};
use std::result::Iter;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum DbType {
@ -88,7 +89,7 @@ impl Document{
}
}
pub fn get_document(&self, key : &str) -> Option<Document>{
pub fn get_doc(&self, key : &str) -> Option<Document>{
match self.fields.get(key)?{
DbType::Document(value) => Some(value.clone()),
_ => None

9
src/db_system/storage.rs

@ -5,7 +5,8 @@ use serde::{Serialize, Deserialize};
use serde_json::{to_writer};
use std::fs::File;
use std::path::Path;
use std::io::{BufWriter, BufReader};
use std::io::{BufWriter, BufReader, Error, ErrorKind};
use std::error::Error as gerror;
lazy_static! {
pub static ref DOCUMENTS: RwLock<DocumentStorage> = RwLock::new(DocumentStorage{
@ -57,8 +58,10 @@ impl DocumentStorage{
match output{
Ok(file)
=> {
serde_json::to_writer(BufWriter::new(file), &self.documents);
None
match serde_json::to_writer(BufWriter::new(file), &self.documents){
Ok(_) => None,
Err(error) => Some(Error::new(ErrorKind::Other, format!("Serialization not successful: {}", error.description())))
}
}
Err(error) => {
Some(error)

Loading…
Cancel
Save