pub struct PhysicalDB {
pub path: PathBuf,
pub file: Option<File>,
pub header: DbHeader,
}
Expand description
a DB in file
Fields§
§path: PathBuf
§file: Option<File>
§header: DbHeader
Implementations§
Source§impl PhysicalDB
impl PhysicalDB
Sourcepub fn new(
path: &Path,
origin_date: Option<DateTime<Utc>>,
) -> Result<PhysicalDB, TSLiteError>
pub fn new( path: &Path, origin_date: Option<DateTime<Utc>>, ) -> Result<PhysicalDB, TSLiteError>
This function will create a new database file or open it if it already exists.
The second argument the date with which to initialize the database. It is optional, if you give None
it will use the current date and time. If the file exists, the date is ignored complitely.
Sourcepub fn create(
path: &Path,
origin_date: Option<DateTime<Utc>>,
) -> Result<PhysicalDB, TSLiteError>
pub fn create( path: &Path, origin_date: Option<DateTime<Utc>>, ) -> Result<PhysicalDB, TSLiteError>
This function will create a new database file.
Warning: It will not check if there is already a file at path
, if there is one, it will be overwritten.
The second argument the date with which to initialize the database. It is optional, if you give None
it will use the current date and time.
Sourcepub fn open(&mut self) -> Result<(), TSLiteError>
pub fn open(&mut self) -> Result<(), TSLiteError>
Open the database file in read and write mode.
Sourcepub fn close(&mut self) -> Result<(), TSLiteError>
pub fn close(&mut self) -> Result<(), TSLiteError>
Drop the database file to close it. Make sure to sync all IO operation before closing it.
Sourcepub fn read_header(&mut self) -> Result<DbHeader, TSLiteError>
pub fn read_header(&mut self) -> Result<DbHeader, TSLiteError>
Read the header from the file. Does not update the header in memory.
Sourcepub fn read_record(&mut self, rec_id: u64) -> Result<RecordInfo, TSLiteError>
pub fn read_record(&mut self, rec_id: u64) -> Result<RecordInfo, TSLiteError>
The size of the header and record are static.
So the position of each record is deterministic.
If n
is the record id, then its position within the file can be computed with :
pos(n) = (7 + 8) + (5*n)
Sourcepub fn update_record_number(&mut self, drn: u64) -> Result<(), TSLiteError>
pub fn update_record_number(&mut self, drn: u64) -> Result<(), TSLiteError>
This utility function will update the number of record in the database.
Sourcepub fn append_record(&mut self, rec_nfo: RecordInfo) -> Result<(), TSLiteError>
pub fn append_record(&mut self, rec_nfo: RecordInfo) -> Result<(), TSLiteError>
Add a record in the database.
Sourcepub fn append_record_now(&mut self, value: u8) -> Result<(), TSLiteError>
pub fn append_record_now(&mut self, value: u8) -> Result<(), TSLiteError>
Append a record with the current time.
Sourcepub fn update_record(
&mut self,
rec_id: u64,
value: u8,
) -> Result<(), TSLiteError>
pub fn update_record( &mut self, rec_id: u64, value: u8, ) -> Result<(), TSLiteError>
Change the value of a record within the database.
Sourcepub fn check_db_file(&mut self) -> Result<DbIssue, TSLiteError>
pub fn check_db_file(&mut self) -> Result<DbIssue, TSLiteError>
Perform check to find any issue in the database file.
It will return the first issue it find. You might need to run this function
until it return DbIssue::None
to check for all possible issue.
Sourcepub fn reorder_record(&mut self) -> Result<(), TSLiteError>
pub fn reorder_record(&mut self) -> Result<(), TSLiteError>
Reorder the record in the DB. Use if your DB records got scrambled for some reason. Right now it use a simple way :
- Read all the record
- reorder them in-memory
- dump all the record in the DB It means that if you have just one record wrong you end up re-writing the whole DB.