pub trait Model:
Sized
+ Send
+ Sync
+ 'static {
// Required methods
fn table_name() -> &'static str;
fn columns() -> Vec<ColumnDef>;
fn to_row(&self) -> Result<Row>;
fn from_row(row: Row) -> Result<Self>;
fn pk_value(&self) -> Result<Value>;
// Provided method
fn primary_key() -> &'static str { ... }
}Expand description
Core trait that every ORM model must implement.
You should never implement this by hand. Apply #[derive(Model)] to
your struct and the macro generates all methods automatically from the
field types and #[rusticx(...)] attributes.
§Example
#[derive(Debug, Serialize, Deserialize, Model)]
#[rusticx(table = "orders")]
pub struct Order {
#[rusticx(primary_key)]
pub id: uuid::Uuid,
pub user_id: uuid::Uuid,
pub total: f64,
pub placed_at: chrono::DateTime<chrono::Utc>,
}Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Table name (SQL) or collection name (MongoDB).
Defaults to the struct name converted to snake_case and pluralised
(User → users). Override with #[rusticx(table = "my_table")].
Sourcefn columns() -> Vec<ColumnDef>
fn columns() -> Vec<ColumnDef>
Full column schema — used by migrate() to emit CREATE TABLE DDL.
Sourcefn to_row(&self) -> Result<Row>
fn to_row(&self) -> Result<Row>
Serialize all persisted fields into a flat Row map.
Called by Repository::insert and Repository::save before
handing data to the backend adapter.
Provided Methods§
Sourcefn primary_key() -> &'static str
fn primary_key() -> &'static str
Primary key column name (default: "id").
Override at struct level: #[rusticx(primary_key = "uuid")].
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".