Skip to content

Commit

Permalink
rename luna_orm_trait::add_arg to luna_add_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
soulww committed Dec 27, 2023
1 parent f7219c1 commit a8163e4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions luna-orm-macro/src/field_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ pub fn map_field(field: Field, map_type: FieldMapType) -> TokenStream {
}
FieldMapType::ArgsAddRef => {
quote_spanned! { span =>
luna_orm_trait::add_arg(&mut arguments, &self.#field_name);
luna_add_arg(&mut arguments, &self.#field_name);
}
}
FieldMapType::ArgsAddOptionRef => {
quote_spanned! { span =>
if let Some(#field_name) = &self.#field_name {
luna_orm_trait::add_arg(&mut arguments, &#field_name);
luna_add_arg(&mut arguments, &#field_name);
}
}
}
FieldMapType::ArgsAddOptionLocationRef => {
quote_spanned! { span =>
if let Some(#field_name) = &self.#field_name {
luna_orm_trait::add_arg(&mut arguments, &#field_name.val);
luna_add_arg(&mut arguments, &#field_name.val);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion luna-orm-macro/src/template_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn impl_template_record_by_macro(input: TokenStream) -> TokenStream {
let span = Span::call_site();
let ident = Ident::new(variable, span);
quote!(
luna_orm_trait::add_arg(&mut arguments, &self.#ident);
luna_add_arg(&mut arguments, &self.#ident);
)
})
.collect::<Vec<proc_macro2::TokenStream>>();
Expand Down
6 changes: 4 additions & 2 deletions luna-orm-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,17 @@ where
}
}

pub fn merge_any_arguments<'p>(
//pub fn merge_any_arguments<'p>(
pub fn luna_merge_args<'p>(
mut args_a: AnyArguments<'p>,
args_b: AnyArguments<'p>,
) -> AnyArguments<'p> {
args_a.values.0.extend(args_b.values.0);
args_a
}

pub fn add_arg<'q, T>(args: &mut AnyArguments<'q>, value: &T)
//pub fn add_arg<'q, T>(args: &mut AnyArguments<'q>, value: &T)
pub fn luna_add_arg<'q, T>(args: &mut AnyArguments<'q>, value: &T)
where
T: 'q + Send + Encode<'q, Any> + Type<Any>,
{
Expand Down
3 changes: 2 additions & 1 deletion luna-orm-trait/tests/trait_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use sqlx::{AnyExecutor, Arguments};
pub struct HelloPrimary {
name: String,
}
use luna_orm_trait::luna_add_arg;

/*
impl Primary for HelloPrimary {
Expand All @@ -32,7 +33,7 @@ impl Primary for HelloPrimary {
fn any_arguments(&self) -> sqlx::any::AnyArguments<'_> {
let mut args = AnyArguments::default();
//<Encode<'_, Any>>::encode_by_ref(self.name, args.values);
luna_orm_trait::add_arg(&mut args, &self.name);
luna_add_arg(&mut args, &self.name);
args
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/command_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait CommandExecutor: SqlExecutor {
let sql = self.get_generator().get_update_sql(mutation, primary);
let mut args = mutation.any_arguments();
let where_args = primary.any_arguments();
args = merge_any_arguments(args, where_args);
args = luna_merge_args(args, where_args);
let result = self.execute(&sql, args).await?;
return Ok(result.rows_affected() > 0);
}
Expand Down Expand Up @@ -184,7 +184,7 @@ pub trait CommandExecutor: SqlExecutor {
let sql = self.get_generator().get_change_sql(mutation, location);
let mut args = mutation.any_arguments();
let where_args = location.any_arguments();
args = merge_any_arguments(args, where_args);
args = luna_merge_args(args, where_args);
let result = self.execute(&sql, args).await?;
return Ok(result.rows_affected() as usize);
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub type LunaOrmResult<T> = std::result::Result<T, error::LunaOrmError>;
pub mod prelude {
pub use crate::command_executor::CommandExecutor;
pub use crate::database::*;
pub use crate::sql_executor::SqlExecutor;
pub use crate::error::*;
pub use crate::sql_executor::*;
pub use crate::sql_generator::*;
pub use crate::transaction::Transaction;
pub use luna_orm_macro::*;
Expand Down
1 change: 0 additions & 1 deletion src/mapper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use async_trait::async_trait;
use luna_orm_trait::merge_any_arguments;
use luna_orm_trait::SqlxError;
use luna_orm_trait::{
Entity, Location, Mutation, PageInfo, PagedList, Primary, SelectedEntity, Selection,
Expand Down

0 comments on commit a8163e4

Please sign in to comment.