pub struct RecordData {
pub location: usize,
pub location_type: u8,
pub hash_data: HashMap<usize, RecordCharacteristics>,
pub record_counter: usize,
pub data_base: String,
}
Fields§
§location: usize
§location_type: u8
§hash_data: HashMap<usize, RecordCharacteristics>
§record_counter: usize
§data_base: String
Implementations§
Source§impl RecordData
impl RecordData
Sourcepub fn add_record_with_key<T>(&mut self, key_to_add: String, record: T)where
T: Base,
pub fn add_record_with_key<T>(&mut self, key_to_add: String, record: T)where
T: Base,
This method adds information to the database with a key as well.
§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record_with_key("mob".to_string(), "0404111222".to_string());
Sourcepub fn add_record_with_key_exclusive<T>(
&mut self,
key_to_add: String,
record: T,
) -> boolwhere
T: Base,
pub fn add_record_with_key_exclusive<T>(
&mut self,
key_to_add: String,
record: T,
) -> boolwhere
T: Base,
This method adds information to the database with a key as well. If the key already exists in the database, the information will not be added. The method returns true if successful, false, if they key exists already in the database.
§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record_with_key_exclusive("mob".to_string(), "0404111222".to_string());
Sourcepub fn add_record<T>(&mut self, record: T)where
T: Base,
pub fn add_record<T>(&mut self, record: T)where
T: Base,
This method adds information to the database.
§Examples
use simplebase::engine::*;
let mut loaded_database = load_hash_database("test1base.txt");
loaded_database.add_record("0404111222".to_string());
Sourcepub fn delete_record(&mut self, record_number: usize)
pub fn delete_record(&mut self, record_number: usize)
This method deletes a record based on the supplied record number. If the record does not exist, it does nothing.
§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.delete_record(1);
database.delete_record(1000000); //This will do nothing since the 1000000 record does not exist.
Sourcepub fn find(&self, what_to_find: &str) -> Vec<String>
pub fn find(&self, what_to_find: &str) -> Vec<String>
Searches the database for a particular term and returns the matching record in a String vector consisting of two values for each match 1) The record id 2) The contents of the matching record.
This method is available on read only databases (all methods work on writeable databases).
§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let found_records = loaded_database.find("great");
Sourcepub fn find_key(&self, what_to_find: &str) -> Vec<String>
pub fn find_key(&self, what_to_find: &str) -> Vec<String>
Searches the database key values (if a key value exists for a record- key values are optional) for a particular term and returns the matching record in a String vector consisting of two values for each match 1) The record id 2) The contents of the matching record. This method is available on read only databases (all methods work on writeable databases).
§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let found_records = loaded_database.find_key("great");
Sourcepub fn get_record(&self, record_number: usize) -> Option<String>
pub fn get_record(&self, record_number: usize) -> Option<String>
This method returns a record. It returns None if the record does not exist. This is also available if a database is opened using the load_hash_database_read_only method.
§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
let particular_record = loaded_database.get_record(1);
Sourcepub fn length(&self) -> usize
pub fn length(&self) -> usize
This function returns the number of records stored in the database
§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.length();
Sourcepub fn return_data_type(&self, record_number: usize) -> u8
pub fn return_data_type(&self, record_number: usize) -> u8
This function returns the data type (e.g String, u64, f64 etc) of a stored value. This is based on the DataType enum.
§Examples
use simplebase::engine::*;
let mut database = load_hash_database("test1base.txt");
database.return_data_type(1);
Sourcepub fn save_database(&self, filename: &str)
pub fn save_database(&self, filename: &str)
Saves a database hash table to a file. This will need to be run to save the database to a file. It is up to the user to impliment this action.
§Examples
use simplebase::engine::*;
let database = load_hash_database("test1base.txt");
database.save_database("test1base.txt");
Sourcepub fn save_database_every(&self, filename: &str, save_cycle: usize) -> bool
pub fn save_database_every(&self, filename: &str, save_cycle: usize) -> bool
Saves a database hash table to a file every ## cycles. This is useful in high intensity/write scenarios where you could have 1000s of saves a second. To increase performance you could use this function. The only drawback is that if the server goes down, you could potentially lose a small amount of data since the last save. Keep in mind that some form of save function will need to be run to save the database to a file. It is up to the user to impliment this action. This function returns false if the database is not saved, true if it is.
§Examples
use simplebase::engine::*;
let database = load_hash_database("test1base.txt");
database.save_database_every("test1base.txt", 10);
Sourcepub fn verify_record(&self, record_number: usize) -> bool
pub fn verify_record(&self, record_number: usize) -> bool
Calculates a simple chksum on the contents of a record and compares it to the stored chksum. This will return false if there is a mismatch. If the record does not exist, it will still return true.
§Examples
use simplebase::engine::*;
let mut database = new_empty_database();
database.add_record_with_key_exclusive("mob".to_string(), "0404111222".to_string());
let result = database.verify_record(1);
assert_eq!(true,result);
Sourcepub fn verify_database(&self) -> usize
pub fn verify_database(&self) -> usize
Checks the checksum in the database for each record. If it does not match, a message is printed stated which record has potentially being corrupted. It also returns the amount of corrupted records if there are any. If zero is returned this means that there are no corrupted records.
§Examples
use simplebase::engine::*;
let loaded_database = load_hash_database("test1base.txt");
loaded_database.verify_database();