[][src]Struct tslite::PhysicalDB

pub struct PhysicalDB {
    pub path: PathBuf,
    pub file: Option<File>,
    pub header: DbHeader,
}

a DB in file

Fields

path: PathBuffile: Option<File>header: DbHeader

Implementations

impl PhysicalDB[src]

pub fn new(
    path: &Path,
    origin_date: Option<DateTime<Utc>>
) -> Result<PhysicalDB, TSLiteError>
[src]

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.

pub fn create(
    path: &Path,
    origin_date: Option<DateTime<Utc>>
) -> Result<PhysicalDB, TSLiteError>
[src]

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.

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

Open the database file in read and write mode.

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

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

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

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

pub fn read_record(&mut self, rec_id: u64) -> Result<RecordInfo, TSLiteError>[src]

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)

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

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

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

Add a record in the database.

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

Append a record with the current time.

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

Change the value of a record within the database.

pub fn check_db_file(&mut self) -> Result<DbIssue, TSLiteError>[src]

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.

pub fn reorder_record(&mut self) -> Result<(), TSLiteError>[src]

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

impl Debug for PhysicalDB[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.