Readme
This commit is contained in:
parent
beb3ec62dc
commit
33f0cfaa77
25
README.md
25
README.md
@ -139,6 +139,31 @@ async fn list(
|
||||
|
||||
## A quick taste of SeaORM
|
||||
|
||||
### Entity
|
||||
```rust
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "cake")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::fruit::Entity")]
|
||||
Fruit,
|
||||
}
|
||||
|
||||
impl Related<super::fruit::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Fruit.def()
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Select
|
||||
```rust
|
||||
// find all models
|
||||
|
57
src/lib.rs
57
src/lib.rs
@ -203,6 +203,63 @@
|
||||
//!
|
||||
//! ## A quick taste of SeaORM
|
||||
//!
|
||||
//! ### Entity
|
||||
//! ```
|
||||
//! # #[cfg(feature = "macros")]
|
||||
//! # mod entities {
|
||||
//! # mod fruit {
|
||||
//! # use sea_orm::entity::prelude::*;
|
||||
//! # #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
//! # #[sea_orm(table_name = "fruit")]
|
||||
//! # pub struct Model {
|
||||
//! # #[sea_orm(primary_key)]
|
||||
//! # pub id: i32,
|
||||
//! # pub name: String,
|
||||
//! # pub cake_id: Option<i32>,
|
||||
//! # }
|
||||
//! # #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
//! # pub enum Relation {
|
||||
//! # #[sea_orm(
|
||||
//! # belongs_to = "super::cake::Entity",
|
||||
//! # from = "Column::CakeId",
|
||||
//! # to = "super::cake::Column::Id"
|
||||
//! # )]
|
||||
//! # Cake,
|
||||
//! # }
|
||||
//! # impl Related<super::cake::Entity> for Entity {
|
||||
//! # fn to() -> RelationDef {
|
||||
//! # Relation::Cake.def()
|
||||
//! # }
|
||||
//! # }
|
||||
//! # impl ActiveModelBehavior for ActiveModel {}
|
||||
//! # }
|
||||
//! # mod cake {
|
||||
//! use sea_orm::entity::prelude::*;
|
||||
//!
|
||||
//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||
//! #[sea_orm(table_name = "cake")]
|
||||
//! pub struct Model {
|
||||
//! #[sea_orm(primary_key)]
|
||||
//! pub id: i32,
|
||||
//! pub name: String,
|
||||
//! }
|
||||
//!
|
||||
//! #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
//! pub enum Relation {
|
||||
//! #[sea_orm(has_many = "super::fruit::Entity")]
|
||||
//! Fruit,
|
||||
//! }
|
||||
//!
|
||||
//! impl Related<super::fruit::Entity> for Entity {
|
||||
//! fn to() -> RelationDef {
|
||||
//! Relation::Fruit.def()
|
||||
//! }
|
||||
//! }
|
||||
//! # impl ActiveModelBehavior for ActiveModel {}
|
||||
//! # }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! ### Select
|
||||
//! ```
|
||||
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};
|
||||
|
Loading…
x
Reference in New Issue
Block a user