diff --git a/rorm-db b/rorm-db index 20cfdea..ab7c192 160000 --- a/rorm-db +++ b/rorm-db @@ -1 +1 @@ -Subproject commit 20cfdeadcb0e3284ede88502f24cf93d1f89b243 +Subproject commit ab7c192caa6f4b7ab7c2bce9657634a584807c65 diff --git a/rorm-macro/src/generate/db_enum.rs b/rorm-macro/src/generate/db_enum.rs index d89ee82..685d449 100644 --- a/rorm-macro/src/generate/db_enum.rs +++ b/rorm-macro/src/generate/db_enum.rs @@ -13,7 +13,7 @@ pub fn generate_db_enum(parsed: &ParsedDbEnum) -> TokenStream { #(stringify!(#variants)),* ]; - impl ::rorm::internal::field::FieldType for #ident { + impl ::rorm::fields::traits::FieldType for #ident { type Kind = ::rorm::internal::field::kind::AsDbType; type Columns = [T; 1]; @@ -67,15 +67,25 @@ pub fn generate_db_enum(parsed: &ParsedDbEnum) -> TokenStream { } } } - impl<'a> ::rorm::conditions::IntoSingleValue<'a, ::rorm::internal::hmr::db_type::Choices> for #ident { - type Condition = ::rorm::conditions::Value<'a>; + impl<'rhs> ::rorm::fields::traits::FieldEq<'rhs, #ident> for #ident { + type EqCond = ::rorm::conditions::Binary<::rorm::conditions::Column, ::rorm::conditions::Value<'rhs>>; + fn field_equals(access: A, value: #ident) -> Self::EqCond { + let [value] = <#ident as ::rorm::fields::traits::FieldType>::into_values(value); + ::rorm::conditions::Binary { + operator: ::rorm::conditions::BinaryOperator::Equals, + fst_arg: ::rorm::conditions::Column(access), + snd_arg: value, + } + } - fn into_condition(self) -> Self::Condition { - ::rorm::conditions::Value::Choice(::std::borrow::Cow::Borrowed(match self { - #( - Self::#variants => stringify!(#variants), - )* - })) + type NeCond = ::rorm::conditions::Binary<::rorm::conditions::Column, ::rorm::conditions::Value<'rhs>>; + fn field_not_equals(access: A, value: #ident) -> Self::NeCond { + let [value] = <#ident as ::rorm::fields::traits::FieldType>::into_values(value); + ::rorm::conditions::Binary { + operator: ::rorm::conditions::BinaryOperator::NotEquals, + fst_arg: ::rorm::conditions::Column(access), + snd_arg: value, + } } } }; diff --git a/src/conditions/mod.rs b/src/conditions/mod.rs index e1ed386..dc4c4da 100644 --- a/src/conditions/mod.rs +++ b/src/conditions/mod.rs @@ -133,9 +133,14 @@ impl<'a, A: FieldAccess> Condition<'a> for Column { /// A binary expression #[derive(Copy, Clone)] pub struct Binary { - pub(crate) operator: BinaryOperator, - pub(crate) fst_arg: A, - pub(crate) snd_arg: B, + /// SQL operator to use + pub operator: BinaryOperator, + + /// The expression's first argument + pub fst_arg: A, + + /// The expression's second argument + pub snd_arg: B, } /// A binary operator #[derive(Copy, Clone)] @@ -189,10 +194,17 @@ impl<'a, A: Condition<'a>, B: Condition<'a>> Condition<'a> for Binary { /// A ternary expression #[derive(Copy, Clone)] pub struct Ternary { - pub(crate) operator: TernaryOperator, - pub(crate) fst_arg: A, - pub(crate) snd_arg: B, - pub(crate) trd_arg: C, + /// SQL operator to use + pub operator: TernaryOperator, + + /// The expression's first argument + pub fst_arg: A, + + /// The expression's second argument + pub snd_arg: B, + + /// The expression's third argument + pub trd_arg: C, } /// A ternary operator #[derive(Copy, Clone)] @@ -224,8 +236,11 @@ impl<'a, A: Condition<'a>, B: Condition<'a>, C: Condition<'a>> Condition<'a> for /// A unary expression #[derive(Copy, Clone)] pub struct Unary { - pub(crate) operator: UnaryOperator, - pub(crate) fst_arg: A, + /// SQL operator to use + pub operator: UnaryOperator, + + /// The expression's first argument + pub fst_arg: A, } /// A unary operator #[derive(Copy, Clone)]