mongory 2.1.1-x86_64-linux → 2.2.0-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/README.md +45 -74
  4. data/docs/clang_bridge.md +2 -2
  5. data/docs/performance.md +28 -1
  6. data/lib/core/2.6/mongory_ext.so +0 -0
  7. data/lib/core/2.7/mongory_ext.so +0 -0
  8. data/lib/core/3.0/mongory_ext.so +0 -0
  9. data/lib/core/3.1/mongory_ext.so +0 -0
  10. data/lib/core/3.2/mongory_ext.so +0 -0
  11. data/lib/core/3.3/mongory_ext.so +0 -0
  12. data/lib/core/3.4/mongory_ext.so +0 -0
  13. data/lib/core/4.0/mongory_ext.so +0 -0
  14. data/lib/mongory/converters/abstract_converter.rb +5 -5
  15. data/lib/mongory/converters/converted.rb +0 -4
  16. data/lib/mongory/converters/key_converter.rb +13 -36
  17. data/lib/mongory/converters/value_converter.rb +4 -4
  18. data/lib/mongory/matchers.rb +8 -7
  19. data/lib/mongory/query_builder.rb +9 -0
  20. data/lib/mongory/utils/context.rb +0 -6
  21. data/lib/mongory/utils/singleton_builder.rb +1 -4
  22. data/lib/mongory/version.rb +1 -1
  23. data/lib/mongory.rb +0 -1
  24. data/mongory.gemspec +13 -12
  25. data/script/coverage.rb +84 -0
  26. metadata +9 -54
  27. data/ext/mongory_ext/extconf.rb +0 -115
  28. data/ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h +0 -62
  29. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +0 -122
  30. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +0 -217
  31. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +0 -82
  32. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +0 -115
  33. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +0 -127
  34. data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +0 -175
  35. data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +0 -103
  36. data/ext/mongory_ext/mongory-core/include/mongory-core.h +0 -12
  37. data/ext/mongory_ext/mongory-core/src/foundations/array.c +0 -336
  38. data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +0 -20
  39. data/ext/mongory_ext/mongory-core/src/foundations/config.c +0 -335
  40. data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +0 -49
  41. data/ext/mongory_ext/mongory-core/src/foundations/error.c +0 -48
  42. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +0 -406
  43. data/ext/mongory_ext/mongory-core/src/foundations/memory_pool_private.h +0 -45
  44. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +0 -117
  45. data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +0 -43
  46. data/ext/mongory_ext/mongory-core/src/foundations/table.c +0 -502
  47. data/ext/mongory_ext/mongory-core/src/foundations/utils.c +0 -206
  48. data/ext/mongory_ext/mongory-core/src/foundations/utils.h +0 -77
  49. data/ext/mongory_ext/mongory-core/src/foundations/value.c +0 -548
  50. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +0 -193
  51. data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +0 -117
  52. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +0 -241
  53. data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +0 -83
  54. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +0 -730
  55. data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +0 -131
  56. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c +0 -158
  57. data/ext/mongory_ext/mongory-core/src/matchers/existence_matcher.h +0 -48
  58. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +0 -199
  59. data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +0 -58
  60. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c +0 -204
  61. data/ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.h +0 -47
  62. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +0 -483
  63. data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +0 -46
  64. data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +0 -529
  65. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +0 -117
  66. data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +0 -29
  67. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +0 -61
  68. data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +0 -23
  69. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.c +0 -416
  70. data/ext/mongory_ext/mongory-core/src/matchers/value_matcher.h +0 -97
  71. data/ext/mongory_ext/mongory_ext.c +0 -66
  72. data/ext/mongory_ext/mongory_ext_internal.h +0 -74
  73. data/ext/mongory_ext/rb_mongory_adapters.c +0 -140
  74. data/ext/mongory_ext/rb_mongory_matcher.c +0 -440
  75. data/ext/mongory_ext/rb_mongory_value.c +0 -327
@@ -1,204 +0,0 @@
1
- /**
2
- * @file implicit_array_matcher.c
3
- * @brief Implements a versatile matcher for arrays, handling various condition
4
- * types. This is an internal implementation file for the matcher module.
5
- *
6
- * This matcher can interpret conditions as:
7
- * - A table: Parsed for operators like $elemMatch or implicit field conditions
8
- * on array elements.
9
- * - A regex: Creates an $elemMatch to match array elements against the regex.
10
- * - A literal: Creates an $elemMatch to check for equality with elements.
11
- * - Another array: Checks for whole-array equality.
12
- * It often constructs a composite OR matcher to combine these possibilities.
13
- */
14
- #include "implicit_array_matcher.h"
15
- #include "../foundations/config_private.h"
16
- #include "../foundations/utils.h" // For mongory_try_parse_int
17
- #include "base_matcher.h" // For mongory_matcher_base_new
18
- #include "compare_matcher.h" // For mongory_matcher_equal_new
19
- #include "composite_matcher.h" // For mongory_matcher_composite_new, $elemMatch, table_cond_new, or_match
20
- #include "value_matcher.h" // Potentially used by table_cond_new
21
- #include "mongory-core/foundations/table.h"
22
- #include "mongory-core/foundations/value.h"
23
- #include <mongory-core.h> // General include
24
- #include <stdio.h> // For NULL
25
- #include <string.h> // For strcmp
26
-
27
- /**
28
- * @struct mongory_matcher_implicit_array_parse_table_context
29
- * @brief Context used when parsing a table condition for array record matching.
30
- *
31
- * Helps separate parts of the condition table:
32
- * - `parsed_table`: For explicit operators (e.g., $size, $all if implemented)
33
- * or indexed conditions.
34
- * - `elem_match_table`: For conditions that should apply to individual elements
35
- * via an implicit or explicit $elemMatch.
36
- */
37
- typedef struct mongory_matcher_implicit_array_parse_table_context {
38
- mongory_table *parsed_table; /**< Stores operator or indexed conditions. */
39
- mongory_table *elem_match_table; /**< Stores conditions for element matching. */
40
- } mongory_matcher_implicit_array_parse_table_context;
41
-
42
- /**
43
- * @brief Callback to parse a condition table for array matching.
44
- *
45
- * Iterates through the main condition table:
46
- * - If `key` is "$elemMatch" and `value` is a table, its contents are added to
47
- * `context->elem_match_table`.
48
- * - If `key` is an element-level comparison operator (`$gt`, `$gte`, `$lt`,
49
- * `$lte`, `$regex` with its `$options`, or non-array `$eq`), it's added to
50
- * `context->elem_match_table`.
51
- * - If `key` starts with '$' (container operator like `$size`, `$in`, `$nin`,
52
- * `$every`, `$ne`, or array `$eq`) or is a valid integer index, it's added to
53
- * `context->parsed_table`.
54
- * - Otherwise (plain field name), it's considered part of an implicit element
55
- * match and added to `context->elem_match_table`.
56
- *
57
- * @param key Current key in the condition table.
58
- * @param value Current value for the key.
59
- * @param acc Pointer to `mongory_matcher_implicit_array_parse_table_context`.
60
- * @return Always true to continue.
61
- */
62
- static inline bool mongory_is_elem_match_operator(char *key, mongory_value *value) {
63
- if (strcmp(key, "$gt") == 0 || strcmp(key, "$gte") == 0 ||
64
- strcmp(key, "$lt") == 0 || strcmp(key, "$lte") == 0 ||
65
- strcmp(key, "$regex") == 0 || strcmp(key, "$options") == 0) {
66
- return true;
67
- }
68
- if (strcmp(key, "$eq") == 0) {
69
- return value == NULL || value->type != MONGORY_TYPE_ARRAY;
70
- }
71
- return false;
72
- }
73
-
74
- static inline bool mongory_matcher_implicit_array_parse_table_foreach(char *key, mongory_value *value, void *acc) {
75
- mongory_matcher_implicit_array_parse_table_context *context = (mongory_matcher_implicit_array_parse_table_context *)acc;
76
- mongory_table *parsed_table_for_operators = context->parsed_table;
77
- mongory_table *table_for_elem_match_conditions = context->elem_match_table;
78
-
79
- if (strcmp(key, "$elemMatch") == 0 && value->type == MONGORY_TYPE_TABLE && value->data.t != NULL) {
80
- // Explicit $elemMatch: iterate its sub-table and add to elem_match_table
81
- mongory_table_merge(table_for_elem_match_conditions, value->data.t);
82
- } else if (mongory_is_elem_match_operator(key, value)) {
83
- // Element-level comparison operators apply to array elements via $elemMatch
84
- table_for_elem_match_conditions->set(table_for_elem_match_conditions, key, value);
85
- } else if (*key == '$' || mongory_try_parse_int(key, NULL)) {
86
- // Array-level operator (like $size, $in, $nin, $every, $ne) or numeric index: goes to parsed_table
87
- parsed_table_for_operators->set(parsed_table_for_operators, key, value);
88
- } else {
89
- // Regular field name: implies a condition on elements, goes to
90
- // elem_match_table
91
- table_for_elem_match_conditions->set(table_for_elem_match_conditions, key, value);
92
- }
93
- return true;
94
- }
95
-
96
- /**
97
- * @brief Parses a table `condition` intended for array matching.
98
- *
99
- * Separates the condition into parts for direct array operations (like $size)
100
- * and parts for matching individual elements (implicit or explicit $elemMatch).
101
- * If any element-matching conditions are found, they are grouped under an
102
- * "$elemMatch" key in the returned `parsed_table`.
103
- *
104
- * @param condition The `mongory_value` (must be a table) to parse.
105
- * @return A new `mongory_value` (table) containing the parsed and restructured
106
- * condition. Returns NULL if input is not a table or on allocation failure.
107
- */
108
- static inline mongory_value *mongory_matcher_implicit_array_parse_table(mongory_memory_pool *pool, mongory_value *condition) {
109
- if (!pool) {
110
- return NULL;
111
- }
112
- if (!condition || !condition->data.t) {
113
- mongory_error_set(pool, MONGORY_ERROR_INVALID_TYPE, "Expected condition to be a table, got a non-table value");
114
- return NULL; // Invalid input
115
- }
116
- mongory_table *parsed_table = mongory_table_new(pool);
117
- mongory_table *elem_match_sub_table = mongory_table_new(pool);
118
-
119
- if (!parsed_table || !elem_match_sub_table) {
120
- return NULL;
121
- }
122
-
123
- mongory_matcher_implicit_array_parse_table_context parse_ctx = {parsed_table, elem_match_sub_table};
124
- mongory_table *original_condition_table = condition->data.t;
125
-
126
- original_condition_table->each(original_condition_table, &parse_ctx,
127
- mongory_matcher_implicit_array_parse_table_foreach);
128
- if (pool->error != NULL) {
129
- return NULL;
130
- }
131
-
132
- if (elem_match_sub_table->count > 0) {
133
- // If there were conditions for element matching, add them as an $elemMatch
134
- // clause to the main parsed_table.
135
- mongory_value *wrapped_elem = mongory_value_wrap_t(pool, elem_match_sub_table);
136
- if (!wrapped_elem || !parsed_table->set(parsed_table, "$elemMatch", wrapped_elem)) {
137
- return NULL;
138
- }
139
- }
140
- // If elem_match_sub_table is empty, it's not added. The original parsed_table
141
- // (which might contain $size etc.) is returned.
142
- return mongory_value_wrap_t(pool, parsed_table);
143
- }
144
-
145
- /**
146
- * @brief Main constructor for `mongory_matcher_implicit_array_new`.
147
- *
148
- * Constructs a two-part matcher (often combined with OR):
149
- * - `left`: Handles element-wise conditions (like $elemMatch from various
150
- * condition types).
151
- * - `right`: Handles whole-array equality if the original `condition` was an
152
- * array.
153
- *
154
- * If `right` is NULL (i.e., original `condition` was not an array), only the
155
- * `left` matcher is returned. Otherwise, a composite OR matcher is created
156
- * with `left` and `right` as children.
157
- *
158
- * @param pool Memory pool.
159
- * @param condition The condition to apply to arrays.
160
- * @return The constructed implicit_array_matcher, or NULL on failure.
161
- */
162
- mongory_matcher *mongory_matcher_implicit_array_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx) {
163
- if (!condition || !pool)
164
- return NULL;
165
- mongory_compile_budget saved = mongory_compile_budget_begin();
166
- mongory_matcher *result = NULL;
167
- switch (condition->type) {
168
- case MONGORY_TYPE_TABLE: {
169
- mongory_value *parsed = mongory_matcher_implicit_array_parse_table(pool, condition);
170
- if (parsed && pool->error == NULL) {
171
- result = mongory_matcher_condition_new(pool, parsed, extern_ctx);
172
- }
173
- break;
174
- }
175
- case MONGORY_TYPE_ARRAY: {
176
- mongory_value *or_cond = MG_ARRAY_WRAP(pool, 2,
177
- MG_TABLE_WRAP(pool, 1, "$eq", condition),
178
- MG_TABLE_WRAP(pool, 1, "$elemMatch",
179
- MG_TABLE_WRAP(pool, 1, "$eq", condition)
180
- )
181
- );
182
- if (or_cond && pool->error == NULL) {
183
- result = mongory_matcher_or_new(pool, or_cond, extern_ctx);
184
- }
185
- break;
186
- }
187
- case MONGORY_TYPE_REGEX: {
188
- mongory_value *re_cond = MG_TABLE_WRAP(pool, 1, "$regex", condition);
189
- if (re_cond && pool->error == NULL) {
190
- result = mongory_matcher_elem_match_new(pool, re_cond, extern_ctx);
191
- }
192
- break;
193
- }
194
- default: { // Literals (string, int, bool, etc.)
195
- mongory_value *eq_cond = MG_TABLE_WRAP(pool, 1, "$eq", condition);
196
- if (eq_cond && pool->error == NULL) {
197
- result = mongory_matcher_elem_match_new(pool, eq_cond, extern_ctx);
198
- }
199
- break;
200
- }
201
- }
202
- mongory_compile_budget_end(saved);
203
- return result;
204
- }
@@ -1,47 +0,0 @@
1
- #ifndef MONGORY_MATCHER_IMPLICIT_ARRAY_H
2
- #define MONGORY_MATCHER_IMPLICIT_ARRAY_H
3
-
4
- /**
5
- * @file implicit_array_matcher.h
6
- * @brief Defines the constructor for a matcher that handles complex conditions
7
- * against arrays. This is an internal header for the matcher module.
8
- *
9
- * This matcher is more specialized than simple `$elemMatch` or `$every`. It can
10
- * interpret a condition that might be a direct value to find, a regex to match
11
- * elements, or a table defining multiple criteria for array elements (similar
12
- * to an implicit `$elemMatch` with that table). It can also handle checking if
13
- * an input array is equal to a condition array.
14
- */
15
-
16
- #include "base_matcher.h"
17
- #include "mongory-core/foundations/memory_pool.h"
18
- #include "mongory-core/foundations/value.h"
19
- #include "mongory-core/matchers/matcher.h" // For mongory_matcher structure
20
-
21
- /**
22
- * @brief Creates an "array record" matcher.
23
- *
24
- * This matcher is designed to apply various types of conditions to an input
25
- * array or its elements. The behavior depends on the `condition`'s type:
26
- * - If `condition` is a table: It's parsed. Keys like `$elemMatch` are handled
27
- * specifically. Other field-value pairs in the table are typically wrapped
28
- * into an implicit `$elemMatch` condition that applies to elements of the
29
- * target array.
30
- * - If `condition` is a regex: It effectively creates an `$elemMatch` where
31
- * each element of the target array is matched against this regex.
32
- * - If `condition` is a simple literal (string, number, bool): It creates an
33
- * `$elemMatch` where elements are checked for equality against this literal.
34
- * - If `condition` itself is an array: It creates a matcher that checks if the
35
- * target array is equal to this condition array.
36
- *
37
- * The resulting matcher might be a composite of several internal matchers (e.g.,
38
- * an OR between element matching and whole-array equality).
39
- *
40
- * @param pool Memory pool for allocation.
41
- * @param condition A `mongory_value` representing the condition to apply to an
42
- * array or its elements.
43
- * @return A new array record matcher, or NULL on failure.
44
- */
45
- mongory_matcher *mongory_matcher_implicit_array_new(mongory_memory_pool *pool, mongory_value *condition, void *extern_ctx);
46
-
47
- #endif /* MONGORY_MATCHER_IMPLICIT_ARRAY_H */