Table

Trait Table 

Source
pub trait Table: Sized {
    // Required methods
    fn from_row(row: &Row<'_>) -> Result<Self>;
    fn get(db: &Connection) -> Result<CachedStatement<'_>, TableError>;
    fn extract(
        item: Result<Result<Self, Error>, Error>,
    ) -> Result<Self, TableError>;

    // Provided methods
    fn stream<F, E>(db: &Connection, callback: F) -> Result<(), TableError>
       where F: FnMut(Result<Self, TableError>) -> Result<(), E> { ... }
    fn get_blob<'a>(
        &self,
        db: &'a Connection,
        table: &str,
        column: &str,
        rowid: i64,
    ) -> Option<Blob<'a>> { ... }
    fn has_blob(
        &self,
        db: &Connection,
        table: &str,
        column: &str,
        rowid: i64,
    ) -> bool { ... }
}
Expand description

Defines behavior for SQL Table data

Required Methods§

Source

fn from_row(row: &Row<'_>) -> Result<Self>

Deserialize a single row into Self, returning a rusqlite::Result

Source

fn get(db: &Connection) -> Result<CachedStatement<'_>, TableError>

Prepare SELECT * statement

Source

fn extract(item: Result<Result<Self, Error>, Error>) -> Result<Self, TableError>

Map a rusqlite::Result<Self> into our TableError

Provided Methods§

Source

fn stream<F, E>(db: &Connection, callback: F) -> Result<(), TableError>
where F: FnMut(Result<Self, TableError>) -> Result<(), E>,

Process all rows from the table using a callback. This is the most memory-efficient approach for large tables.

Uses the default Table implementation to prepare the statement and query the rows.

To execute custom queries, see the message module docs for examples.

§Example
use imessage_database::{
   error::table::TableError,
   tables::{
       table::{get_connection, Table},
       handle::Handle,
   },
   util::dirs::default_db_path
};

// Get a connection to the database
let db_path = default_db_path();
let db = get_connection(&db_path).unwrap();

// Stream the Handle table, processing each row with a callback
Handle::stream(&db, |handle_result| {
    match handle_result {
        Ok(handle) => println!("Handle: {}", handle.id),
        Err(e) => eprintln!("Error: {:?}", e),
    }
    Ok::<(), TableError>(())
}).unwrap();
Source

fn get_blob<'a>( &self, db: &'a Connection, table: &str, column: &str, rowid: i64, ) -> Option<Blob<'a>>

Get a BLOB from the table

§Arguments
  • db - The database connection
  • table - The name of the table
  • column - The name of the column containing the BLOB
  • rowid - The row ID to retrieve the BLOB from
Source

fn has_blob( &self, db: &Connection, table: &str, column: &str, rowid: i64, ) -> bool

Check if a BLOB exists in the table

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§