pub trait Model:
Sized
+ Send
+ Sync
+ Unpin
+ 'static
+ for<'r> FromRow<'r, PgRow> {
type PrimaryKey: Type<Postgres> + for<'q> Encode<'q, Postgres> + Send + Sync + Clone + 'static;
const TABLE: &'static str;
const COLUMNS: &'static [&'static str];
const PK_COLUMN: &'static str = "id";
// Required method
fn primary_key(&self) -> &Self::PrimaryKey;
// Provided methods
fn query() -> QueryBuilder<Self> { ... }
fn find(
pool: &Pool<Postgres>,
id: Self::PrimaryKey,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>, Error>> + Send + '_>> { ... }
fn all(
pool: &Pool<Postgres>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self>, Error>> + Send + '_>> { ... }
}Required Associated Constants§
Provided Associated Constants§
Required Associated Types§
type PrimaryKey: Type<Postgres> + for<'q> Encode<'q, Postgres> + Send + Sync + Clone + 'static
Required Methods§
Sourcefn primary_key(&self) -> &Self::PrimaryKey
fn primary_key(&self) -> &Self::PrimaryKey
Return this row’s primary key.
Provided Methods§
Sourcefn query() -> QueryBuilder<Self>
fn query() -> QueryBuilder<Self>
Start a new query builder for this model.
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.