Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<S: Source> { /* private fields */ }
Expand description

A SQLite database file, opened for reading.

Implementations§

Source§

impl<S: Source> Reader<S>

Source

pub fn survey_table(&self, object: &SchemaObject) -> Result<TableSurvey>

Read every row of a table and report what each column holds.

This is the first of the import’s two passes: it writes nothing and its whole purpose is to let the second pass know the shape of what it is about to write, and to let a caller see every problem at once rather than the first one after ten minutes of work.

Source§

impl<S: Source> Reader<S>

Source

pub fn open(source: S) -> Result<Reader<S>>

Read and validate the header, then work out how many pages the file really has.

Source

pub fn header(&self) -> &Header

Source

pub fn page_count(&self) -> u32

Pages in the database. Page numbers run from 1 to this value.

Source

pub fn read_page(&self, number: u32) -> Result<Vec<u8>>

Read one whole page, reserved trailer included.

Source

pub fn btree_page(&self, number: u32) -> Result<BtreePage>

Read a page and parse it as a b-tree page.

Source

pub fn cell(&self, page: &BtreePage, index: usize) -> Result<Cell>

Parse one cell of a b-tree page, following overflow pages so the payload comes back whole.

Source

pub fn schema(&self) -> Result<Schema>

Read the database’s own description of itself.

The schema lives in a table rooted at page 1, so this is an ordinary scan; it is separate only because everything else in the file is found through it.

Source

pub fn table_scan(&self, root: u32) -> Result<TableScan<'_, S>>

Walk the table b-tree rooted at root, yielding rows in rowid order.

The walk is lazy: a table larger than memory is read a page at a time, and a caller that only wants the first row only pays for the pages down to it.

Source

pub fn index_scan(&self, root: u32) -> Result<IndexScan<'_, S>>

Walk the index b-tree rooted at root, yielding entries in key order.

This reads real indexes and, because a without rowid table is an index b-tree holding whole rows, those tables too.

Source

pub fn decode_record(&self, payload: &[u8]) -> Result<Vec<SqliteValue>>

Decode a record with the encoding this database uses.

The same as the free function, minus the chance of passing the wrong encoding: this one reads it off the header in hand.

Source

pub fn rows(&self, root: u32) -> Result<Rows<'_, S>>

Rows of a table, whichever kind of table it is.

Which walk applies is not a matter of taste: a rowid table is a table b-tree and a without rowid table is an index b-tree, and the root page says which one it is. Reading that off the page rather than off the create statement means this works before any sql has been parsed, and cannot disagree with the file.

Auto Trait Implementations§

§

impl<S> Freeze for Reader<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Reader<S>
where S: RefUnwindSafe,

§

impl<S> Send for Reader<S>
where S: Send,

§

impl<S> Sync for Reader<S>
where S: Sync,

§

impl<S> Unpin for Reader<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Reader<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Reader<S>
where S: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.