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§
Sourcefn from_row(row: &Row<'_>) -> Result<Self>
fn from_row(row: &Row<'_>) -> Result<Self>
Deserialize a single row into Self, returning a rusqlite::Result
Sourcefn get(db: &Connection) -> Result<CachedStatement<'_>, TableError>
fn get(db: &Connection) -> Result<CachedStatement<'_>, TableError>
Prepare SELECT * statement
Provided Methods§
Sourcefn stream<F, E>(db: &Connection, callback: F) -> Result<(), TableError>
fn stream<F, E>(db: &Connection, callback: F) -> Result<(), TableError>
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();
Sourcefn get_blob<'a>(
&self,
db: &'a Connection,
table: &str,
column: &str,
rowid: i64,
) -> Option<Blob<'a>>
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 connectiontable
- The name of the tablecolumn
- The name of the column containing the BLOBrowid
- The row ID to retrieve the BLOB from
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.