diff --git a/examples/crud/Cargo.toml b/examples/crud/Cargo.toml index a3e7c78..96f11b4 100644 --- a/examples/crud/Cargo.toml +++ b/examples/crud/Cargo.toml @@ -6,6 +6,6 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -luna-orm = "0.3.3" +luna-orm = "0.3.4" sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/mysql/Cargo.toml b/examples/mysql/Cargo.toml index 5e3d838..a61db79 100644 --- a/examples/mysql/Cargo.toml +++ b/examples/mysql/Cargo.toml @@ -6,6 +6,6 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -luna-orm = "0.3.3" +luna-orm = "0.3.4" sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 362aaba..f594dd8 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -6,6 +6,6 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -luna-orm = "0.3.3" +luna-orm = "0.3.4" sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/template/Cargo.toml b/examples/template/Cargo.toml index 402b6dd..4043b4b 100644 --- a/examples/template/Cargo.toml +++ b/examples/template/Cargo.toml @@ -6,6 +6,6 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -luna-orm = "0.3.3" +luna-orm = "0.3.4" sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/examples/transaction/Cargo.toml b/examples/transaction/Cargo.toml index a65ed48..ac15be1 100644 --- a/examples/transaction/Cargo.toml +++ b/examples/transaction/Cargo.toml @@ -6,6 +6,6 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -luna-orm = "0.3.3" +luna-orm = "0.3.4" sqlx = { version = "0.7", features = [ "runtime-tokio" ] } tokio = { version = "1.35.1", features = ["full"] } diff --git a/luna-orm-macro/src/auto_entity.rs b/luna-orm-macro/src/auto_entity.rs index ff0ce76..24d2879 100644 --- a/luna-orm-macro/src/auto_entity.rs +++ b/luna-orm-macro/src/auto_entity.rs @@ -38,6 +38,8 @@ pub fn impl_auto_entity_macro(input: TokenStream) -> TokenStream { //let body_fields_name = build_fields_name(&body_fields); let body_fields_name = build_fields_name_with_option(&body_fields); + let generated_fields = extract_annotated_fields(&fields, "Generated"); + let generated_fields_name = build_fields_name(&generated_fields); let name = extract_table_name(&ident, &attrs); let generated_primary = generate_primary(&name, &primary_fields); @@ -85,9 +87,9 @@ pub fn impl_auto_entity_macro(input: TokenStream) -> TokenStream { let mut output = quote! { impl Entity for #ident { - //fn get_option_fields(&self) -> &'static str { - // vec![ #(#option_fields, )* ] - //} + fn get_generated_fields_name(&self) -> &'static [&'static str] { + &[ #(#generated_fields_name, )* ] + } fn get_table_name(&self) -> &'static str { #name diff --git a/luna-orm-macro/src/entity.rs b/luna-orm-macro/src/entity.rs index 3ef3c69..1a6d7e3 100644 --- a/luna-orm-macro/src/entity.rs +++ b/luna-orm-macro/src/entity.rs @@ -33,10 +33,12 @@ pub fn impl_entity_macro(input: TokenStream) -> TokenStream { let body_fields = extract_not_annotated_fields(&fields, "PrimaryKey"); //let body_fields_name = build_fields_name(&body_fields); let body_fields_name = build_fields_name_with_option(&body_fields); + let generated_fields = extract_annotated_fields(&fields, "Generated"); let name = extract_table_name(&ident, &attrs); let generated_primary = generate_primary(&name, &primary_fields); + let generated_fields_name = build_fields_name(&generated_fields); let primary_args_add_ref: Vec = gen_args_add_maybe_option(&primary_fields); @@ -76,9 +78,9 @@ pub fn impl_entity_macro(input: TokenStream) -> TokenStream { let mut output = quote! { impl Entity for #ident { - //fn get_option_fields(&self) -> &'static str { - // vec![ #(#option_fields, )* ] - //} + fn get_generated_fields_name(&self) -> &'static [&'static str] { + &[ #(#generated_fields_name, )* ] + } fn get_table_name(&self) -> &'static str { #name diff --git a/luna-orm-macro/src/lib.rs b/luna-orm-macro/src/lib.rs index 2085bdd..cedc216 100644 --- a/luna-orm-macro/src/lib.rs +++ b/luna-orm-macro/src/lib.rs @@ -65,7 +65,7 @@ pub fn expand_template_record_by_macro(input: TokenStream) -> TokenStream { impl_template_record_by_macro(input) } -#[proc_macro_derive(Schema, attributes(TableName, PrimaryKey, UniqueIndex))] +#[proc_macro_derive(Schema, attributes(TableName, PrimaryKey, UniqueIndex, Generated))] pub fn expand_auto_entity_macro(input: TokenStream) -> TokenStream { impl_auto_entity_macro(input) } diff --git a/luna-orm-trait/src/lib.rs b/luna-orm-trait/src/lib.rs index ed633e2..e1f6eba 100644 --- a/luna-orm-trait/src/lib.rs +++ b/luna-orm-trait/src/lib.rs @@ -51,6 +51,8 @@ pub trait Location: Sync { pub trait Entity: Sync { fn get_table_name(&self) -> &'static str; + fn get_generated_fields_name(&self) -> &'static [&'static str]; + fn get_primary_fields_name(&self) -> Vec; fn get_body_fields_name(&self) -> Vec;