Skip to content

Commit

Permalink
next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
kuqmua committed Dec 27, 2024
1 parent 265b9c9 commit 70f5b45
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 116 deletions.
143 changes: 84 additions & 59 deletions common/src/repositories_types/server/routes/api/example/example.http
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,38 @@ content-type: application/json
commit: 72a7f5c066a08a77fb91e75abee9f6e79e00e2b8

{
"std_primitive_i64_as_postgresql_big_serial_not_null": {
"logical_operator": "Or",
"value": [
{
"Equal": {
"logical_operator": "Or",
"value": 1
}
}
# ,
# {
# "GreaterThan": {
# "logical_operator": "Or",
# "value": 0
# }
# },
# {
# "Between": {
# "logical_operator": "Or",
# "start": 0,
# "end": 0
# }
# },
# {
# "In": {
# "logical_operator": "Or",
# "value": [
# 0
# ]
# }
# }
]
},
# "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
# ]
# }
# }
# ]
# },
# "pg_range_std_primitive_i64_as_postgresql_int8_range": {
# "logical_operator": "Or",
# "value": [
Expand Down Expand Up @@ -141,43 +140,69 @@ commit: 72a7f5c066a08a77fb91e75abee9f6e79e00e2b8
# }
# },
# {
# "IsNull": {
# "logical_operator": "Or"
# }
# }
# ]
# },
# "pg_range_std_primitive_i64_as_postgresql_int8_range_not_null": {
# "logical_operator": "Or",
# "value": [
# {
# "Equal": {
# "StrictlyToLeftOfRange": {
# "logical_operator": "Or",
# "value": {
# "start": {
# "Included": 10
# "Included": 0
# },
# "end": {
# "Excluded": 501
# "Included": 0
# }
# }
# }
# },
# {
# "IsNull": {
# "logical_operator": "Or"
# }
# }
# # ,
# # {
# # "ValueIsContainedWithinRange": {
# # "logical_operator": "Or",
# # "value": 0
# # }
# # },
# # {
# # "ContainsAnotherRange": {
# # "logical_operator": "Or",
# # "value": 0
# # }
# # }
# ]
# },
"pg_range_std_primitive_i64_as_postgresql_int8_range_not_null": {
"logical_operator": "Or",
"value": [
# {
# "Equal": {
# "logical_operator": "Or",
# "value": {
# "start": {
# "Included": 0
# },
# "end": {
# "Included": 0
# }
# }
# }
# },
# {
# "ValueIsContainedWithinRange": {
# "logical_operator": "Or",
# "value": 0
# }
# },
# {
# "ContainsAnotherRange": {
# "logical_operator": "Or",
# "value": 0
# }
# }
# ,
{
"StrictlyToLeftOfRange": {
"logical_operator": "Or",
"value": {
"start": {
"Included": 100
},
"end": {
"Included": 150
}
}
}
}
]
},
"select": [
{
"std_primitive_i64_as_postgresql_big_serial_not_null": null
Expand Down
3 changes: 2 additions & 1 deletion naming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ naming_macros::generate_upper_camel_and_snake_case_stringified_and_token_stream!
["is", "empty"],
["length", "is", "negative"],
["start", "is", "equal", "to", "end"],
["start"]
["start"],
["strictly", "to", "left", "of", "range"]
]);

#[derive(Debug, Clone, Copy)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4442,13 +4442,46 @@ pub fn postgresql_base_type_tokens_where_element_sqlx_postgres_types_pg_range_st
)
};

let strictly_to_left_of_range_upper_camel_case = naming::StrictlyToLeftOfRangeUpperCamelCase;
let postgresql_type_tokens_where_element_strictly_to_left_of_range_token_stream = generate_postgresql_type_tokens_where_element_variant_token_stream(
&ident,
&strictly_to_left_of_range_upper_camel_case,
&is_nullable,
ShouldWhereElementFieldsBePublic::True,
&quote::quote!{pub #value_snake_case: #ident},
&quote::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
},
&quote::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!(),
})
}
},
&quote::quote!{
#query_snake_case = #query_snake_case.bind(self.#value_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,
&value_is_contained_within_range_upper_camel_case,
&contains_another_range_upper_camel_case,
&strictly_to_left_of_range_upper_camel_case,
]
);
quote::quote! {
Expand All @@ -4457,6 +4490,7 @@ pub fn postgresql_base_type_tokens_where_element_sqlx_postgres_types_pg_range_st
#postgresql_type_tokens_where_element_equal_token_stream
#postgresql_type_tokens_where_element_value_is_contained_within_range_token_stream
#postgresql_type_tokens_where_element_contains_another_range_token_stream
#postgresql_type_tokens_where_element_strictly_to_left_of_range_token_stream
#postgresql_type_tokens_where_element_token_stream
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,62 +310,6 @@ impl<'de> serde::Deserialize<'de> for SqlxPostgresTypesPgRangeStdPrimitiveI64 {

// In PostgreSQL, INT8RANGE is a range type that is used to represent a range of 64-bit integers (BIGINT). The range types in PostgreSQL can be used with various operations that allow you to filter, compare, and manipulate the ranges. Below is a comprehensive list of WHERE operations that you can use with the INT8RANGE type.

// 1. Checking if a value is contained within a range
// You can use the @> (contains) operator to check if a value is contained within an INT8RANGE.

// sql
// Копировать код
// WHERE range_column @> 10
// This will return rows where the range contains the value 10.

// 2. Checking if a range contains another range
// You can use the @> operator to check if one range contains another.

// sql
// Копировать код
// WHERE range_column @> '[5, 15]'
// This will return rows where range_column contains the range [5, 15].

// 3. Checking if a value is strictly inside a range (not touching boundaries)
// You can use the << (strictly contained by) operator to check if a value is strictly inside the range.

// sql
// Копировать код
// WHERE 10 << range_column
// This will return rows where range_column does not include the boundaries and strictly contains the value 10.

// 4. Checking if a range is strictly contained by another range
// You can use the << operator to check if one range is strictly contained within another range.

// sql
// Копировать код
// WHERE range_column << '[5, 15]'
// This will return rows where range_column is strictly contained within [5, 15].

// 5. Checking if a range overlaps with another range
// You can use the && (overlaps) operator to check if two ranges overlap.

// sql
// Копировать код
// WHERE range_column && '[10, 20]'
// This will return rows where range_column overlaps with the range [10, 20].

// 6. Checking if a range does not overlap with another range
// You can use the && operator in a negation form to check if two ranges do not overlap.

// sql
// Копировать код
// WHERE NOT (range_column && '[10, 20]')
// This will return rows where range_column does not overlap with the range [10, 20].

// 7. Checking if a range is left of another range (non-overlapping)
// You can use the &< (left of) operator to check if one range is entirely to the left of another.

// sql
// Копировать код
// WHERE range_column &< '[5, 15]'
// This will return rows where range_column is completely to the left of the range [5, 15].

// 8. Checking if a range is right of another range (non-overlapping)
// You can use the &> (right of) operator to check if one range is entirely to the right of another.

Expand Down

0 comments on commit 70f5b45

Please sign in to comment.