Cont. Added support for using sea-orm with #[deny(missing_docs)] (#1531)
* Added support for using sea-orm with #[deny(missing_docs)] (#1522) * feat(macros): Added documentation tags for generated entities * chore: Added deny(missing_docs) attribute to basic example * chore: Fix clippy errors * ci: test missing docs of derive macros generated types * Try missing docs (CI should fail) * Revert "Try missing docs (CI should fail)" This reverts commit 83356bfca8939e7807f14bad8bb816fcabc1bf7b. --------- Co-authored-by: Lewin Probst, M.Sc <30552361+emirror-de@users.noreply.github.com>
This commit is contained in:
parent
27e061c99e
commit
4f8ad56cc4
@ -1,15 +1,22 @@
|
||||
//! The `cake` entity.
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
/// Cake entity
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
|
||||
#[sea_orm(table_name = "cake")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
/// id field
|
||||
pub id: i32,
|
||||
/// name field
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Cake relation
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
/// Fruit relation
|
||||
Fruit,
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! The `cake_filling` entity.
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
/// CakeFilling entity
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
@ -9,21 +12,30 @@ impl EntityName for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
/// CakeFilling model
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
|
||||
pub struct Model {
|
||||
/// cake_id field
|
||||
pub cake_id: i32,
|
||||
/// filling_id field
|
||||
pub filling_id: i32,
|
||||
}
|
||||
|
||||
/// CakeFilling column
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
pub enum Column {
|
||||
/// CakeId column
|
||||
CakeId,
|
||||
/// FillingId column
|
||||
FillingId,
|
||||
}
|
||||
|
||||
/// CakeFilling primary key
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
/// CakeId primary key
|
||||
CakeId,
|
||||
/// FillingId primary key
|
||||
FillingId,
|
||||
}
|
||||
|
||||
@ -35,9 +47,12 @@ impl PrimaryKeyTrait for PrimaryKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// CakeFilling relation
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
/// Cake relation
|
||||
Cake,
|
||||
/// Filling relation
|
||||
Filling,
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! The `filling` entity.
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
/// Filling entity
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
@ -9,20 +12,28 @@ impl EntityName for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
/// Filling model
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
|
||||
pub struct Model {
|
||||
/// id field
|
||||
pub id: i32,
|
||||
/// name field
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// Filling column
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
pub enum Column {
|
||||
/// Id column
|
||||
Id,
|
||||
/// Name column
|
||||
Name,
|
||||
}
|
||||
|
||||
/// Filling primary key
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
/// Id primary key
|
||||
Id,
|
||||
}
|
||||
|
||||
@ -34,6 +45,7 @@ impl PrimaryKeyTrait for PrimaryKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// Filling relation
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
//! The `fruit` entity.
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
/// Fruit entity
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
@ -9,22 +12,32 @@ impl EntityName for Entity {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fruit model
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
|
||||
pub struct Model {
|
||||
/// id field
|
||||
pub id: i32,
|
||||
/// name field
|
||||
pub name: String,
|
||||
/// cake_id field
|
||||
pub cake_id: Option<i32>,
|
||||
}
|
||||
|
||||
/// Fruit column
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
|
||||
pub enum Column {
|
||||
/// Id column
|
||||
Id,
|
||||
/// Name column
|
||||
Name,
|
||||
/// CakeId column
|
||||
CakeId,
|
||||
}
|
||||
|
||||
/// Fruit primary key
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
/// Id primary key
|
||||
Id,
|
||||
}
|
||||
|
||||
@ -36,8 +49,10 @@ impl PrimaryKeyTrait for PrimaryKey {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fruit relation
|
||||
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||
pub enum Relation {
|
||||
/// Cake relation
|
||||
Cake,
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,16 @@
|
||||
//! Basic sea-orm example.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
use sea_orm::Database;
|
||||
|
||||
mod entities;
|
||||
mod example_cake;
|
||||
mod example_cake_filling;
|
||||
mod example_filling;
|
||||
mod example_fruit;
|
||||
pub mod example_cake;
|
||||
pub mod example_cake_filling;
|
||||
pub mod example_filling;
|
||||
pub mod example_fruit;
|
||||
mod operation;
|
||||
pub mod sea_orm_active_enums;
|
||||
mod select;
|
||||
|
||||
use entities::*;
|
||||
|
15
examples/basic/src/sea_orm_active_enums.rs
Normal file
15
examples/basic/src/sea_orm_active_enums.rs
Normal file
@ -0,0 +1,15 @@
|
||||
//! SeaORM's active enums.
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
/// Tea active enum
|
||||
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
|
||||
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]
|
||||
pub enum Tea {
|
||||
/// EverydayTea variant
|
||||
#[sea_orm(string_value = "EverydayTea")]
|
||||
EverydayTea,
|
||||
/// BreakfastTea variant
|
||||
#[sea_orm(string_value = "BreakfastTea")]
|
||||
BreakfastTea,
|
||||
}
|
@ -256,9 +256,11 @@ impl ActiveEnum {
|
||||
.collect();
|
||||
|
||||
quote!(
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, sea_orm::EnumIter)]
|
||||
pub enum #enum_variant_iden {
|
||||
#(
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#enum_variants,
|
||||
)*
|
||||
}
|
||||
@ -276,6 +278,7 @@ impl ActiveEnum {
|
||||
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
pub fn iden_values() -> Vec<sea_orm::sea_query::DynIden> {
|
||||
<#enum_variant_iden as sea_orm::strum::IntoEnumIterator>::iter()
|
||||
.map(|v| sea_orm::sea_query::SeaRc::new(v) as sea_orm::sea_query::DynIden)
|
||||
@ -297,6 +300,7 @@ impl ActiveEnum {
|
||||
};
|
||||
|
||||
quote!(
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct #enum_name_iden;
|
||||
|
||||
|
@ -38,11 +38,10 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
|
||||
fn derive_active_model(all_fields: IntoIter<Field>) -> syn::Result<TokenStream> {
|
||||
let fields = all_fields.filter(field_not_ignored);
|
||||
|
||||
let field: Vec<Ident> = fields.clone().into_iter().map(format_field_ident).collect();
|
||||
let field: Vec<Ident> = fields.clone().map(format_field_ident).collect();
|
||||
|
||||
let name: Vec<Ident> = fields
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|field| {
|
||||
let ident = field.ident.as_ref().unwrap().to_string();
|
||||
let ident = trim_starting_raw_identifier(ident).to_camel_case();
|
||||
@ -78,9 +77,14 @@ fn derive_active_model(all_fields: IntoIter<Field>) -> syn::Result<TokenStream>
|
||||
let ty: Vec<Type> = fields.into_iter().map(|Field { ty, .. }| ty).collect();
|
||||
|
||||
Ok(quote!(
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ActiveModel {
|
||||
#(pub #field: sea_orm::ActiveValue<#ty>),*
|
||||
|
||||
#(
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
pub #field: sea_orm::ActiveValue<#ty>
|
||||
),*
|
||||
}
|
||||
|
||||
#[automatically_derived]
|
||||
@ -172,11 +176,7 @@ fn derive_into_model(model_fields: IntoIter<Field>) -> syn::Result<TokenStream>
|
||||
.into_iter()
|
||||
.map(format_field_ident)
|
||||
.collect();
|
||||
let model_field: Vec<Ident> = model_fields
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(format_field_ident)
|
||||
.collect();
|
||||
let model_field: Vec<Ident> = model_fields.clone().map(format_field_ident).collect();
|
||||
|
||||
let ignore_attr: Vec<bool> = model_fields
|
||||
.map(|field| !field_not_ignored(&field))
|
||||
|
@ -43,6 +43,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
.as_ref()
|
||||
.map(|table_name| {
|
||||
quote! {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Copy, Clone, Default, Debug, sea_orm::prelude::DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
@ -72,6 +73,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
if let Some(table_name) = table_name {
|
||||
let table_field_name = Ident::new("Table", Span::call_site());
|
||||
columns_enum.push(quote! {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[sea_orm(table_name=#table_name)]
|
||||
#[strum(disabled)]
|
||||
#table_field_name
|
||||
@ -226,8 +228,11 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
let variant_attrs = match &column_name {
|
||||
Some(column_name) => quote! {
|
||||
#[sea_orm(column_name = #column_name)]
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
},
|
||||
None => quote! {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
},
|
||||
None => quote! {},
|
||||
};
|
||||
|
||||
if ignore {
|
||||
@ -360,6 +365,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
quote! { (#primary_key_types) }
|
||||
};
|
||||
quote! {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
#primary_keys
|
||||
@ -377,6 +383,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
|
||||
};
|
||||
|
||||
Ok(quote! {
|
||||
#[doc = " Generated by sea-orm-macros"]
|
||||
#[derive(Copy, Clone, Debug, sea_orm::prelude::EnumIter, sea_orm::prelude::DeriveColumn)]
|
||||
pub enum Column {
|
||||
#columns_enum
|
||||
|
Loading…
x
Reference in New Issue
Block a user