Solutions for doc tests
This commit is contained in:
parent
870ca3ffb0
commit
a22350914c
@ -57,25 +57,7 @@ where
|
|||||||
|
|
||||||
/// Enforces a set of constraints on any type performing an Create, Update or Delete operation.
|
/// Enforces a set of constraints on any type performing an Create, Update or Delete operation.
|
||||||
/// The type must also implement the [EntityTrait].
|
/// The type must also implement the [EntityTrait].
|
||||||
/// #### Example
|
/// See module level docs [crate::entity] for a full example
|
||||||
/// ```
|
|
||||||
/// use sea_orm::entity::prelude::*;
|
|
||||||
///
|
|
||||||
/// #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
|
||||||
/// pub struct Entity;
|
|
||||||
///
|
|
||||||
/// impl EntityName for Entity {
|
|
||||||
/// fn table_name(&self) -> &str {
|
|
||||||
/// "cake"
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// #[derive(Clone, Debug, PartialEq, DeriveActiveModel)]
|
|
||||||
/// pub struct Model {
|
|
||||||
/// pub id: i32,
|
|
||||||
/// pub name: Option<String>,
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ActiveModelTrait: Clone + Debug {
|
pub trait ActiveModelTrait: Clone + Debug {
|
||||||
/// Enforce the type to the constraints of the [EntityTrait]
|
/// Enforce the type to the constraints of the [EntityTrait]
|
||||||
@ -210,18 +192,30 @@ pub trait ActiveModelTrait: Clone + Debug {
|
|||||||
/// The type must also implement the [ActiveModelTrait]
|
/// The type must also implement the [ActiveModelTrait]
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```
|
/// ```ignore
|
||||||
/// use sea_orm::entity::prelude::*;
|
/// use sea_orm::entity::prelude::*;
|
||||||
///
|
///
|
||||||
/// /// Derive the active
|
/// // Use [DeriveEntity] to derive the EntityTrait automatically
|
||||||
|
/// #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||||
|
/// pub struct Entity;
|
||||||
|
///
|
||||||
|
/// /// The [EntityName] describes the name of a table
|
||||||
|
/// impl EntityName for Entity {
|
||||||
|
/// fn table_name(&self) -> &str {
|
||||||
|
/// "cake"
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// // Derive the ActiveModel
|
||||||
/// #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
/// #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
/// pub struct Model {
|
/// pub struct Model {
|
||||||
/// pub id: i32,
|
/// pub id: i32,
|
||||||
/// pub name: String,
|
/// pub name: String,
|
||||||
/// pub cake_id: Option<i32>,
|
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
///
|
||||||
/// impl ActiveModelBehavior for ActiveModel {}
|
/// impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
/// ```
|
||||||
|
/// See module level docs [crate::entity] for a full example
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
pub trait ActiveModelBehavior: ActiveModelTrait {
|
pub trait ActiveModelBehavior: ActiveModelTrait {
|
||||||
/// Create a new ActiveModel with default values. Also used by `Default::default()`.
|
/// Create a new ActiveModel with default values. Also used by `Default::default()`.
|
||||||
|
@ -1,125 +1,104 @@
|
|||||||
//! This modules contains types and traits for an Entity, ActiveMode, Model, PrimaryKey, ForeignKey and Relations.
|
/// This modules contains types and traits for an Entity, ActiveMode, Model, PrimaryKey, ForeignKey and Relations.
|
||||||
//!
|
///
|
||||||
//! // An Entity
|
/// // An Entity
|
||||||
//! A unit struct implements [EntityTrait](crate::EntityTrait) representing a table in the database.
|
/// A unit struct implements [EntityTrait](crate::EntityTrait) representing a table in the database.
|
||||||
//!
|
///
|
||||||
//! This trait contains the properties of an entity including
|
/// This trait contains the properties of an entity including
|
||||||
//!
|
///
|
||||||
//! Table Name (implemented EntityName)
|
/// - The Table Name which is implemented by [EntityName](crate::EntityName)
|
||||||
//! Column (implemented ColumnTrait)
|
/// - The Column which is implemented by [ColumnTrait](crate::ColumnTrait)
|
||||||
//! Relation (implemented RelationTrait)
|
/// - A Relation which is implemented by [RelationTrait](crate::RelationTrait)
|
||||||
//! Primary Key (implemented PrimaryKeyTrait and PrimaryKeyToColumn)
|
/// - The Primary Key which is implemented by [PrimaryKeyTrait](crate::PrimaryKeyTrait)
|
||||||
//!
|
/// and [PrimaryKeyToColumn](crate::PrimaryKeyToColumn)
|
||||||
//! This trait also provides an API for CRUD actions
|
///
|
||||||
//!
|
/// This trait also provides an API for CRUD actions
|
||||||
//! Select: find, find_*
|
///
|
||||||
//! Insert: insert, insert_*
|
/// #### Example for creating an Entity, Model and ActiveModel
|
||||||
//! Update: update, update_*
|
/// ```
|
||||||
//! Delete: delete, delete_*
|
/// #[cfg(feature = "macros")]
|
||||||
//!
|
///
|
||||||
//! #### Example for creating an Entity, Model and ActiveModel
|
/// # use crate::entity::prelude::*;
|
||||||
//! ```
|
/// # use sea_orm_macros::*;
|
||||||
//! use sea_orm::entity::prelude::*;
|
/// use sea_orm::ActiveModelBehavior;
|
||||||
//!
|
/// use sea_orm::RelationDef;
|
||||||
//! // Use [DeriveEntity] to derive the EntityTrait automatically
|
/// use sea_orm::RelationTrait;
|
||||||
//! #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
/// use sea_orm::ColumnType;
|
||||||
//! pub struct Entity;
|
/// use sea_orm::ColumnDef;
|
||||||
//!
|
/// use sea_orm::ColumnTrait;
|
||||||
//! /// The [EntityName] describes the name of a table
|
/// use sea_orm::PrimaryKeyTrait;
|
||||||
//! impl EntityName for Entity {
|
/// use sea_orm::EntityName;
|
||||||
//! fn table_name(&self) -> &str {
|
///
|
||||||
//! "cake"
|
/// // Use [DeriveEntity] to derive the EntityTrait automatically
|
||||||
//! }
|
/// #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||||
//! }
|
/// pub struct Entity;
|
||||||
//!
|
///
|
||||||
//! // Create a Model for the Entity through [DeriveModel].
|
/// /// The [EntityName] describes the name of a table
|
||||||
//! // The `Model` handles `READ` operations on a table in a database.
|
/// impl EntityName for Entity {
|
||||||
//! // The [DeriveActiveModel] creates a way to perform `CREATE` , `READ` and `UPDATE` operations
|
/// fn table_name(&self) -> &str {
|
||||||
//! // in a database
|
/// "filling"
|
||||||
//!
|
/// }
|
||||||
//! #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
/// }
|
||||||
//! pub struct Model {
|
///
|
||||||
//! pub id: i32,
|
/// // Create a Model for the Entity through [DeriveModel].
|
||||||
//! pub name: Option<String>,
|
/// // The `Model` handles `READ` operations on a table in a database.
|
||||||
//! }
|
/// // The [DeriveActiveModel] creates a way to perform `CREATE` , `READ` and `UPDATE` operations
|
||||||
//!
|
/// // in a database
|
||||||
//! // Use the [DeriveColumn] to create a Column for an the table called Entity
|
/// #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
|
||||||
//! // The [EnumIter] which creates a new type that iterates of the variants of a Column.
|
/// pub struct Model {
|
||||||
//! #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
/// pub id: i32,
|
||||||
//! pub enum Column {
|
/// pub name: String,
|
||||||
//! Id,
|
/// }
|
||||||
//! Name,
|
///
|
||||||
//! }
|
/// // Use the [DeriveColumn] to create a Column for an the table called Entity
|
||||||
//!
|
/// // The [EnumIter] which creates a new type that iterates of the variants of a Column.
|
||||||
//! // Create a PrimaryKey for the Entity using the [PrimaryKeyTrait]
|
/// #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||||
//! // The [EnumIter] which creates a new type that iterates of the variants of a PrimaryKey.
|
/// pub enum Column {
|
||||||
//! #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
/// Id,
|
||||||
//! pub enum PrimaryKey {
|
/// Name,
|
||||||
//! Id,
|
/// }
|
||||||
//! }
|
///
|
||||||
//!
|
/// // Create a PrimaryKey for the Entity using the [PrimaryKeyTrait]
|
||||||
//! // Or implement the [PrimaryKeyTrait] manually instead of using the macro [DerivePrimaryKey]
|
/// // The [EnumIter] which creates a new type that iterates of the variants of a PrimaryKey.
|
||||||
//! impl PrimaryKeyTrait for PrimaryKey {
|
/// #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||||
//! type ValueType = i32;
|
/// pub enum PrimaryKey {
|
||||||
//!
|
/// Id,
|
||||||
//! fn auto_increment() -> bool {
|
/// }
|
||||||
//! true
|
///
|
||||||
//! }
|
/// // Or implement the [PrimaryKeyTrait] manually instead of using the macro [DerivePrimaryKey]
|
||||||
//! }
|
/// impl PrimaryKeyTrait for PrimaryKey {
|
||||||
//!
|
/// type ValueType = i32;
|
||||||
//! // Create a Relation for the Entity
|
///
|
||||||
//! #[derive(Copy, Clone, Debug, EnumIter)]
|
/// fn auto_increment() -> bool {
|
||||||
//! #[sea_orm(
|
/// true
|
||||||
//! // The relation belongs to `Entity` type
|
/// }
|
||||||
//! belongs_to = "Entity",
|
/// }
|
||||||
//! from = "Column::FruitId",
|
///
|
||||||
//! to = "Column::Id"
|
///
|
||||||
//! )]
|
/// #[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
//! pub enum Relation {
|
/// pub enum Relation {}
|
||||||
//! Fruit,
|
///
|
||||||
//! }
|
/// impl ColumnTrait for Column {
|
||||||
//!
|
/// type EntityName = Entity;
|
||||||
//! // Create the properties of a Column in an Entity ensuring that calling
|
///
|
||||||
//! // Column::def() yields a Column definition as defined in [ColumnDef]
|
/// fn def(&self) -> ColumnDef {
|
||||||
//! impl ColumnTrait for Column {
|
/// match self {
|
||||||
//! type EntityName = Entity;
|
/// Self::Id => ColumnType::Integer.def(),
|
||||||
//! fn def(&self) -> ColumnDef {
|
/// Self::Name => ColumnType::String(None).def(),
|
||||||
//! match self {
|
/// }
|
||||||
//! Self::Id => ColumnType::Integer.def(),
|
/// }
|
||||||
//! Self::Name => ColumnType::Text.def().null(),
|
/// }
|
||||||
//! }
|
///
|
||||||
//! }
|
/// // Create a Relation for the Entity
|
||||||
//! }
|
/// impl RelationTrait for Relation {
|
||||||
//!
|
/// fn def(&self) -> RelationDef {
|
||||||
//! // Implement the set of constraints for creating a Relation as defined in the [RelationTrait]
|
/// panic!()
|
||||||
//! impl RelationTrait for Relation {
|
/// }
|
||||||
//! fn def(&self) -> RelationDef {
|
/// }
|
||||||
//! match self {
|
/// // Implement user defined operations for CREATE, UPDATE and DELETE operations
|
||||||
//! Self::Fruit => Entity::has_many(super::fruit::Entity).into(),
|
/// // to create an ActiveModel using the [ActiveModelBehavior]
|
||||||
//! }
|
/// impl ActiveModelBehavior for ActiveModel {}
|
||||||
//! }
|
///
|
||||||
//! }
|
/// ```
|
||||||
//!
|
|
||||||
//! impl Related<fruit::Entity> for Entity {
|
|
||||||
//! fn to() -> RelationDef {
|
|
||||||
//! Relation::Fruit.def()
|
|
||||||
//! }
|
|
||||||
//! }
|
|
||||||
//!
|
|
||||||
//! impl Related<super::filling::Entity> for Entity {
|
|
||||||
//! fn to() -> RelationDef {
|
|
||||||
//! super::cake_filling::Relation::Filling.def()
|
|
||||||
//! }
|
|
||||||
//! fn via() -> Option<RelationDef> {
|
|
||||||
//! Some(super::cake_filling::Relation::Cake.def().rev())
|
|
||||||
//! }
|
|
||||||
//! }
|
|
||||||
//!
|
|
||||||
//! // Implement user defined operations for CREATE, UPDATE and DELETE operations
|
|
||||||
//! // to create an ActiveModel using the [ActiveModelBehavior]
|
|
||||||
//! impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
//! ```
|
|
||||||
|
|
||||||
mod active_model;
|
mod active_model;
|
||||||
mod base_entity;
|
mod base_entity;
|
||||||
mod column;
|
mod column;
|
||||||
|
@ -9,7 +9,7 @@ use std::fmt::Debug;
|
|||||||
/// A primary key can be derived manually
|
/// A primary key can be derived manually
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```
|
/// ```text
|
||||||
/// use sea_orm::entity::prelude::*;
|
/// use sea_orm::entity::prelude::*;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy, Clone, Debug, EnumIter)]
|
/// #[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
@ -28,7 +28,7 @@ use std::fmt::Debug;
|
|||||||
/// Alternatively, use derive macros to automatically implement the trait for a Primary Key
|
/// Alternatively, use derive macros to automatically implement the trait for a Primary Key
|
||||||
///
|
///
|
||||||
/// ### Example
|
/// ### Example
|
||||||
/// ```
|
/// ```text
|
||||||
/// use sea_orm::entity::prelude::*;
|
/// use sea_orm::entity::prelude::*;
|
||||||
///
|
///
|
||||||
/// #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
/// #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||||
@ -36,6 +36,7 @@ use std::fmt::Debug;
|
|||||||
/// Id,
|
/// Id,
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// See module level docs [crate::entity] for a full example
|
||||||
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
pub trait PrimaryKeyTrait: IdenStatic + Iterable {
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
type ValueType: Sized
|
type ValueType: Sized
|
||||||
|
Loading…
x
Reference in New Issue
Block a user