Skip to main content

ModelSchema

Trait ModelSchema 

Source
pub trait ModelSchema: Model {
    // Provided method
    fn table_schema() -> TableInfo { ... }
}
Expand description

Extension trait that adds schema extraction to Model types.

This trait is automatically implemented for all types that implement Model. It provides the table_schema() method to extract the expected table schema from the Model’s metadata.

§Example

use sqlmodel::Model;
use sqlmodel_schema::expected::ModelSchema;

#[derive(Model)]
#[sqlmodel(table = "heroes")]
struct Hero {
    #[sqlmodel(primary_key, auto_increment)]
    id: Option<i64>,
    name: String,
}

// Extract the expected schema
let schema = Hero::table_schema();
assert_eq!(schema.name, "heroes");

Provided Methods§

Source

fn table_schema() -> TableInfo

Get the expected table schema 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.

Implementors§

Source§

impl<M: Model> ModelSchema for M