Struct PhysicalDB

Source
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

Source

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.

Source

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.

Source

pub fn open(&mut self) -> Result<(), TSLiteError>

Open the database file in read and write mode.

Source

pub fn close(&mut self) -> Result<(), TSLiteError>

Drop the database file to close it. Make sure to sync all IO operation before closing it.

Source

pub fn read_header(&mut self) -> Result<DbHeader, TSLiteError>

Read the header from the file. Does not update the header in memory.

Source

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)

Source

pub fn update_record_number(&mut self, drn: u64) -> Result<(), TSLiteError>

This utility function will update the number of record in the database.

Source

pub fn append_record(&mut self, rec_nfo: RecordInfo) -> Result<(), TSLiteError>

Add a record in the database.

Source

pub fn append_record_now(&mut self, value: u8) -> Result<(), TSLiteError>

Append a record with the current time.

Source

pub fn update_record( &mut self, rec_id: u64, value: u8, ) -> Result<(), TSLiteError>

Change the value of a record within the database.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for PhysicalDB

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.