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

Documentation for sea-orm #280

Merged
merged 21 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
21 changes: 21 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ jobs:
args: >
--manifest-path sea-orm-cli/Cargo.toml

test-temp:
name: Unit Test (Temp)
runs-on: ubuntu-20.04
strategy:
matrix:
args: ["--workspace", "--doc", "--all-targets"]
fail-fast: false
steps:
- uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- uses: actions-rs/cargo@v1
with:
command: test
args: ${{ matrix.args }}
Comment on lines +263 to +282
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a kind reminder. Removing it before merge :P


cli:
name: CLI
needs: init
Expand Down
4 changes: 4 additions & 0 deletions sea-orm-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ syn = { version = "^1", default-features = false, features = [ "full", "derive",
quote = "^1"
heck = "^0.3"
proc-macro2 = "^1"

[dev-dependencies]
sea-orm = { path = "../", features = ["macros"] }
serde = { version = "^1.0", features = ["derive"] }
Comment on lines +25 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @charleschege, I have fixed all the errors inside sea-orm doctest on fcf3ea9. And I know why cargo test --doc passes while cargo test --workspace fails.

In sea-orm-macros/src/lib.rs, you have include some code snippets that requires sea-orm. However, sea-orm-macros does not depends on sea-orm. So, all of the doctests failed. By adding dev-dependencies will solve the problem. 6904b9f

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This has resolved all the issues I had when testing documentation examples.

2 changes: 2 additions & 0 deletions sea-orm-macros/src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod derive_attr {
use bae::FromAttributes;

/// Attributes for Models and ActiveModels
#[derive(Default, FromAttributes)]
pub struct SeaOrm {
pub column: Option<syn::Ident>,
Expand All @@ -16,6 +17,7 @@ pub mod derive_attr {
pub mod field_attr {
use bae::FromAttributes;

/// Operations for Models and ActiveModels
#[derive(Default, FromAttributes)]
pub struct SeaOrm {
pub belongs_to: Option<syn::Lit>,
Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::{punctuated::Punctuated, token::Comma, Data, DataStruct, Field, Fields, Lit, Meta, Type};

/// Method to derive an [ActiveModel](sea_orm::ActiveModel)
pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<TokenStream> {
let fields = match data {
Data::Struct(DataStruct {
Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/active_model_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::quote;
use syn::Data;

/// Method to derive an implementation of [ActiveModelBehavior](sea_orm::ActiveModelBehavior)
pub fn expand_derive_active_model_behavior(_ident: Ident, _data: Data) -> syn::Result<TokenStream> {
Ok(quote!(
#[automatically_derived]
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-macros/src/derives/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::{quote, quote_spanned};
use syn::{punctuated::Punctuated, token::Comma, Data, DataEnum, Fields, Lit, Meta, Variant};

/// Derive a Column name for an enum type
pub fn impl_default_as_str(ident: &Ident, data: &Data) -> syn::Result<TokenStream> {
let variants = match data {
syn::Data::Enum(DataEnum { variants, .. }) => variants,
Expand Down Expand Up @@ -65,6 +66,7 @@ pub fn impl_default_as_str(ident: &Ident, data: &Data) -> syn::Result<TokenStrea
))
}

/// Implement a column using for an enum using [DeriveColumn](sea_orm::DeriveColumn)
pub fn impl_col_from_str(ident: &Ident, data: &Data) -> syn::Result<TokenStream> {
let data_enum = match data {
Data::Enum(data_enum) => data_enum,
Expand Down Expand Up @@ -114,6 +116,7 @@ pub fn expand_derive_column(ident: &Ident, data: &Data) -> syn::Result<TokenStre
))
}

/// Derive a column with a non_snake_case name
pub fn expand_derive_custom_column(ident: &Ident, data: &Data) -> syn::Result<TokenStream> {
let impl_default_as_str = impl_default_as_str(ident, data)?;
let impl_col_from_str = impl_col_from_str(ident, data)?;
Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use syn::{
Lit, Meta,
};

/// Method to derive an Model
pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Result<TokenStream> {
// if #[sea_orm(table_name = "foo", schema_name = "bar")] specified, create Entity struct
let mut table_name = None;
Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/from_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote, quote_spanned};
use syn::{Data, DataStruct, Field, Fields};

/// Method to derive a [QueryResult](sea_orm::QueryResult)
pub fn expand_derive_from_query_result(ident: Ident, data: Data) -> syn::Result<TokenStream> {
let fields = match data {
Data::Struct(DataStruct {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-macros/src/derives/into_active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use bae::FromAttributes;
use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned};

/// Attributes to derive an ActiveModel
#[derive(Default, FromAttributes)]
pub struct SeaOrm {
pub active_model: Option<syn::Ident>,
Expand Down Expand Up @@ -89,6 +90,7 @@ impl IntoActiveModel {
}
}

/// Method to derive the ActiveModel from the [ActiveModelTrait](sea_orm::ActiveModelTrait)
pub fn expand_into_active_model(input: syn::DeriveInput) -> syn::Result<TokenStream> {
let ident_span = input.ident.span();

Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl DeriveModel {
}
}

/// Method to derive an ActiveModel
pub fn expand_derive_model(input: syn::DeriveInput) -> syn::Result<TokenStream> {
let ident_span = input.ident.span();

Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/primary_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use proc_macro2::{Ident, TokenStream};
use quote::{quote, quote_spanned};
use syn::{Data, DataEnum, Fields, Variant};

/// Method to derive a Primary Key for a Model using the [PrimaryKeyTrait](sea_orm::PrimaryKeyTrait)
pub fn expand_derive_primary_key(ident: Ident, data: Data) -> syn::Result<TokenStream> {
let variants = match data {
syn::Data::Enum(DataEnum { variants, .. }) => variants,
Expand Down
1 change: 1 addition & 0 deletions sea-orm-macros/src/derives/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl DeriveRelation {
}
}

/// Method to derive a Relation
pub fn expand_derive_relation(input: syn::DeriveInput) -> syn::Result<TokenStream> {
let ident_span = input.ident.span();

Expand Down
Loading