Skip to main content

FromQuery

Trait FromQuery 

Source
pub trait FromQuery: Sized {
    type Based: AsTable;

    // Required methods
    fn select_sql() -> String;
    fn from_row(row: &Row<'_>) -> Result<Self, Error>;
}
Available on crate feature utils only.
Expand description

Trait for types that can be deserialized from a SQL row.

Implement this trait to make a type queryable as a generic parameter of Query::query(). Typically implemented via #[derive] macros or manually on entity structs (e.g. Post, Author).

§Associated types

  • Based: the corresponding database table type, must implement AsTable.

Required Associated Types§

Required Methods§

Source

fn select_sql() -> String

Returns the SELECT … SQL fragment used to query this type (without WHERE/ORDER/LIMIT).

Source

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

Deserializes one instance of this type from a rusqlite Row.

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§