mongory 0.6.3 → 0.7.0
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +42 -0
- data/README.md +82 -176
- data/Rakefile +77 -0
- data/SUBMODULE_INTEGRATION.md +325 -0
- data/docs/advanced_usage.md +40 -0
- data/docs/clang_bridge.md +69 -0
- data/docs/field_names.md +30 -0
- data/docs/migration.md +30 -0
- data/docs/performance.md +61 -0
- data/examples/benchmark.rb +98 -19
- data/ext/mongory_ext/extconf.rb +91 -0
- data/ext/mongory_ext/mongory-core/LICENSE +3 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h +105 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +206 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +82 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +95 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/table.h +108 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/value.h +175 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +76 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core.h +12 -0
- data/ext/mongory_ext/mongory-core/src/foundations/array.c +246 -0
- data/ext/mongory_ext/mongory-core/src/foundations/array_private.h +18 -0
- data/ext/mongory_ext/mongory-core/src/foundations/config.c +406 -0
- data/ext/mongory_ext/mongory-core/src/foundations/config_private.h +30 -0
- data/ext/mongory_ext/mongory-core/src/foundations/error.c +30 -0
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +298 -0
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +65 -0
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.h +49 -0
- data/ext/mongory_ext/mongory-core/src/foundations/table.c +458 -0
- data/ext/mongory_ext/mongory-core/src/foundations/value.c +459 -0
- data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c +309 -0
- data/ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h +47 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +161 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +115 -0
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +210 -0
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h +83 -0
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +539 -0
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +125 -0
- data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.c +144 -0
- data/ext/mongory_ext/mongory-core/src/matchers/existance_matcher.h +48 -0
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +121 -0
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.h +46 -0
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +199 -0
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h +46 -0
- data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c +334 -0
- data/ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h +97 -0
- data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +196 -0
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +107 -0
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +50 -0
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +55 -0
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +23 -0
- data/ext/mongory_ext/mongory_ext.c +635 -0
- data/lib/mongory/c_query_builder.rb +44 -0
- data/lib/mongory/query_builder.rb +8 -0
- data/lib/mongory/utils/context.rb +7 -0
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +7 -0
- data/mongory.gemspec +10 -4
- data/scripts/build_with_core.sh +292 -0
- metadata +69 -4
@@ -0,0 +1,107 @@
|
|
1
|
+
#ifndef MONGORY_MATCHER_EXPLAINABLE_C
|
2
|
+
#define MONGORY_MATCHER_EXPLAINABLE_C
|
3
|
+
|
4
|
+
#include "matcher_explainable.h"
|
5
|
+
#include "../foundations/string_buffer.h"
|
6
|
+
#include "base_matcher.h"
|
7
|
+
#include "composite_matcher.h"
|
8
|
+
#include "literal_matcher.h"
|
9
|
+
#include <stdio.h>
|
10
|
+
|
11
|
+
char *mongory_matcher_title(mongory_matcher *matcher, mongory_memory_pool *pool) {
|
12
|
+
mongory_string_buffer *buffer = mongory_string_buffer_new(pool);
|
13
|
+
mongory_string_buffer_append(buffer, matcher->name);
|
14
|
+
mongory_string_buffer_append(buffer, ": ");
|
15
|
+
mongory_value *condition = matcher->condition;
|
16
|
+
mongory_string_buffer_append(buffer, condition->to_str(condition, pool));
|
17
|
+
return mongory_string_buffer_cstr(buffer);
|
18
|
+
}
|
19
|
+
|
20
|
+
char *mongory_matcher_title_with_field(mongory_matcher *matcher, mongory_memory_pool *pool) {
|
21
|
+
mongory_string_buffer *buffer = mongory_string_buffer_new(pool);
|
22
|
+
mongory_field_matcher *field_matcher = (mongory_field_matcher *)matcher;
|
23
|
+
mongory_string_buffer_appendf(buffer, "Field: \"%s\", to match: ", field_matcher->field);
|
24
|
+
mongory_value *condition = field_matcher->literal.base.condition;
|
25
|
+
mongory_string_buffer_append(buffer, condition->to_str(condition, pool));
|
26
|
+
return mongory_string_buffer_cstr(buffer);
|
27
|
+
}
|
28
|
+
|
29
|
+
static inline char *mongory_matcher_tail_connection(int count, int total) {
|
30
|
+
if (count == (total - 1)) {
|
31
|
+
return "└─ ";
|
32
|
+
} else if (total == 0) {
|
33
|
+
return "";
|
34
|
+
}
|
35
|
+
return "├─ ";
|
36
|
+
}
|
37
|
+
|
38
|
+
static inline char *mongory_matcher_indent_connection(int count, int total) {
|
39
|
+
if (count < total) {
|
40
|
+
return "│ ";
|
41
|
+
} else if (total == 0) {
|
42
|
+
return "";
|
43
|
+
}
|
44
|
+
return " ";
|
45
|
+
}
|
46
|
+
|
47
|
+
void mongory_matcher_base_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
48
|
+
char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
|
49
|
+
ctx->count++;
|
50
|
+
char *title = mongory_matcher_title(matcher, ctx->pool);
|
51
|
+
printf("%s%s%s\n", ctx->prefix, connection, title);
|
52
|
+
}
|
53
|
+
|
54
|
+
void mongory_matcher_traverse_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
55
|
+
mongory_composite_matcher *composite = (mongory_composite_matcher *)matcher;
|
56
|
+
mongory_array *children = composite->children;
|
57
|
+
int total = (int)children->count;
|
58
|
+
for (int i = 0; i < total; i++) {
|
59
|
+
mongory_matcher *child = (mongory_matcher *)children->get(children, i);
|
60
|
+
child->explain(child, ctx);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
void mongory_matcher_composite_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
65
|
+
mongory_matcher_base_explain(matcher, ctx);
|
66
|
+
mongory_string_buffer *buffer = mongory_string_buffer_new(ctx->pool);
|
67
|
+
mongory_string_buffer_appendf(buffer, "%s%s", ctx->prefix, mongory_matcher_indent_connection(ctx->count, ctx->total));
|
68
|
+
mongory_matcher_explain_context child_ctx = {
|
69
|
+
.pool = ctx->pool,
|
70
|
+
.count = 0,
|
71
|
+
.total = matcher->sub_count,
|
72
|
+
.prefix = mongory_string_buffer_cstr(buffer),
|
73
|
+
};
|
74
|
+
mongory_matcher_traverse_explain(matcher, &child_ctx);
|
75
|
+
}
|
76
|
+
|
77
|
+
static inline void mongory_matcher_literal_shared_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
78
|
+
mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
|
79
|
+
mongory_string_buffer *buffer = mongory_string_buffer_new(ctx->pool);
|
80
|
+
mongory_string_buffer_appendf(buffer, "%s%s", ctx->prefix, mongory_matcher_indent_connection(ctx->count, ctx->total));
|
81
|
+
mongory_matcher_explain_context child_ctx = {
|
82
|
+
.pool = ctx->pool,
|
83
|
+
.count = 0,
|
84
|
+
.total = matcher->sub_count,
|
85
|
+
.prefix = mongory_string_buffer_cstr(buffer),
|
86
|
+
};
|
87
|
+
if (literal->array_record_matcher) {
|
88
|
+
literal->array_record_matcher->explain(literal->array_record_matcher, &child_ctx);
|
89
|
+
} else {
|
90
|
+
literal->delegate_matcher->explain(literal->delegate_matcher, &child_ctx);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
void mongory_matcher_literal_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
95
|
+
mongory_matcher_base_explain(matcher, ctx);
|
96
|
+
mongory_matcher_literal_shared_explain(matcher, ctx);
|
97
|
+
}
|
98
|
+
|
99
|
+
void mongory_matcher_field_explain(mongory_matcher *matcher, mongory_matcher_explain_context *ctx) {
|
100
|
+
char *connection = mongory_matcher_tail_connection(ctx->count, ctx->total);
|
101
|
+
char *title = mongory_matcher_title_with_field(matcher, ctx->pool);
|
102
|
+
ctx->count++;
|
103
|
+
printf("%s%s%s\n", ctx->prefix, connection, title);
|
104
|
+
mongory_matcher_literal_shared_explain(matcher, ctx);
|
105
|
+
}
|
106
|
+
|
107
|
+
#endif /* MONGORY_MATCHER_EXPLAINABLE_C */
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#ifndef MONGORY_MATCHER_EXPLAINABLE_H
|
2
|
+
#define MONGORY_MATCHER_EXPLAINABLE_H
|
3
|
+
|
4
|
+
#include "mongory-core/matchers/matcher.h"
|
5
|
+
#include <mongory-core.h>
|
6
|
+
|
7
|
+
/**
|
8
|
+
* @brief Context for explaining a matcher.
|
9
|
+
*
|
10
|
+
* @param pool The pool to use for the explanation.
|
11
|
+
* @param count The count of the matcher.
|
12
|
+
* @param total The total number of matchers.
|
13
|
+
* @param prefix The prefix to use for the explanation.
|
14
|
+
*/
|
15
|
+
typedef struct mongory_matcher_explain_context {
|
16
|
+
mongory_memory_pool *pool;
|
17
|
+
int count;
|
18
|
+
int total;
|
19
|
+
char *prefix;
|
20
|
+
} mongory_matcher_explain_context;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @brief Function pointer type for a matcher's explanation logic.
|
24
|
+
*
|
25
|
+
* @param matcher The matcher to explain.
|
26
|
+
* @param ctx The context to use for the explanation.
|
27
|
+
*/
|
28
|
+
typedef void (*mongory_matcher_explain_func)(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @brief Explains a matcher.
|
32
|
+
* @param matcher The matcher to explain.
|
33
|
+
* @param ctx The context to use for the explanation.
|
34
|
+
*/
|
35
|
+
|
36
|
+
char *mongory_matcher_title(struct mongory_matcher *matcher, mongory_memory_pool *pool);
|
37
|
+
|
38
|
+
char *mongory_matcher_title_with_field(struct mongory_matcher *matcher, mongory_memory_pool *pool);
|
39
|
+
|
40
|
+
void mongory_matcher_base_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
41
|
+
|
42
|
+
void mongory_matcher_composite_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
43
|
+
|
44
|
+
void mongory_matcher_traverse_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
45
|
+
|
46
|
+
void mongory_matcher_field_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
47
|
+
|
48
|
+
void mongory_matcher_literal_explain(struct mongory_matcher *matcher, mongory_matcher_explain_context *ctx);
|
49
|
+
|
50
|
+
#endif /* MONGORY_MATCHER_EXPLAINABLE_H */
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#ifndef MONGORY_MATCHER_TRAVERSABLE_C
|
2
|
+
#define MONGORY_MATCHER_TRAVERSABLE_C
|
3
|
+
|
4
|
+
#include "matcher_traversable.h"
|
5
|
+
#include "base_matcher.h"
|
6
|
+
#include "composite_matcher.h"
|
7
|
+
#include "literal_matcher.h"
|
8
|
+
|
9
|
+
bool mongory_matcher_leaf_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
|
10
|
+
bool continue_traverse = ctx->callback(matcher, ctx);
|
11
|
+
if (!continue_traverse)
|
12
|
+
return false;
|
13
|
+
ctx->count++;
|
14
|
+
return true;
|
15
|
+
}
|
16
|
+
|
17
|
+
bool mongory_matcher_composite_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
|
18
|
+
if (!mongory_matcher_leaf_traverse(matcher, ctx))
|
19
|
+
return false;
|
20
|
+
mongory_composite_matcher *composite = (mongory_composite_matcher *)matcher;
|
21
|
+
mongory_array *children = composite->children;
|
22
|
+
int total = (int)children->count;
|
23
|
+
mongory_matcher_traverse_context child_ctx = {
|
24
|
+
.pool = ctx->pool,
|
25
|
+
.level = ctx->level + 1,
|
26
|
+
.count = 0,
|
27
|
+
.total = total,
|
28
|
+
.acc = ctx->acc,
|
29
|
+
.callback = ctx->callback,
|
30
|
+
};
|
31
|
+
|
32
|
+
for (int i = 0; i < total; i++) {
|
33
|
+
mongory_matcher *child = (mongory_matcher *)children->get(children, i);
|
34
|
+
if (!child->traverse(child, &child_ctx))
|
35
|
+
return false;
|
36
|
+
}
|
37
|
+
return true;
|
38
|
+
}
|
39
|
+
|
40
|
+
bool mongory_matcher_literal_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx) {
|
41
|
+
if (!mongory_matcher_leaf_traverse(matcher, ctx))
|
42
|
+
return false;
|
43
|
+
mongory_literal_matcher *literal = (mongory_literal_matcher *)matcher;
|
44
|
+
mongory_matcher *next_matcher = literal->array_record_matcher ? literal->array_record_matcher : literal->delegate_matcher;
|
45
|
+
mongory_matcher_traverse_context child_ctx = {
|
46
|
+
.pool = ctx->pool,
|
47
|
+
.level = ctx->level + 1,
|
48
|
+
.count = 0,
|
49
|
+
.total = 1,
|
50
|
+
.acc = ctx->acc,
|
51
|
+
.callback = ctx->callback,
|
52
|
+
};
|
53
|
+
return next_matcher->traverse(next_matcher, &child_ctx);
|
54
|
+
}
|
55
|
+
#endif /* MONGORY_MATCHER_TRAVERSABLE_C */
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef MONGORY_MATCHER_TRAVERSABLE_H
|
2
|
+
#define MONGORY_MATCHER_TRAVERSABLE_H
|
3
|
+
|
4
|
+
#include "mongory-core/matchers/matcher.h"
|
5
|
+
|
6
|
+
typedef struct mongory_matcher_traverse_context {
|
7
|
+
mongory_memory_pool *pool;
|
8
|
+
int level;
|
9
|
+
int count;
|
10
|
+
int total;
|
11
|
+
void *acc;
|
12
|
+
bool (*callback)(mongory_matcher *matcher, struct mongory_matcher_traverse_context *ctx);
|
13
|
+
} mongory_matcher_traverse_context;
|
14
|
+
|
15
|
+
typedef bool (*mongory_matcher_traverse_func)(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
|
16
|
+
|
17
|
+
bool mongory_matcher_leaf_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
|
18
|
+
|
19
|
+
bool mongory_matcher_composite_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
|
20
|
+
|
21
|
+
bool mongory_matcher_literal_traverse(mongory_matcher *matcher, mongory_matcher_traverse_context *ctx);
|
22
|
+
|
23
|
+
#endif /* MONGORY_MATCHER_TRAVERSABLE_H */
|