Skip to content

Commit

Permalink
Merge pull request #280 from charleschege/master
Browse files Browse the repository at this point in the history
Documentation for sea-orm
  • Loading branch information
tyt2y3 authored Nov 1, 2021
2 parents 8338c23 + 6904b9f commit d5da351
Show file tree
Hide file tree
Showing 55 changed files with 1,077 additions and 6 deletions.
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 }}

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"] }
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

0 comments on commit d5da351

Please sign in to comment.