Skip to content

Commit

Permalink
update generated
Browse files Browse the repository at this point in the history
  • Loading branch information
soulww committed Dec 29, 2023
1 parent ab8af7b commit d9ca738
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/crud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion examples/mysql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion examples/sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion examples/template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion examples/transaction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
8 changes: 5 additions & 3 deletions luna-orm-macro/src/auto_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions luna-orm-macro/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<proc_macro2::TokenStream> =
gen_args_add_maybe_option(&primary_fields);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion luna-orm-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions luna-orm-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>;

fn get_body_fields_name(&self) -> Vec<String>;
Expand Down

0 comments on commit d9ca738

Please sign in to comment.