orbit_orm/model.rs
1use crate::Query;
2use crate::driver::rows::DriverRows;
3
4/// A table and the Rust type that its rows map to. Derive it with `#[derive(OrbitModel)]`, or write it by hand.
5///
6/// A model decodes from the row type of every database that the build enables, so `DriverRows`
7/// holds for it. With only one database enabled, that is the one `FromRow` for that database.
8pub trait Model: DriverRows + Send + Unpin + Sized {
9 /// The table name.
10 const TABLE: &'static str;
11
12 /// The primary key, used by `find`. `first` has no default order, as in Laravel.
13 const PRIMARY_KEY: &'static str = "id";
14
15 /// The columns that `insert` and `update` may write. Empty by default, as in Laravel's `$fillable`.
16 const FILLABLE: &'static [&'static str] = &[];
17
18 /// Starts a query on the table.
19 fn query() -> Query<Self> {
20 Query::table()
21 }
22}