sea_orm/entity/
mod.rs

1/// This modules contains types and traits for an  Entity, ActiveMode, Model, PrimaryKey, ForeignKey and Relations.
2///
3/// // An Entity
4/// A unit struct implements [EntityTrait](crate::EntityTrait) representing a table in the database.
5///
6/// This trait contains the properties of an entity including
7///
8/// - The Table Name which is implemented by [EntityName](crate::EntityName)
9/// - The Column which is implemented by [ColumnTrait](crate::ColumnTrait)
10/// - A Relation which is implemented by [RelationTrait](crate::RelationTrait)
11/// - The Primary Key which is implemented by [PrimaryKeyTrait](crate::PrimaryKeyTrait)
12///   and [PrimaryKeyToColumn](crate::PrimaryKeyToColumn)
13///
14/// This trait also provides an API for CRUD actions
15///
16/// #### Example for creating an Entity, Model and ActiveModel
17/// ```
18/// #[cfg(feature = "macros")]
19/// # use sea_orm::entity::prelude::*;
20/// use sea_orm::ActiveModelBehavior;
21/// use sea_orm::ColumnDef;
22/// use sea_orm::ColumnTrait;
23/// use sea_orm::ColumnType;
24/// use sea_orm::EntityName;
25/// use sea_orm::PrimaryKeyTrait;
26/// use sea_orm::RelationDef;
27/// use sea_orm::RelationTrait;
28///
29/// // Use [DeriveEntity] to derive the EntityTrait automatically
30/// #[derive(Copy, Clone, Default, Debug, DeriveEntity)]
31/// pub struct Entity;
32///
33/// /// The [EntityName] describes the name of a table
34/// impl EntityName for Entity {
35///     fn table_name(&self) -> &str {
36///         "filling"
37///     }
38/// }
39///
40/// // Create a Model for the Entity through [DeriveModel].
41/// // The `Model` handles `READ` operations on a table in a database.
42/// // The [DeriveActiveModel] creates a way to perform `CREATE` , `READ` and `UPDATE` operations
43/// // in a database
44/// #[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel)]
45/// pub struct Model {
46///     pub id: i32,
47///     pub name: String,
48/// }
49///
50/// // Use the [DeriveColumn] to create a Column for an the table called Entity
51/// // The [EnumIter] which creates a new type that iterates of the variants of a Column.
52/// #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
53/// pub enum Column {
54///     Id,
55///     Name,
56/// }
57///
58/// // Create a PrimaryKey for the Entity using the [PrimaryKeyTrait]
59/// // The [EnumIter] which creates a new type that iterates of the variants of a PrimaryKey.
60/// #[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
61/// pub enum PrimaryKey {
62///     Id,
63/// }
64///
65/// // Or implement the [PrimaryKeyTrait] manually instead of using the macro [DerivePrimaryKey]
66/// impl PrimaryKeyTrait for PrimaryKey {
67///     type ValueType = i32;
68///
69///     fn auto_increment() -> bool {
70///         true
71///     }
72/// }
73///
74/// #[derive(Copy, Clone, Debug, EnumIter)]
75/// pub enum Relation {}
76///
77/// impl ColumnTrait for Column {
78///     type EntityName = Entity;
79///
80///     fn def(&self) -> ColumnDef {
81///         match self {
82///             Self::Id => ColumnType::Integer.def(),
83///             Self::Name => ColumnType::String(StringLen::None).def(),
84///         }
85///     }
86/// }
87///
88/// // Create a Relation for the Entity
89/// impl RelationTrait for Relation {
90///     fn def(&self) -> RelationDef {
91///         unimplemented!()
92///     }
93/// }
94///
95/// // Implement user defined operations for CREATE, UPDATE and DELETE operations
96/// // to create an ActiveModel using the [ActiveModelBehavior]
97/// impl ActiveModelBehavior for ActiveModel {}
98/// ```
99mod active_enum;
100mod active_model;
101mod base_entity;
102mod column;
103mod identity;
104mod link;
105mod model;
106mod partial_model;
107/// Re-export common types from the entity
108pub mod prelude;
109mod primary_key;
110mod relation;
111
112pub use active_enum::*;
113pub use active_model::*;
114pub use base_entity::*;
115pub use column::*;
116pub use identity::*;
117pub use link::*;
118pub use model::*;
119pub use partial_model::*;
120// pub use prelude::*;
121pub use primary_key::*;
122pub use relation::*;