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

Introduce ARITY to PrimaryKeyTrait #2180

Closed
wants to merge 4 commits into from
Closed
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/example_cake_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/src/example_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/src/example_fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions issues/1599/entity/src/cake_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions issues/1599/entity/src/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
4 changes: 4 additions & 0 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,12 @@ impl EntityWriter {
pub fn gen_impl_primary_key(entity: &Entity, date_time_crate: &DateTimeCrate) -> TokenStream {
let primary_key_auto_increment = entity.get_primary_key_auto_increment();
let value_type = entity.get_primary_key_rs_type(date_time_crate);
let primary_key_len = entity.primary_keys.len();
let arity = proc_macro2::Literal::usize_unsuffixed(primary_key_len);
quote! {
impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = #arity;

type ValueType = #value_type;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/cake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/cake_filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/cake_filling_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/cake_with_double.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/cake_with_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded/collection_float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
false
}
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/rust_keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_attributes/cake_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_attributes/cake_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_derives/cake_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_derives/cake_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_derives/cake_one.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/cake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
true
}
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/fruit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
3 changes: 3 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/parent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 2;

type ValueType = (i32, i32);

fn auto_increment() -> bool {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_schema_name/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_serde/cake_both.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_serde/cake_deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_serde/cake_none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
2 changes: 2 additions & 0 deletions sea-orm-codegen/tests/expanded_with_serde/cake_serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum PrimaryKey {
}

impl PrimaryKeyTrait for PrimaryKey {
const ARITY: usize = 1;

type ValueType = i32;

fn auto_increment() -> bool {
Expand Down
Loading
Loading