From 8007c13ad2f2ce0e6196c3a0acecef64f8924c6a Mon Sep 17 00:00:00 2001 From: kuqmua Date: Sat, 4 Jan 2025 13:19:12 +0300 Subject: [PATCH] next steps --- .../server/routes/api/example/example.http | 222 +++-- .../server/routes/api/example/mod.rs | 9 +- .../src/lib.rs | 477 ++++++++++ .../postgresql_type/postgresql_base_type.rs | 860 +++++++++++++----- .../src/postgresql_type/postgresql_type.rs | 29 + 5 files changed, 1274 insertions(+), 323 deletions(-) diff --git a/common/src/repositories_types/server/routes/api/example/example.http b/common/src/repositories_types/server/routes/api/example/example.http index a005c0f83..d54701a95 100644 --- a/common/src/repositories_types/server/routes/api/example/example.http +++ b/common/src/repositories_types/server/routes/api/example/example.http @@ -38,8 +38,20 @@ commit: 926cf2c0bac1dfbd1fd466068b2c9fc5a271bc3b [ { - "sqlx_types_decimal_as_postgresql_numeric": "1", - "sqlx_types_decimal_as_postgresql_numeric_not_null": "5" + "sqlx_types_big_decimal_as_postgresql_numeric": { + "digits": { + "sign": "NoSign", + "digits": [1,2] + }, + "scale": 1 + }, + "sqlx_types_big_decimal_as_postgresql_numeric_not_null": { + "digits": { + "sign": "Plus", + "digits": [654] + }, + "scale": 2 + } } ] @@ -72,87 +84,137 @@ content-type: application/json commit: 72a7f5c066a08a77fb91e75abee9f6e79e00e2b8 { - "std_primitive_i64_as_postgresql_big_serial_not_null": { + # "std_primitive_i64_as_postgresql_big_serial_not_null": { + # "logical_operator": "Or", + # "value": [ + # { + # "Equal": { + # "logical_operator": "Or", + # "value": 0 + # } + # }, + # { + # "GreaterThan": { + # "logical_operator": "Or", + # "value": 0 + # } + # }, + # { + # "Between": { + # "logical_operator": "Or", + # "start": 0, + # "end": 0 + # } + # }, + # { + # "In": { + # "logical_operator": "Or", + # "value": [ + # 0 + # ] + # } + # } + # ] + # }, + # "sqlx_types_big_decimal_as_postgresql_numeric": { + # "logical_operator": "Or", + # "value": [ + # { + # "Equal": { + # "logical_operator": "Or", + # "value": { + # "digits": { + # "sign": "NoSign", + # "digits": [] + # }, + # "scale": 0 + # } + # } + # }, + # { + # "GreaterThan": { + # "logical_operator": "Or", + # "value": { + # "digits": { + # "sign": "NoSign", + # "digits": [] + # }, + # "scale": 0 + # } + # } + # }, + # { + # "Between": { + # "logical_operator": "Or", + # "start": { + # "digits": { + # "sign": "NoSign", + # "digits": [] + # }, + # "scale": 0 + # }, + # "end": { + # "digits": { + # "sign": "NoSign", + # "digits": [] + # }, + # "scale": 0 + # } + # } + # }, + # { + # "IsNull": { + # "logical_operator": "Or" + # } + # } + # ] + # }, + "sqlx_types_big_decimal_as_postgresql_numeric_not_null": { "logical_operator": "Or", "value": [ - { - "Equal": { - "logical_operator": "Or", - "value": 0 - } - }, - { - "GreaterThan": { - "logical_operator": "Or", - "value": 0 - } - }, - { - "Between": { - "logical_operator": "Or", - "start": 0, - "end": 0 - } - }, - { - "In": { - "logical_operator": "Or", - "value": [ - 0 - ] - } - } - ] - }, - "sqlx_types_decimal_as_postgresql_numeric": { - "logical_operator": "Or", - "value": [ - { - "Equal": { - "logical_operator": "Or", - "value": "0" - } - }, - { - "GreaterThan": { - "logical_operator": "Or", - "value": "0" - } - }, - { - "Between": { - "logical_operator": "Or", - "start": "0", - "end": "0" - } - }, - { - "IsNull": { - "logical_operator": "Or" - } - } - ] - }, - "sqlx_types_decimal_as_postgresql_numeric_not_null": { - "logical_operator": "Or", - "value": [ - { - "Equal": { - "logical_operator": "Or", - "value": "0" - } - }, - { - "GreaterThan": { - "logical_operator": "Or", - "value": "0" - } - }, + # { + # "Equal": { + # "logical_operator": "Or", + # "value": { + # "digits": { + # "sign": "Plus", + # "digits": [64823423,2323,23423] + # }, + # "scale": 2 + # } + # } + # } + # , + # { + # "GreaterThan": { + # "logical_operator": "Or", + # "value": { + # "digits": { + # "sign": "NoSign", + # "digits": [1] + # }, + # "scale": 1 + # } + # } + # } + # , { "Between": { "logical_operator": "Or", - "start": "0", - "end": "0" + "start": { + "digits": { + "sign": "Plus", + "digits": [1] + }, + "scale": 2 + }, + "end": { + "digits": { + "sign": "Plus", + "digits": [1000000] + }, + "scale": 2 + } } } ] @@ -162,10 +224,10 @@ commit: 72a7f5c066a08a77fb91e75abee9f6e79e00e2b8 "std_primitive_i64_as_postgresql_big_serial_not_null": null }, { - "sqlx_types_decimal_as_postgresql_numeric": null + "sqlx_types_big_decimal_as_postgresql_numeric": null }, { - "sqlx_types_decimal_as_postgresql_numeric_not_null": null + "sqlx_types_big_decimal_as_postgresql_numeric_not_null": null } ], "order_by": { diff --git a/common/src/repositories_types/server/routes/api/example/mod.rs b/common/src/repositories_types/server/routes/api/example/mod.rs index 39000ef90..9536aa543 100644 --- a/common/src/repositories_types/server/routes/api/example/mod.rs +++ b/common/src/repositories_types/server/routes/api/example/mod.rs @@ -134,9 +134,11 @@ pub struct Example { // pub sqlx_types_time_primitive_date_time_as_timestamp: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesTimePrimitiveDateTimeAsPostgresqlTimestamp, // pub sqlx_types_time_primitive_date_time_as_timestamp_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesTimePrimitiveDateTimeAsPostgresqlTimestampNotNull, - pub sqlx_types_decimal_as_postgresql_numeric: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesDecimalAsPostgresqlNumeric, - pub sqlx_types_decimal_as_postgresql_numeric_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesDecimalAsPostgresqlNumericNotNull, + // pub sqlx_types_decimal_as_postgresql_numeric: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesDecimalAsPostgresqlNumeric, + // pub sqlx_types_decimal_as_postgresql_numeric_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesDecimalAsPostgresqlNumericNotNull, + pub sqlx_types_big_decimal_as_postgresql_numeric: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesBigDecimalAsPostgresqlNumeric, + pub sqlx_types_big_decimal_as_postgresql_numeric_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesBigDecimalAsPostgresqlNumericNotNull, //here // pub sqlx_postgres_types_pg_range_sqlx_types_time_offset_date_time_as_postgresql_ts_tz_range: postgresql_crud::postgresql_type::postgresql_type::SqlxPostgresTypesPgRangeSqlxTypesTimeOffsetDateTimeAsPostgresqlTsTzRange, @@ -154,9 +156,6 @@ pub struct Example { // pub sqlx_postgres_types_pg_ci_text_as_postgresql_ci_text: postgresql_crud::postgresql_type::postgresql_type::SqlxPostgresTypesPgCiTextAsPostgresqlCiText, // pub sqlx_postgres_types_pg_ci_text_as_postgresql_ci_text_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxPostgresTypesPgCiTextAsPostgresqlCiTextNotNull, - // pub sqlx_types_big_decimal_as_postgresql_numeric: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesBigDecimalAsPostgresqlNumeric, - // pub sqlx_types_big_decimal_as_postgresql_numeric_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesBigDecimalAsPostgresqlNumericNotNull, - // pub sqlx_types_chrono_date_time_sqlx_types_chrono_utc_as_postgresql_timestamp_tz: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesChronoDateTimeSqlxTypesChronoUtcAsPostgresqlTimestampTz, // pub sqlx_types_chrono_date_time_sqlx_types_chrono_utc_as_postgresql_timestamp_tz_not_null: postgresql_crud::postgresql_type::postgresql_type::SqlxTypesChronoDateTimeSqlxTypesChronoUtcAsPostgresqlTimestampTzNotNull, diff --git a/postgresql_crud/postgresql_crud_common/postgresql_crud_types_macro_logic_reuse/src/lib.rs b/postgresql_crud/postgresql_crud_common/postgresql_crud_types_macro_logic_reuse/src/lib.rs index 711f0b233..1c78a1847 100644 --- a/postgresql_crud/postgresql_crud_common/postgresql_crud_types_macro_logic_reuse/src/lib.rs +++ b/postgresql_crud/postgresql_crud_common/postgresql_crud_types_macro_logic_reuse/src/lib.rs @@ -9456,4 +9456,481 @@ pub fn postgresql_base_type_tokens_where_element_sqlx_types_decimal(input: proc_ // ); // } generated.into() +} + +//////////// +#[proc_macro_derive(PostgresqlBaseTypeTokensSqlxTypesBigDecimal)] +pub fn postgresql_base_type_tokens_sqlx_types_big_decimal(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + generate_postgresql_base_type_tokens( + input, + "e::quote!{::core::default::Default::default()} + ) +} + +#[proc_macro_derive(PostgresqlBaseTypeTokensWhereElementSqlxTypesBigDecimal)] +pub fn postgresql_base_type_tokens_where_element_sqlx_types_big_decimal(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + panic_location::panic_location(); + let syn_derive_input: syn::DeriveInput = syn::parse(input).unwrap_or_else(|error| panic!("{}: {error}", constants::AST_PARSE_FAILED)); + let ident = &syn_derive_input.ident; + let field_type = extract_first_syn_type_from_unnamed_struct(&syn_derive_input); + let generate_postgresql_type_tokens_where_element_token_stream = |is_nullable: IsNullable|{ + let increment_snake_case = naming::IncrementSnakeCase; + let value_snake_case = naming::ValueSnakeCase; + let column_snake_case = naming::ColumnSnakeCase; + let query_snake_case = naming::QuerySnakeCase; + let crate_generate_postgresql_json_type_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_call_token_stream = quote::quote!{ + crate::generate_postgresql_json_type::StdDefaultDefaultButStdOptionOptionIsAlwaysSomeAndStdVecVecAlwaysContainsOneElement::std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element() + }; + let checked_add_upper_camel_case = naming::CheckedAddUpperCamelCase; + let try_generate_bind_increments_error_named_upper_camel_case = naming::TryGenerateBindIncrementsErrorNamedUpperCamelCase; + + let maybe_postgresql_type_tokens_where_element_is_null_token_stream = is_nullable.maybe_generate_postgresql_type_std_option_option_tokens_where_element_is_null_token_stream(&ident); + + let equal_upper_camel_case = naming::EqualUpperCamelCase; + let postgresql_type_tokens_where_element_equal_token_stream = generate_postgresql_type_tokens_where_element_variant_token_stream( + &ident, + &equal_upper_camel_case, + &is_nullable, + ShouldWhereElementFieldsBePublic::True, + "e::quote!{pub value: #ident}, + "e::quote!{#value_snake_case: #crate_generate_postgresql_json_type_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_call_token_stream}, + "e::quote!{ + match #increment_snake_case.checked_add(1) { + Some(#value_snake_case) => { + *#increment_snake_case = #value_snake_case; + Ok(format!( + "{}({} = ${})", + &self.logical_operator.to_query_part(is_need_to_add_logical_operator), + #column_snake_case, + #increment_snake_case + )) + }, + None => Err(crate::#try_generate_bind_increments_error_named_upper_camel_case::#checked_add_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence!(), + }) + } + }, + "e::quote!{ + #query_snake_case = #query_snake_case.bind(self.#value_snake_case.0); + #query_snake_case + } + ); + + let greater_than_upper_camel_case = naming::GreaterThanUpperCamelCase; + let postgresql_type_tokens_where_element_greater_than_token_stream = generate_postgresql_type_tokens_where_element_variant_token_stream( + &ident, + &greater_than_upper_camel_case, + &is_nullable, + ShouldWhereElementFieldsBePublic::True, + "e::quote!{pub #value_snake_case: #ident}, + "e::quote!{#value_snake_case: #crate_generate_postgresql_json_type_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_call_token_stream}, + "e::quote!{ + match #increment_snake_case.checked_add(1) { + Some(#value_snake_case) => { + *#increment_snake_case = #value_snake_case; + Ok(format!( + "{}({} > ${})", + &self.logical_operator.to_query_part(is_need_to_add_logical_operator), + #column_snake_case, + #increment_snake_case + )) + }, + None => Err(crate::#try_generate_bind_increments_error_named_upper_camel_case::#checked_add_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence!(), + }) + } + }, + "e::quote!{ + #query_snake_case = #query_snake_case.bind(self.#value_snake_case.0); + #query_snake_case + } + ); + + let between_upper_camel_case = naming::BetweenUpperCamelCase; + let postgresql_type_tokens_where_element_between_token_stream = { + let start_more_or_equal_to_end_upper_camel_case = naming::StartMoreOrEqualToEndUpperCamelCase; + let start_snake_case = naming::StartSnakeCase; + let end_snake_case = naming::EndSnakeCase; + generate_postgresql_type_tokens_where_element_variant_token_stream( + &ident, + &between_upper_camel_case, + &is_nullable, + ShouldWhereElementFieldsBePublic::False { + ident: &ident, + postfix: &between_upper_camel_case, + try_new_error_named_variants_token_stream: "e::quote!{ + #start_more_or_equal_to_end_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence::CodeOccurence, + } + }, + try_new_additional_input_parameters_token_stream: "e::quote!{ + #start_snake_case: #ident, + #end_snake_case: #ident, + }, + try_new_content_token_stream: &{ + let postgresql_type_ident_where_element_between_try_new_error_named_upper_camel_case = naming::parameter::PostgresqlTypeSelfWhereElementBetweenTryNewErrorNamedUpperCamelCase::from_tokens(&ident); + quote::quote!{ + if #start_snake_case.0 < #end_snake_case.0 { + Ok(Self { + logical_operator, + #start_snake_case, + #end_snake_case + }) + } + else { + Err(#postgresql_type_ident_where_element_between_try_new_error_named_upper_camel_case::#start_more_or_equal_to_end_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence!(), + }) + } + } + }, + impl_deserialize_token_stream: &{ + let postgresql_type_ident_where_element_between_upper_camel_case = naming::parameter::PostgresqlTypeSelfWhereElementBetweenUpperCamelCase::from_tokens(&ident); + let ( + struct_postgresql_type_ident_where_element_between_double_quotes_token_stream, + struct_postgresql_type_ident_where_element_between_with_3_elements_double_quotes_token_stream, + postgresql_type_ident_where_element_between_double_quotes_token_stream + ) = generate_serde_deserialize_double_quotes_token_stream(&postgresql_type_ident_where_element_between_upper_camel_case, 3, &between_upper_camel_case); + quote::quote! { + const _: () = { + #[allow(unused_extern_crates, clippy::useless_attribute)] + extern crate serde as _serde; + #[automatically_derived] + impl<'de> _serde::Deserialize<'de> + for #postgresql_type_ident_where_element_between_upper_camel_case { + fn deserialize<__D>( + __deserializer: __D, + ) -> _serde::__private::Result + where + __D: _serde::Deserializer<'de>, + { + #[allow(non_camel_case_types)] + #[doc(hidden)] + enum __Field { + __field0, + __field1, + __field2, + __ignore, + } + #[doc(hidden)] + struct __FieldVisitor; + impl<'de> _serde::de::Visitor<'de> for __FieldVisitor { + type Value = __Field; + fn expecting( + &self, + __formatter: &mut _serde::__private::Formatter, + ) -> _serde::__private::fmt::Result { + _serde::__private::Formatter::write_str( + __formatter, + "field identifier", + ) + } + fn visit_u64<__E>( + self, + __value: u64, + ) -> _serde::__private::Result + where + __E: _serde::de::Error, + { + match __value { + 0u64 => _serde::__private::Ok(__Field::__field0), + 1u64 => _serde::__private::Ok(__Field::__field1), + 2u64 => _serde::__private::Ok(__Field::__field2), + _ => _serde::__private::Ok(__Field::__ignore), + } + } + fn visit_str<__E>( + self, + __value: &str, + ) -> _serde::__private::Result + where + __E: _serde::de::Error, + { + match __value { + "logical_operator" => _serde::__private::Ok(__Field::__field0), + "start" => _serde::__private::Ok(__Field::__field1), + "end" => _serde::__private::Ok(__Field::__field2), + _ => _serde::__private::Ok(__Field::__ignore), + } + } + fn visit_bytes<__E>( + self, + __value: &[u8], + ) -> _serde::__private::Result + where + __E: _serde::de::Error, + { + match __value { + b"logical_operator" => _serde::__private::Ok(__Field::__field0), + b"start" => _serde::__private::Ok(__Field::__field1), + b"end" => _serde::__private::Ok(__Field::__field2), + _ => _serde::__private::Ok(__Field::__ignore), + } + } + } + impl<'de> _serde::Deserialize<'de> for __Field { + #[inline] + fn deserialize<__D>( + __deserializer: __D, + ) -> _serde::__private::Result + where + __D: _serde::Deserializer<'de>, + { + _serde::Deserializer::deserialize_identifier( + __deserializer, + __FieldVisitor, + ) + } + } + #[doc(hidden)] + struct __Visitor<'de> { + marker: _serde::__private::PhantomData< + #postgresql_type_ident_where_element_between_upper_camel_case, + >, + lifetime: _serde::__private::PhantomData<&'de ()>, + } + impl<'de> _serde::de::Visitor<'de> for __Visitor<'de> { + type Value = #postgresql_type_ident_where_element_between_upper_camel_case; + fn expecting( + &self, + __formatter: &mut _serde::__private::Formatter, + ) -> _serde::__private::fmt::Result { + _serde::__private::Formatter::write_str( + __formatter, + #struct_postgresql_type_ident_where_element_between_double_quotes_token_stream, + ) + } + #[inline] + fn visit_seq<__A>( + self, + mut __seq: __A, + ) -> _serde::__private::Result + where + __A: _serde::de::SeqAccess<'de>, + { + let __field0 = match _serde::de::SeqAccess::next_element::< + crate::LogicalOperator, + >(&mut __seq)? { + _serde::__private::Some(__value) => __value, + _serde::__private::None => { + return _serde::__private::Err( + _serde::de::Error::invalid_length( + 0usize, + &#struct_postgresql_type_ident_where_element_between_with_3_elements_double_quotes_token_stream, + ), + ); + } + }; + let __field1 = match _serde::de::SeqAccess::next_element::< + #ident, + >(&mut __seq)? { + _serde::__private::Some(__value) => __value, + _serde::__private::None => { + return _serde::__private::Err( + _serde::de::Error::invalid_length( + 1usize, + &#struct_postgresql_type_ident_where_element_between_with_3_elements_double_quotes_token_stream, + ), + ); + } + }; + let __field2 = match _serde::de::SeqAccess::next_element::< + #ident, + >(&mut __seq)? { + _serde::__private::Some(__value) => __value, + _serde::__private::None => { + return _serde::__private::Err( + _serde::de::Error::invalid_length( + 2usize, + &#struct_postgresql_type_ident_where_element_between_with_3_elements_double_quotes_token_stream, + ), + ); + } + }; + match #postgresql_type_ident_where_element_between_upper_camel_case::try_new(__field0, __field1, __field2) { + Ok(value) => _serde::__private::Ok(value), + Err(error) => Err(_serde::de::Error::custom(format!("{error:?}"))) + } + } + #[inline] + fn visit_map<__A>( + self, + mut __map: __A, + ) -> _serde::__private::Result + where + __A: _serde::de::MapAccess<'de>, + { + let mut __field0: _serde::__private::Option< + crate::LogicalOperator, + > = _serde::__private::None; + let mut __field1: _serde::__private::Option< + #ident, + > = _serde::__private::None; + let mut __field2: _serde::__private::Option< + #ident, + > = _serde::__private::None; + while let _serde::__private::Some(__key) = _serde::de::MapAccess::next_key::< + __Field, + >(&mut __map)? { + match __key { + __Field::__field0 => { + if _serde::__private::Option::is_some(&__field0) { + return _serde::__private::Err( + <__A::Error as _serde::de::Error>::duplicate_field( + "logical_operator", + ), + ); + } + __field0 = _serde::__private::Some( + _serde::de::MapAccess::next_value::< + crate::LogicalOperator, + >(&mut __map)?, + ); + } + __Field::__field1 => { + if _serde::__private::Option::is_some(&__field1) { + return _serde::__private::Err( + <__A::Error as _serde::de::Error>::duplicate_field("start"), + ); + } + __field1 = _serde::__private::Some( + _serde::de::MapAccess::next_value::< + #ident, + >(&mut __map)?, + ); + } + __Field::__field2 => { + if _serde::__private::Option::is_some(&__field2) { + return _serde::__private::Err( + <__A::Error as _serde::de::Error>::duplicate_field("end"), + ); + } + __field2 = _serde::__private::Some( + _serde::de::MapAccess::next_value::< + #ident, + >(&mut __map)?, + ); + } + _ => { + let _ = _serde::de::MapAccess::next_value::< + _serde::de::IgnoredAny, + >(&mut __map)?; + } + } + } + let __field0 = match __field0 { + _serde::__private::Some(__field0) => __field0, + _serde::__private::None => { + _serde::__private::de::missing_field("logical_operator")? + } + }; + let __field1 = match __field1 { + _serde::__private::Some(__field1) => __field1, + _serde::__private::None => { + _serde::__private::de::missing_field("start")? + } + }; + let __field2 = match __field2 { + _serde::__private::Some(__field2) => __field2, + _serde::__private::None => { + _serde::__private::de::missing_field("end")? + } + }; + match #postgresql_type_ident_where_element_between_upper_camel_case::try_new(__field0, __field1, __field2) { + Ok(value) => _serde::__private::Ok(value), + Err(error) => Err(_serde::de::Error::custom(format!("{error:?}"))) + } + } + } + #[doc(hidden)] + const FIELDS: &'static [&'static str] = &[ + "logical_operator", + "start", + "end", + ]; + _serde::Deserializer::deserialize_struct( + __deserializer, + #postgresql_type_ident_where_element_between_double_quotes_token_stream, + FIELDS, + __Visitor { + marker: _serde::__private::PhantomData::< + #postgresql_type_ident_where_element_between_upper_camel_case, + >, + lifetime: _serde::__private::PhantomData, + }, + ) + } + } + }; + } + }, + }, + "e::quote!{ + #start_snake_case: #ident, + #end_snake_case: #ident, + }, + "e::quote!{ + #start_snake_case: #crate_generate_postgresql_json_type_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_call_token_stream, + #end_snake_case: #crate_generate_postgresql_json_type_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element_call_token_stream, + }, + "e::quote!{ + match #increment_snake_case.checked_add(1) { + Some(first_value) => { + *#increment_snake_case = first_value; + match #increment_snake_case.checked_add(1) { + Some(second_value) => { + *#increment_snake_case = second_value; + let between_snake_case = naming::BetweenSnakeCase; + let and_snake_case = naming::AndSnakeCase; + Ok(format!("{}({column} {between_snake_case} ${first_value} {and_snake_case} ${second_value})", &self.logical_operator.to_query_part(is_need_to_add_logical_operator))) + }, + None => Err(crate::#try_generate_bind_increments_error_named_upper_camel_case::#checked_add_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence!(), + }) + } + }, + None => Err(crate::#try_generate_bind_increments_error_named_upper_camel_case::#checked_add_upper_camel_case { + code_occurence: error_occurence_lib::code_occurence!(), + }) + } + }, + "e::quote!{ + #query_snake_case = #query_snake_case.bind(self.#start_snake_case.0); + #query_snake_case = #query_snake_case.bind(self.#end_snake_case.0); + #query_snake_case + } + ) + }; + + let postgresql_type_tokens_where_element_token_stream = generate_postgresql_type_tokens_where_element_and_postgresql_type_std_option_option_tokens_where_element_token_stream( + is_nullable, + &ident, + &vec![ + &equal_upper_camel_case, + &greater_than_upper_camel_case, + &between_upper_camel_case, + ] + ); + quote::quote! { + #maybe_postgresql_type_tokens_where_element_is_null_token_stream + + #postgresql_type_tokens_where_element_equal_token_stream + #postgresql_type_tokens_where_element_greater_than_token_stream + #postgresql_type_tokens_where_element_between_token_stream + #postgresql_type_tokens_where_element_token_stream + } + }; + let postgresql_type_ident_where_element_token_stream = generate_postgresql_type_tokens_where_element_token_stream(IsNullable::False); + let postgresql_type_std_option_option_ident_where_element_token_stream = generate_postgresql_type_tokens_where_element_token_stream(IsNullable::True); + let generated = quote::quote! { + #postgresql_type_ident_where_element_token_stream + #postgresql_type_std_option_option_ident_where_element_token_stream + }; + // if ident == "" { + // macros_helpers::write_token_stream_into_file::write_token_stream_into_file( + // "PostgresqlBaseTypeTokensWhereElementSqlxTypesBigDecimal", + // &generated, + // ); + // } + generated.into() } \ No newline at end of file diff --git a/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_base_type.rs b/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_base_type.rs index 1eac6a7d7..b3bf90ff7 100644 --- a/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_base_type.rs +++ b/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_base_type.rs @@ -2171,192 +2171,6 @@ pub struct SqlxTypesChronoNaiveDateTime(pub sqlx::types::chrono::NaiveDateTime); )] pub struct SqlxTypesTimeTime(pub sqlx::types::time::Time);//todo putting this type to postgresql ignores milliseconds. maybe it changes in future versions of sqlx - -//not an actual postgresql type. -#[derive(Debug, Clone, Copy, PartialEq, Eq, utoipa::ToSchema)] -pub struct SqlxTypesTimeUtcOffset(pub sqlx::types::time::UtcOffset); -impl serde::Serialize for SqlxTypesTimeUtcOffset { - fn serialize<__S>(&self, __serializer: __S) -> serde::__private::Result<__S::Ok, __S::Error> - where - __S: serde::Serializer, - { - let mut __serde_state = serde::Serializer::serialize_struct(__serializer, "SqlxTypesTimeUtcOffset", false as usize + 1 + 1 + 1)?; - serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "hours", &self.0.whole_hours())?; - serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "minutes", &self.0.minutes_past_hour())?; - serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "seconds", &self.0.seconds_past_minute())?; - serde::ser::SerializeStruct::end(__serde_state) - } -} -impl<'de> serde::Deserialize<'de> for SqlxTypesTimeUtcOffset { - fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result - where - __D: serde::Deserializer<'de>, - { - #[allow(non_camel_case_types)] - #[doc(hidden)] - enum __Field { - __field0, - __field1, - __field2, - __ignore, - } - #[doc(hidden)] - struct __FieldVisitor; - impl serde::de::Visitor<'_> for __FieldVisitor { - type Value = __Field; - fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { - serde::__private::Formatter::write_str(__formatter, "field identifier") - } - fn visit_u64<__E>(self, __value: u64) -> serde::__private::Result - where - __E: serde::de::Error, - { - match __value { - 0u64 => serde::__private::Ok(__Field::__field0), - 1u64 => serde::__private::Ok(__Field::__field1), - 2u64 => serde::__private::Ok(__Field::__field2), - _ => serde::__private::Ok(__Field::__ignore), - } - } - fn visit_str<__E>(self, __value: &str) -> serde::__private::Result - where - __E: serde::de::Error, - { - match __value { - "hours" => serde::__private::Ok(__Field::__field0), - "minutes" => serde::__private::Ok(__Field::__field1), - "seconds" => serde::__private::Ok(__Field::__field2), - _ => serde::__private::Ok(__Field::__ignore), - } - } - fn visit_bytes<__E>(self, __value: &[u8]) -> serde::__private::Result - where - __E: serde::de::Error, - { - match __value { - b"hours" => serde::__private::Ok(__Field::__field0), - b"minutes" => serde::__private::Ok(__Field::__field1), - b"seconds" => serde::__private::Ok(__Field::__field2), - _ => serde::__private::Ok(__Field::__ignore), - } - } - } - impl<'de> serde::Deserialize<'de> for __Field { - #[inline] - fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result - where - __D: serde::Deserializer<'de>, - { - serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) - } - } - #[doc(hidden)] - struct __Visitor<'de> { - marker: serde::__private::PhantomData, - lifetime: serde::__private::PhantomData<&'de ()>, - } - impl<'de> serde::de::Visitor<'de> for __Visitor<'de> { - type Value = SqlxTypesTimeUtcOffset; - fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { - serde::__private::Formatter::write_str(__formatter, "struct SqlxTypesTimeUtcOffset") - } - #[inline] - fn visit_seq<__A>(self, mut __seq: __A) -> serde::__private::Result - where - __A: serde::de::SeqAccess<'de>, - { - let __field0 = match serde::de::SeqAccess::next_element::(&mut __seq)? { - serde::__private::Some(__value) => __value, - serde::__private::None => { - return serde::__private::Err(serde::de::Error::invalid_length(0usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); - } - }; - let __field1 = match serde::de::SeqAccess::next_element::(&mut __seq)? { - serde::__private::Some(__value) => __value, - serde::__private::None => { - return serde::__private::Err(serde::de::Error::invalid_length(1usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); - } - }; - let __field2 = match serde::de::SeqAccess::next_element::(&mut __seq)? { - serde::__private::Some(__value) => __value, - serde::__private::None => { - return serde::__private::Err(serde::de::Error::invalid_length(2usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); - } - }; - serde::__private::Ok(SqlxTypesTimeUtcOffset(match sqlx::types::time::UtcOffset::from_hms(__field0, __field1, __field2) { - Ok(value) => value, - Err(error) => { - return Err(serde::de::Error::custom(error)); - } - })) - } - #[inline] - fn visit_map<__A>(self, mut __map: __A) -> serde::__private::Result - where - __A: serde::de::MapAccess<'de>, - { - let mut __field0: serde::__private::Option = serde::__private::None; - let mut __field1: serde::__private::Option = serde::__private::None; - let mut __field2: serde::__private::Option = serde::__private::None; - while let serde::__private::Some(__key) = serde::de::MapAccess::next_key::<__Field>(&mut __map)? { - match __key { - __Field::__field0 => { - if serde::__private::Option::is_some(&__field0) { - return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("hours")); - } - __field0 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); - } - __Field::__field1 => { - if serde::__private::Option::is_some(&__field1) { - return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("minutes")); - } - __field1 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); - } - __Field::__field2 => { - if serde::__private::Option::is_some(&__field2) { - return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("seconds")); - } - __field2 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); - } - _ => { - let _ = serde::de::MapAccess::next_value::(&mut __map)?; - } - } - } - let __field0 = match __field0 { - serde::__private::Some(__field0) => __field0, - serde::__private::None => serde::__private::de::missing_field("hours")?, - }; - let __field1 = match __field1 { - serde::__private::Some(__field1) => __field1, - serde::__private::None => serde::__private::de::missing_field("minutes")?, - }; - let __field2 = match __field2 { - serde::__private::Some(__field2) => __field2, - serde::__private::None => serde::__private::de::missing_field("seconds")?, - }; - serde::__private::Ok(SqlxTypesTimeUtcOffset(match sqlx::types::time::UtcOffset::from_hms(__field0, __field1, __field2) { - Ok(value) => value, - Err(error) => { - return Err(serde::de::Error::custom(error)); - } - })) - } - } - #[doc(hidden)] - const FIELDS: &'static [&'static str] = &["hours", "minutes", "seconds"]; - serde::Deserializer::deserialize_struct( - __deserializer, - "SqlxTypesTimeUtcOffset", - FIELDS, - __Visitor { - marker: serde::__private::PhantomData::, - lifetime: serde::__private::PhantomData, - }, - ) - } -} - #[derive( Debug, Clone, @@ -2844,7 +2658,6 @@ pub struct SqlxTypesTimeOffsetDateTime(pub sqlx::types::time::OffsetDateTime); )] pub struct SqlxTypesTimePrimitiveDateTime(pub sqlx::types::time::PrimitiveDateTime); - #[derive( Debug, Clone, @@ -2855,60 +2668,631 @@ pub struct SqlxTypesTimePrimitiveDateTime(pub sqlx::types::time::PrimitiveDateTi postgresql_crud_types_macro_logic_reuse::PostgresqlBaseTypeTokensSqlxTypesDecimal, postgresql_crud_types_macro_logic_reuse::PostgresqlBaseTypeTokensWhereElementSqlxTypesDecimal, )] -pub struct SqlxTypesDecimal(pub sqlx::types::Decimal); - -// pub struct SqlxTypesBigDecimal(pub sqlx::types::BigDecimal); - - -// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimeOffsetDateTime(pub sqlx::postgres::types::PgRange); -// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimePrimitiveDateTime(pub sqlx::postgres::types::PgRange); -// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimeDate(pub sqlx::postgres::types::PgRange); -// pub struct SqlxPostgresTypesPgRangeSqlxTypesBigDecimal(pub sqlx::postgres::types::PgRange); - - -// pub struct SqlxPostgresTypesPgMoney(pub sqlx::postgres::types::PgMoney); -// pub struct SqlxPostgresTypesPgCiText(pub sqlx::postgres::types::PgCiText); - - - - -// pub struct SqlxTypesChronoDateTimeSqlxTypesChronoUtc(pub sqlx::types::chrono::DateTime); -// pub struct SqlxTypesChronoDateTimeSqlxTypesChronoLocal(pub sqlx::types::chrono::DateTime); - - - -// pub struct SqlxTypesUuidUuid(pub sqlx::types::uuid::Uuid); -// pub struct SqlxTypesIpnetworkIpNetwork(pub sqlx::types::ipnetwork::IpNetwork); -// pub struct StdNetIpAddr(pub std::net::IpAddr); -// pub struct SqlxTypesMacAddressMacAddress(pub sqlx::types::mac_address::MacAddress); -// pub struct SqlxTypesBitVec(pub sqlx::types::BitVec); - -// pub struct SerdeJsonValue(pub serde_json::Value); +pub struct SqlxTypesDecimal(pub sqlx::types::Decimal);//todo add try_new impl and custom checks(maybe even remove it). coz its not 100% equals to postgresql type https://docs.rs/sqlx/latest/sqlx/postgres/types/index.html -//////////////////////////////// -#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] -pub enum EncodeFormat { - Base64, - Hex, - Escape -} -impl std::fmt::Display for EncodeFormat { - fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self { - Self::Base64 => write!(formatter, "base64"), - Self::Hex => write!(formatter, "hex"), - Self::Escape => write!(formatter, "escape"), - } - } -} -impl std::default::Default for EncodeFormat { - fn default() -> Self { - Self::Base64 +#[derive( + Debug, + Clone, + PartialEq, + Eq, + postgresql_crud_types_macro_logic_reuse::PostgresqlBaseTypeTokensSqlxTypesBigDecimal, + postgresql_crud_types_macro_logic_reuse::PostgresqlBaseTypeTokensWhereElementSqlxTypesBigDecimal, +)] +pub struct SqlxTypesBigDecimal(pub sqlx::types::BigDecimal);//todo add try_new impl and custom checks. coz its not 100% equals to postgresql type https://docs.rs/sqlx/latest/sqlx/postgres/types/index.html +impl serde::Serialize for SqlxTypesBigDecimal { + fn serialize<__S>(&self, __serializer: __S) -> serde::__private::Result<__S::Ok, __S::Error> + where + __S: serde::Serializer, + { + let (bigint, exponent) = self.0.clone().into_bigint_and_exponent(); + let mut __serde_state = serde::Serializer::serialize_struct(__serializer, "SqlxTypesBigDecimal", false as usize + 1 + 1)?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "digits", &NumBigintBigInt(bigint))?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "scale", &exponent)?; + serde::ser::SerializeStruct::end(__serde_state) } } -impl crate::generate_postgresql_json_type::StdDefaultDefaultButStdOptionOptionIsAlwaysSomeAndStdVecVecAlwaysContainsOneElement for EncodeFormat { - fn std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element() -> Self { - ::core::default::Default::default() +impl<'de> serde::Deserialize<'de> for SqlxTypesBigDecimal { + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + #[allow(non_camel_case_types)] + #[doc(hidden)] + enum __Field { + __field0, + __field1, + __ignore, + } + #[doc(hidden)] + struct __FieldVisitor; + impl serde::de::Visitor<'_> for __FieldVisitor { + type Value = __Field; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "field identifier") + } + fn visit_u64<__E>(self, __value: u64) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + 0u64 => serde::__private::Ok(__Field::__field0), + 1u64 => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_str<__E>(self, __value: &str) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + "digits" => serde::__private::Ok(__Field::__field0), + "scale" => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_bytes<__E>(self, __value: &[u8]) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + b"digits" => serde::__private::Ok(__Field::__field0), + b"scale" => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + } + impl<'de> serde::Deserialize<'de> for __Field { + #[inline] + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) + } + } + #[doc(hidden)] + struct __Visitor<'de> { + marker: serde::__private::PhantomData, + lifetime: serde::__private::PhantomData<&'de ()>, + } + impl<'de> serde::de::Visitor<'de> for __Visitor<'de> { + type Value = SqlxTypesBigDecimal; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "struct SqlxTypesBigDecimal") + } + #[inline] + fn visit_seq<__A>(self, mut __seq: __A) -> serde::__private::Result + where + __A: serde::de::SeqAccess<'de>, + { + let __field0 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(0usize, &"struct SqlxTypesBigDecimal with 2 elements")); + } + }; + let __field1 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(1usize, &"struct SqlxTypesBigDecimal with 2 elements")); + } + }; + serde::__private::Ok(SqlxTypesBigDecimal(sqlx::types::BigDecimal::new(__field0.0, __field1))) + } + #[inline] + fn visit_map<__A>(self, mut __map: __A) -> serde::__private::Result + where + __A: serde::de::MapAccess<'de>, + { + let mut __field0: serde::__private::Option = serde::__private::None; + let mut __field1: serde::__private::Option = serde::__private::None; + while let serde::__private::Some(__key) = serde::de::MapAccess::next_key::<__Field>(&mut __map)? { + match __key { + __Field::__field0 => { + if serde::__private::Option::is_some(&__field0) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("digits")); + } + __field0 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + __Field::__field1 => { + if serde::__private::Option::is_some(&__field1) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("scale")); + } + __field1 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + _ => { + let _ = serde::de::MapAccess::next_value::(&mut __map)?; + } + } + } + let __field0 = match __field0 { + serde::__private::Some(__field0) => __field0, + serde::__private::None => serde::__private::de::missing_field("digits")?, + }; + let __field1 = match __field1 { + serde::__private::Some(__field1) => __field1, + serde::__private::None => serde::__private::de::missing_field("scale")?, + }; + serde::__private::Ok(SqlxTypesBigDecimal(sqlx::types::BigDecimal::new(__field0.0, __field1))) + } + } + #[doc(hidden)] + const FIELDS: &'static [&'static str] = &["digits", "scale"]; + serde::Deserializer::deserialize_struct( + __deserializer, + "SqlxTypesBigDecimal", + FIELDS, + __Visitor { + marker: serde::__private::PhantomData::, + lifetime: serde::__private::PhantomData, + }, + ) + } +} + +// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimeOffsetDateTime(pub sqlx::postgres::types::PgRange); +// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimePrimitiveDateTime(pub sqlx::postgres::types::PgRange); +// pub struct SqlxPostgresTypesPgRangeSqlxTypesTimeDate(pub sqlx::postgres::types::PgRange); +// pub struct SqlxPostgresTypesPgRangeSqlxTypesBigDecimal(pub sqlx::postgres::types::PgRange); + + +// pub struct SqlxPostgresTypesPgMoney(pub sqlx::postgres::types::PgMoney); +// pub struct SqlxPostgresTypesPgCiText(pub sqlx::postgres::types::PgCiText); + + + + +// pub struct SqlxTypesChronoDateTimeSqlxTypesChronoUtc(pub sqlx::types::chrono::DateTime); +// pub struct SqlxTypesChronoDateTimeSqlxTypesChronoLocal(pub sqlx::types::chrono::DateTime); + + + +// pub struct SqlxTypesUuidUuid(pub sqlx::types::uuid::Uuid); +// pub struct SqlxTypesIpnetworkIpNetwork(pub sqlx::types::ipnetwork::IpNetwork); +// pub struct StdNetIpAddr(pub std::net::IpAddr); +// pub struct SqlxTypesMacAddressMacAddress(pub sqlx::types::mac_address::MacAddress); +// pub struct SqlxTypesBitVec(pub sqlx::types::BitVec); + +// pub struct SerdeJsonValue(pub serde_json::Value); + +//////////////////////////////// +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +pub enum EncodeFormat { + Base64, + Hex, + Escape +} +impl std::fmt::Display for EncodeFormat { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match &self { + Self::Base64 => write!(formatter, "base64"), + Self::Hex => write!(formatter, "hex"), + Self::Escape => write!(formatter, "escape"), + } + } +} +impl std::default::Default for EncodeFormat { + fn default() -> Self { + Self::Base64 + } +} +impl crate::generate_postgresql_json_type::StdDefaultDefaultButStdOptionOptionIsAlwaysSomeAndStdVecVecAlwaysContainsOneElement for EncodeFormat { + fn std_default_default_but_std_option_option_is_always_some_and_std_vec_vec_always_contains_one_element() -> Self { + ::core::default::Default::default() + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, utoipa::ToSchema)] +pub struct SqlxTypesTimeUtcOffset(pub sqlx::types::time::UtcOffset); +impl serde::Serialize for SqlxTypesTimeUtcOffset { + fn serialize<__S>(&self, __serializer: __S) -> serde::__private::Result<__S::Ok, __S::Error> + where + __S: serde::Serializer, + { + let mut __serde_state = serde::Serializer::serialize_struct(__serializer, "SqlxTypesTimeUtcOffset", false as usize + 1 + 1 + 1)?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "hours", &self.0.whole_hours())?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "minutes", &self.0.minutes_past_hour())?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "seconds", &self.0.seconds_past_minute())?; + serde::ser::SerializeStruct::end(__serde_state) + } +} +impl<'de> serde::Deserialize<'de> for SqlxTypesTimeUtcOffset { + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + #[allow(non_camel_case_types)] + #[doc(hidden)] + enum __Field { + __field0, + __field1, + __field2, + __ignore, + } + #[doc(hidden)] + struct __FieldVisitor; + impl serde::de::Visitor<'_> for __FieldVisitor { + type Value = __Field; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "field identifier") + } + fn visit_u64<__E>(self, __value: u64) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + 0u64 => serde::__private::Ok(__Field::__field0), + 1u64 => serde::__private::Ok(__Field::__field1), + 2u64 => serde::__private::Ok(__Field::__field2), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_str<__E>(self, __value: &str) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + "hours" => serde::__private::Ok(__Field::__field0), + "minutes" => serde::__private::Ok(__Field::__field1), + "seconds" => serde::__private::Ok(__Field::__field2), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_bytes<__E>(self, __value: &[u8]) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + b"hours" => serde::__private::Ok(__Field::__field0), + b"minutes" => serde::__private::Ok(__Field::__field1), + b"seconds" => serde::__private::Ok(__Field::__field2), + _ => serde::__private::Ok(__Field::__ignore), + } + } + } + impl<'de> serde::Deserialize<'de> for __Field { + #[inline] + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) + } + } + #[doc(hidden)] + struct __Visitor<'de> { + marker: serde::__private::PhantomData, + lifetime: serde::__private::PhantomData<&'de ()>, + } + impl<'de> serde::de::Visitor<'de> for __Visitor<'de> { + type Value = SqlxTypesTimeUtcOffset; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "struct SqlxTypesTimeUtcOffset") + } + #[inline] + fn visit_seq<__A>(self, mut __seq: __A) -> serde::__private::Result + where + __A: serde::de::SeqAccess<'de>, + { + let __field0 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(0usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); + } + }; + let __field1 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(1usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); + } + }; + let __field2 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(2usize, &"struct SqlxTypesTimeUtcOffset with 3 elements")); + } + }; + serde::__private::Ok(SqlxTypesTimeUtcOffset(match sqlx::types::time::UtcOffset::from_hms(__field0, __field1, __field2) { + Ok(value) => value, + Err(error) => { + return Err(serde::de::Error::custom(error)); + } + })) + } + #[inline] + fn visit_map<__A>(self, mut __map: __A) -> serde::__private::Result + where + __A: serde::de::MapAccess<'de>, + { + let mut __field0: serde::__private::Option = serde::__private::None; + let mut __field1: serde::__private::Option = serde::__private::None; + let mut __field2: serde::__private::Option = serde::__private::None; + while let serde::__private::Some(__key) = serde::de::MapAccess::next_key::<__Field>(&mut __map)? { + match __key { + __Field::__field0 => { + if serde::__private::Option::is_some(&__field0) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("hours")); + } + __field0 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + __Field::__field1 => { + if serde::__private::Option::is_some(&__field1) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("minutes")); + } + __field1 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + __Field::__field2 => { + if serde::__private::Option::is_some(&__field2) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("seconds")); + } + __field2 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + _ => { + let _ = serde::de::MapAccess::next_value::(&mut __map)?; + } + } + } + let __field0 = match __field0 { + serde::__private::Some(__field0) => __field0, + serde::__private::None => serde::__private::de::missing_field("hours")?, + }; + let __field1 = match __field1 { + serde::__private::Some(__field1) => __field1, + serde::__private::None => serde::__private::de::missing_field("minutes")?, + }; + let __field2 = match __field2 { + serde::__private::Some(__field2) => __field2, + serde::__private::None => serde::__private::de::missing_field("seconds")?, + }; + serde::__private::Ok(SqlxTypesTimeUtcOffset(match sqlx::types::time::UtcOffset::from_hms(__field0, __field1, __field2) { + Ok(value) => value, + Err(error) => { + return Err(serde::de::Error::custom(error)); + } + })) + } + } + #[doc(hidden)] + const FIELDS: &'static [&'static str] = &["hours", "minutes", "seconds"]; + serde::Deserializer::deserialize_struct( + __deserializer, + "SqlxTypesTimeUtcOffset", + FIELDS, + __Visitor { + marker: serde::__private::PhantomData::, + lifetime: serde::__private::PhantomData, + }, + ) + } +} + +//todo pub or not for all - think +#[derive(Debug, Clone, PartialEq, Eq, utoipa::ToSchema)] +pub struct NumBigintBigInt(pub num_bigint::BigInt); +impl serde::Serialize for NumBigintBigInt { + fn serialize<__S>(&self, __serializer: __S) -> serde::__private::Result<__S::Ok, __S::Error> + where + __S: serde::Serializer, + { + let (sign, digits) = self.0.to_u32_digits(); + let mut __serde_state = serde::Serializer::serialize_struct(__serializer, "NumBigintBigInt", false as usize + 1 + 1)?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "sign", &NumBigintSign(sign))?; + serde::ser::SerializeStruct::serialize_field(&mut __serde_state, "digits", &digits)?; + serde::ser::SerializeStruct::end(__serde_state) + } +} +impl<'de> serde::Deserialize<'de> for NumBigintBigInt { + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + #[allow(non_camel_case_types)] + #[doc(hidden)] + enum __Field { + __field0, + __field1, + __ignore, + } + #[doc(hidden)] + struct __FieldVisitor; + impl serde::de::Visitor<'_> for __FieldVisitor { + type Value = __Field; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "field identifier") + } + fn visit_u64<__E>(self, __value: u64) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + 0u64 => serde::__private::Ok(__Field::__field0), + 1u64 => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_str<__E>(self, __value: &str) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + "sign" => serde::__private::Ok(__Field::__field0), + "digits" => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + fn visit_bytes<__E>(self, __value: &[u8]) -> serde::__private::Result + where + __E: serde::de::Error, + { + match __value { + b"sign" => serde::__private::Ok(__Field::__field0), + b"digits" => serde::__private::Ok(__Field::__field1), + _ => serde::__private::Ok(__Field::__ignore), + } + } + } + impl<'de> serde::Deserialize<'de> for __Field { + #[inline] + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + serde::Deserializer::deserialize_identifier(__deserializer, __FieldVisitor) + } + } + #[doc(hidden)] + struct __Visitor<'de> { + marker: serde::__private::PhantomData, + lifetime: serde::__private::PhantomData<&'de ()>, + } + impl<'de> serde::de::Visitor<'de> for __Visitor<'de> { + type Value = NumBigintBigInt; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "struct NumBigintBigInt") + } + #[inline] + fn visit_seq<__A>(self, mut __seq: __A) -> serde::__private::Result + where + __A: serde::de::SeqAccess<'de>, + { + let __field0 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => return serde::__private::Err(serde::de::Error::invalid_length(0usize, &"struct NumBigintBigInt with 2 elements")), + }; + let __field1 = match serde::de::SeqAccess::next_element::>(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => return serde::__private::Err(serde::de::Error::invalid_length(1usize, &"struct NumBigintBigInt with 2 elements")), + }; + serde::__private::Ok(NumBigintBigInt(num_bigint::BigInt::new(__field0.0, __field1))) + } + #[inline] + fn visit_map<__A>(self, mut __map: __A) -> serde::__private::Result + where + __A: serde::de::MapAccess<'de>, + { + let mut __field0: serde::__private::Option = serde::__private::None; + let mut __field1: serde::__private::Option> = serde::__private::None; + while let serde::__private::Some(__key) = serde::de::MapAccess::next_key::<__Field>(&mut __map)? { + match __key { + __Field::__field0 => { + if serde::__private::Option::is_some(&__field0) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("sign")); + } + __field0 = serde::__private::Some(serde::de::MapAccess::next_value::(&mut __map)?); + } + __Field::__field1 => { + if serde::__private::Option::is_some(&__field1) { + return serde::__private::Err(<__A::Error as serde::de::Error>::duplicate_field("digits")); + } + __field1 = serde::__private::Some(serde::de::MapAccess::next_value::>(&mut __map)?); + } + _ => { + let _ = serde::de::MapAccess::next_value::(&mut __map)?; + } + } + } + let __field0 = match __field0 { + serde::__private::Some(__field0) => __field0, + serde::__private::None => serde::__private::de::missing_field("sign")?, + }; + let __field1 = match __field1 { + serde::__private::Some(__field1) => __field1, + serde::__private::None => serde::__private::de::missing_field("digits")?, + }; + serde::__private::Ok(NumBigintBigInt(num_bigint::BigInt::new(__field0.0, __field1))) + } + } + #[doc(hidden)] + const FIELDS: &'static [&'static str] = &["sign", "digits"]; + serde::Deserializer::deserialize_struct( + __deserializer, + "NumBigintBigInt", + FIELDS, + __Visitor { + marker: serde::__private::PhantomData::, + lifetime: serde::__private::PhantomData, + }, + ) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, utoipa::ToSchema)] +pub struct NumBigintSign(pub num_bigint::Sign); +impl serde::Serialize for NumBigintSign { + fn serialize<__S>(&self, __serializer: __S) -> serde::__private::Result<__S::Ok, __S::Error> + where + __S: serde::Serializer, + { + serde::Serializer::serialize_newtype_struct( + __serializer, + "NumBigintSign", + match self.0 { + num_bigint::Sign::Minus => "Minus", + num_bigint::Sign::NoSign => "NoSign", + num_bigint::Sign::Plus => "Plus", + }, + ) + } +} +impl<'de> serde::Deserialize<'de> for NumBigintSign { + fn deserialize<__D>(__deserializer: __D) -> serde::__private::Result + where + __D: serde::Deserializer<'de>, + { + #[doc(hidden)] + struct __Visitor<'de> { + marker: serde::__private::PhantomData, + lifetime: serde::__private::PhantomData<&'de ()>, + } + impl<'de> serde::de::Visitor<'de> for __Visitor<'de> { + type Value = NumBigintSign; + fn expecting(&self, __formatter: &mut serde::__private::Formatter<'_>) -> serde::__private::fmt::Result { + serde::__private::Formatter::write_str(__formatter, "tuple struct NumBigintSign") + } + #[inline] + fn visit_newtype_struct<__E>(self, __e: __E) -> serde::__private::Result + where + __E: serde::Deserializer<'de>, + { + let __field0: std::string::String = ::deserialize(__e)?; + serde::__private::Ok(NumBigintSign(match __field0.as_str() { + "Minus" => num_bigint::Sign::Minus, + "NoSign" => num_bigint::Sign::NoSign, + "Plus" => num_bigint::Sign::Plus, + _ => { + return Err(serde::de::Error::custom("unsupported value, supported: Minus, NoSign, Plus")); + } + })) + } + #[inline] + fn visit_seq<__A>(self, mut __seq: __A) -> serde::__private::Result + where + __A: serde::de::SeqAccess<'de>, + { + let __field0 = match serde::de::SeqAccess::next_element::(&mut __seq)? { + serde::__private::Some(__value) => __value, + serde::__private::None => { + return serde::__private::Err(serde::de::Error::invalid_length(0usize, &"tuple struct NumBigintSign with 1 element")); + } + }; + serde::__private::Ok(NumBigintSign(match __field0.as_str() { + "Minus" => num_bigint::Sign::Minus, + "NoSign" => num_bigint::Sign::NoSign, + "Plus" => num_bigint::Sign::Plus, + _ => { + return Err(serde::de::Error::custom("unsupported value, supported: Minus, NoSign, Plus")); + } + })) + } + } + serde::Deserializer::deserialize_newtype_struct( + __deserializer, + "NumBigintSign", + __Visitor { + marker: serde::__private::PhantomData::, + lifetime: serde::__private::PhantomData, + }, + ) } } /////////////////////////////////////////////////////// \ No newline at end of file diff --git a/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_type.rs b/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_type.rs index 9940dd5a7..f904af0c8 100644 --- a/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_type.rs +++ b/postgresql_crud/postgresql_crud_common/src/postgresql_type/postgresql_type.rs @@ -907,4 +907,33 @@ impl crate::CreateTableColumnQueryPart for SqlxTypesDecimalAsPostgresqlNumericNo fn create_table_column_query_part(column: &dyn std::fmt::Display, _: std::primitive::bool) -> impl std::fmt::Display { format!("{column} {NUMERIC} {NOT_NULL}") } +} + +#[derive( + Debug, + Clone, + PartialEq, + serde::Serialize, + serde::Deserialize, + postgresql_crud_types_macro_logic_reuse::PostgresqlTypeTokens +)] +pub struct SqlxTypesBigDecimalAsPostgresqlNumeric(crate::postgresql_type::postgresql_base_type::StdOptionOptionSqlxTypesBigDecimal); +impl crate::CreateTableColumnQueryPart for SqlxTypesBigDecimalAsPostgresqlNumeric { + fn create_table_column_query_part(column: &dyn std::fmt::Display, _: std::primitive::bool) -> impl std::fmt::Display { + format!("{column} {NUMERIC}") + } +} +#[derive( + Debug, + Clone, + PartialEq, + serde::Serialize, + serde::Deserialize, + postgresql_crud_types_macro_logic_reuse::PostgresqlTypeTokens +)] +pub struct SqlxTypesBigDecimalAsPostgresqlNumericNotNull(crate::postgresql_type::postgresql_base_type::SqlxTypesBigDecimal); +impl crate::CreateTableColumnQueryPart for SqlxTypesBigDecimalAsPostgresqlNumericNotNull { + fn create_table_column_query_part(column: &dyn std::fmt::Display, _: std::primitive::bool) -> impl std::fmt::Display { + format!("{column} {NUMERIC} {NOT_NULL}") + } } \ No newline at end of file