Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for using sea-orm with #[deny(missing_docs)] #1522

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Basic sea-orm example.
#![deny(missing_docs)]
use sea_orm::Database;

mod entities;
Expand Down
4 changes: 4 additions & 0 deletions sea-orm-macros/src/derives/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)*
}
Expand All @@ -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)
Expand All @@ -297,6 +300,7 @@ impl ActiveEnum {
};

quote!(
#[doc = " Generated by sea-orm-macros"]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct #enum_name_iden;

Expand Down
16 changes: 8 additions & 8 deletions sea-orm-macros/src/derives/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 8 additions & 1 deletion sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down