Skip to main content

TableRegistry

Struct TableRegistry 

Source
pub struct TableRegistry { /* private fields */ }
Expand description

The table registry takes care of storing the records for each table, using the [FreeSegmentsLedger] and [PageLedger] to derive exactly where to read/write.

A registry is generic over a record, which must implement Encode.

The CRUD operations provided by the table registry do NOT perform any logical checks, but just allow to read/write records from/to memory. So CRUD checks must be performed by a higher layer, prior to calling these methods.

Implementations§

Source§

impl TableRegistry

Source

pub fn load( table_pages: TableRegistryPage, mm: &mut impl MemoryAccess, ) -> MemoryResult<Self>

Loads the table registry from memory.

Source

pub fn insert<E>( &mut self, record: E, mm: &mut impl MemoryAccess, ) -> MemoryResult<RecordAddress>
where E: Encode,

Inserts a new record into the table registry.

Returns the address where the record was inserted, which can be used to read it back or to update/delete it.

NOTE: this function does NOT make any logical checks on the record being inserted.

Source

pub fn read<'a, E, MA>(&'a self, mm: &'a mut MA) -> TableReader<'a, E, MA>
where E: Encode, MA: MemoryAccess,

Creates a TableReader to read records from the table registry.

Use TableReader::try_next to read records one by one.

Source

pub fn read_at<E, MA>( &self, address: RecordAddress, mm: &mut MA, ) -> MemoryResult<E>
where E: Encode, MA: MemoryAccess,

Reads a single record at the given address.

Source

pub fn delete( &mut self, record: impl Encode, address: RecordAddress, mm: &mut impl MemoryAccess, ) -> MemoryResult<()>

Deletes a record at the given page and offset.

The space occupied by the record is marked as free and zeroed.

Source

pub fn update( &mut self, new_record: impl Encode, old_record: impl Encode, old_address: RecordAddress, mm: &mut impl MemoryAccess, ) -> MemoryResult<RecordAddress>

Updates a record at the given page and offset.

The RecordAddress of the new record is returned, which can be different from the old one if the record was reallocated.

The logic is the following:

  1. If the new record has exactly the same size of the old record, overwrite it in place.
  2. If the new record does not fit, delete the old record and insert the new record.
Source

pub fn index_ledger(&self) -> &IndexLedger

Get a reference to the index ledger, allowing to read the indexes.

Source

pub fn index_ledger_mut(&mut self) -> &mut IndexLedger

Get a mutable reference to the index ledger, allowing to modify the indexes.

Source

pub fn next_autoincrement( &mut self, column_name: &str, mm: &mut impl MemoryAccess, ) -> MemoryResult<Option<Value>>

Get next value for an autoincrement column of the given type, and increment it in the ledger.

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.