pub trait Table {
// Required methods
fn columns() -> usize;
fn from_row_postgres(row: PostgreRow) -> Result<Self, Error>
where Self: Sized;
fn from_row_sqlite<'__table_row>(
row: &'__table_row SQLiteRow<'__table_row>,
) -> Result<Self, Error>
where Self: Sized;
// Provided method
fn from_row(row: Row<'_>) -> Result<Self, Error>
where Self: Sized { ... }
}Expand description
The trait allows for the conversion of a resulting query’s rows into the given implemented type.
§Examples
#[derive(db_derive::Table)]
struct Tag {
#[table(rename = "Id")]
id: String,
#[table(rename = "Name")]
name: String,
}
#[derive(db_derive::Query)]
#[query(sql = "SELECT Id, Name FROM Tag WHERE Id = $id;")]
struct GetTagById<'a> {
id: &'a str,
}
fn main() -> Result<(), db_derive::Error> {
let pool = Pool::sqlite("example.db")?;
let get = GetTagById { id: "example" };
let tag = get.query_row::<_, Tag>(&pool)?;
println!("Tag Name: {}", tag.name);
Ok(())
}Required Methods§
fn columns() -> usize
Sourcefn from_row_postgres(row: PostgreRow) -> Result<Self, Error>where
Self: Sized,
fn from_row_postgres(row: PostgreRow) -> Result<Self, Error>where
Self: Sized,
Provided Methods§
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.