mongory 0.9.1-aarch64-linux → 2.0.1-aarch64-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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +115 -420
- data/SUBMODULE_INTEGRATION.md +7 -20
- data/docs/clang_bridge.md +28 -63
- data/docs/migration.md +17 -0
- data/docs/performance.md +14 -51
- data/examples/benchmark.rb +10 -26
- data/ext/mongory_ext/extconf.rb +1 -1
- data/ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h +62 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h +31 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h +3 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/foundations/memory_pool.h +20 -0
- data/ext/mongory_ext/mongory-core/include/mongory-core/matchers/matcher.h +31 -4
- data/ext/mongory_ext/mongory-core/src/foundations/array.c +48 -6
- data/ext/mongory_ext/mongory-core/src/foundations/config.c +30 -2
- data/ext/mongory_ext/mongory-core/src/foundations/error.c +10 -0
- data/ext/mongory_ext/mongory-core/src/foundations/memory_pool.c +78 -19
- data/ext/mongory_ext/mongory-core/src/foundations/string_buffer.c +73 -19
- data/ext/mongory_ext/mongory-core/src/foundations/table.c +8 -3
- data/ext/mongory_ext/mongory-core/src/foundations/utils.c +44 -55
- data/ext/mongory_ext/mongory-core/src/foundations/utils.h +7 -0
- data/ext/mongory_ext/mongory-core/src/foundations/value.c +3 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.c +68 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +14 -0
- data/ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c +9 -4
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c +132 -29
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +1 -1
- data/ext/mongory_ext/mongory-core/src/matchers/{existance_matcher.c → existence_matcher.c} +10 -12
- data/ext/mongory_ext/mongory-core/src/matchers/{existance_matcher.h → existence_matcher.h} +4 -4
- data/ext/mongory_ext/mongory-core/src/matchers/external_matcher.c +18 -6
- data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.c → implicit_array_matcher.c} +57 -38
- data/ext/mongory_ext/mongory-core/src/matchers/{array_record_matcher.h → implicit_array_matcher.h} +5 -5
- data/ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c +8 -10
- data/ext/mongory_ext/mongory-core/src/matchers/matcher.c +337 -96
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c +59 -21
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h +7 -1
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c +4 -4
- data/ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h +1 -1
- data/ext/mongory_ext/mongory-core/src/matchers/{literal_matcher.c → value_matcher.c} +104 -60
- data/ext/mongory_ext/mongory-core/src/matchers/{literal_matcher.h → value_matcher.h} +13 -13
- data/ext/mongory_ext/mongory_ext.c +2 -2
- data/ext/mongory_ext/mongory_ext_internal.h +2 -3
- data/ext/mongory_ext/{rb_mongory_cmatcher.c → rb_mongory_matcher.c} +145 -91
- data/ext/mongory_ext/rb_mongory_value.c +67 -0
- data/lib/core/2.6/mongory_ext.so +0 -0
- data/lib/core/2.7/mongory_ext.so +0 -0
- data/lib/core/3.0/mongory_ext.so +0 -0
- data/lib/core/3.1/mongory_ext.so +0 -0
- data/lib/core/3.2/mongory_ext.so +0 -0
- data/lib/core/3.3/mongory_ext.so +0 -0
- data/lib/core/3.4/mongory_ext.so +0 -0
- data/lib/core/4.0/mongory_ext.so +0 -0
- data/lib/generators/mongory/install/templates/initializer.rb.erb +0 -5
- data/lib/generators/mongory/matcher/templates/matcher.rb.erb +4 -15
- data/lib/mongory/converters/condition_converter.rb +1 -1
- data/lib/mongory/converters/converted.rb +28 -6
- data/lib/mongory/converters/key_converter.rb +2 -0
- data/lib/mongory/matcher.rb +50 -0
- data/lib/mongory/matchers/abstract_matcher.rb +18 -192
- data/lib/mongory/matchers.rb +68 -84
- data/lib/mongory/query_builder.rb +29 -42
- data/lib/mongory/utils/context.rb +10 -15
- data/lib/mongory/utils/tree_renderer.rb +98 -0
- data/lib/mongory/utils.rb +2 -67
- data/lib/mongory/version.rb +1 -1
- data/lib/mongory.rb +9 -59
- data/script/bench.rb +54 -0
- data/scripts/build_with_core.sh +0 -1
- metadata +13 -37
- data/lib/mongory/c_matcher.rb +0 -57
- data/lib/mongory/c_query_builder.rb +0 -44
- data/lib/mongory/matchers/abstract_multi_matcher.rb +0 -150
- data/lib/mongory/matchers/and_matcher.rb +0 -73
- data/lib/mongory/matchers/array_record_matcher.rb +0 -105
- data/lib/mongory/matchers/elem_match_matcher.rb +0 -57
- data/lib/mongory/matchers/eq_matcher.rb +0 -48
- data/lib/mongory/matchers/every_matcher.rb +0 -56
- data/lib/mongory/matchers/exists_matcher.rb +0 -53
- data/lib/mongory/matchers/field_matcher.rb +0 -160
- data/lib/mongory/matchers/gt_matcher.rb +0 -41
- data/lib/mongory/matchers/gte_matcher.rb +0 -41
- data/lib/mongory/matchers/hash_condition_matcher.rb +0 -80
- data/lib/mongory/matchers/in_matcher.rb +0 -84
- data/lib/mongory/matchers/literal_matcher.rb +0 -126
- data/lib/mongory/matchers/lt_matcher.rb +0 -41
- data/lib/mongory/matchers/lte_matcher.rb +0 -41
- data/lib/mongory/matchers/ne_matcher.rb +0 -39
- data/lib/mongory/matchers/nin_matcher.rb +0 -64
- data/lib/mongory/matchers/not_matcher.rb +0 -40
- data/lib/mongory/matchers/or_matcher.rb +0 -69
- data/lib/mongory/matchers/present_matcher.rb +0 -55
- data/lib/mongory/matchers/regex_matcher.rb +0 -109
- data/lib/mongory/matchers/size_matcher.rb +0 -54
- data/lib/mongory/query_matcher.rb +0 -93
- data/lib/mongory/rails.rb +0 -15
- data/lib/mongory/utils/debugger.rb +0 -125
- data/lib/mongory/utils/rails_patch.rb +0 -22
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mongory
|
|
4
|
+
module Utils
|
|
5
|
+
# Renders structured explain_tree and trace_tree Hash structures to STDOUT.
|
|
6
|
+
module TreeRenderer
|
|
7
|
+
RESULT_LABELS = {
|
|
8
|
+
pass: 'Matched',
|
|
9
|
+
fail: 'Dismatch',
|
|
10
|
+
skip: 'Skipped'
|
|
11
|
+
}.freeze
|
|
12
|
+
|
|
13
|
+
COLOR_RESULT_LABELS = {
|
|
14
|
+
pass: "\e[30;42mMatched\e[0m",
|
|
15
|
+
fail: "\e[30;41mDismatch\e[0m",
|
|
16
|
+
skip: "\e[30;43mSkipped\e[0m"
|
|
17
|
+
}.freeze
|
|
18
|
+
|
|
19
|
+
module_function
|
|
20
|
+
|
|
21
|
+
# Prints a structured explain_tree Hash to STDOUT.
|
|
22
|
+
#
|
|
23
|
+
# @param node [Hash] root explain_tree node
|
|
24
|
+
# @param prefix [String] indentation prefix
|
|
25
|
+
# @param is_last [Boolean] whether node is last sibling
|
|
26
|
+
# @param is_root [Boolean] whether node is root
|
|
27
|
+
# @return [void]
|
|
28
|
+
def print_explain(node, prefix = '', is_last: true, is_root: true)
|
|
29
|
+
return unless node
|
|
30
|
+
|
|
31
|
+
connector = explain_connector(is_root: is_root, is_last: is_last)
|
|
32
|
+
puts "#{prefix}#{connector}#{explain_title(node)}"
|
|
33
|
+
|
|
34
|
+
children = node[:children] || []
|
|
35
|
+
next_prefix = explain_next_prefix(prefix, is_root: is_root, is_last: is_last)
|
|
36
|
+
last_index = children.length - 1
|
|
37
|
+
children.each_with_index do |child, index|
|
|
38
|
+
print_explain(child, next_prefix, is_last: index == last_index, is_root: false)
|
|
39
|
+
end
|
|
40
|
+
nil
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def explain_connector(is_root:, is_last:)
|
|
44
|
+
return '' if is_root
|
|
45
|
+
|
|
46
|
+
is_last ? '└─ ' : '├─ '
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def explain_next_prefix(prefix, is_root:, is_last:)
|
|
50
|
+
return prefix if is_root
|
|
51
|
+
|
|
52
|
+
"#{prefix}#{is_last ? ' ' : '│ '}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Prints a structured trace_tree Hash to STDOUT.
|
|
56
|
+
#
|
|
57
|
+
# @param node [Hash] root trace_tree node
|
|
58
|
+
# @param level [Integer] indentation depth
|
|
59
|
+
# @param colorful [Boolean] whether to colorize result labels
|
|
60
|
+
# @return [void]
|
|
61
|
+
def print_trace(node, level = 0, colorful: true)
|
|
62
|
+
return unless node
|
|
63
|
+
|
|
64
|
+
indent = ' ' * level
|
|
65
|
+
puts "#{indent}#{trace_line(node, colorful: colorful)}"
|
|
66
|
+
(node[:children] || []).each do |child|
|
|
67
|
+
print_trace(child, level + 1, colorful: colorful)
|
|
68
|
+
end
|
|
69
|
+
nil
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def explain_title(node)
|
|
73
|
+
if node.key?(:field)
|
|
74
|
+
"Field: #{node[:field].inspect}, to match: #{node[:condition].inspect}"
|
|
75
|
+
else
|
|
76
|
+
"#{node[:name]}: #{node[:condition].inspect}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def trace_line(node, colorful: true)
|
|
81
|
+
result = node[:result]
|
|
82
|
+
labels = colorful ? COLOR_RESULT_LABELS : RESULT_LABELS
|
|
83
|
+
res_label = labels.fetch(result, result.to_s)
|
|
84
|
+
parts = ["#{node[:name]}: #{res_label}"]
|
|
85
|
+
parts << "field: #{node[:field].inspect}" if node.key?(:field)
|
|
86
|
+
parts << "condition: #{node[:condition].inspect}"
|
|
87
|
+
parts << "record: #{format_record(node)}" unless result == :skip
|
|
88
|
+
parts.join(', ')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def format_record(node)
|
|
92
|
+
return 'Nothing' unless node.key?(:record)
|
|
93
|
+
|
|
94
|
+
node[:record].inspect
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
data/lib/mongory/utils.rb
CHANGED
|
@@ -1,76 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'date'
|
|
4
3
|
require_relative 'utils/singleton_builder'
|
|
5
|
-
require_relative 'utils/
|
|
4
|
+
require_relative 'utils/tree_renderer'
|
|
6
5
|
require_relative 'utils/context'
|
|
7
6
|
|
|
8
7
|
module Mongory
|
|
9
|
-
# Utility
|
|
10
|
-
#
|
|
11
|
-
# Includes blank checking, present checking,
|
|
12
|
-
# and class-level instance method caching.
|
|
8
|
+
# Utility namespace for shared Mongory internals (`Context`, `TreeRenderer`, `SingletonBuilder`).
|
|
13
9
|
module Utils
|
|
14
|
-
# When included, also extends the including class with ClassMethods.
|
|
15
|
-
# And record which class include this module.
|
|
16
|
-
#
|
|
17
|
-
# @param base [Class, Module]
|
|
18
|
-
def self.included(base)
|
|
19
|
-
base.extend(ClassMethods)
|
|
20
|
-
super
|
|
21
|
-
included_classes << base
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Where to record classes that include Utils.
|
|
25
|
-
#
|
|
26
|
-
# @return [Array]
|
|
27
|
-
def self.included_classes
|
|
28
|
-
@included_classes ||= []
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Checks if an object is "present".
|
|
32
|
-
# Inverse of {#is_blank?}.
|
|
33
|
-
#
|
|
34
|
-
# @param obj [Object]
|
|
35
|
-
# @return [Boolean]
|
|
36
|
-
def is_present?(obj)
|
|
37
|
-
!is_blank?(obj)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# Determines whether an object is considered "blank".
|
|
41
|
-
# Nil, false, empty string/array/hash are blank.
|
|
42
|
-
#
|
|
43
|
-
# @param obj [Object]
|
|
44
|
-
# @return [Boolean]
|
|
45
|
-
def is_blank?(obj)
|
|
46
|
-
case obj
|
|
47
|
-
when false, nil
|
|
48
|
-
true
|
|
49
|
-
when Hash, Array, String, Set
|
|
50
|
-
obj.empty?
|
|
51
|
-
else
|
|
52
|
-
false
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# Class-level methods injected via Utils.
|
|
57
|
-
module ClassMethods
|
|
58
|
-
# Defines a lazily-evaluated, memoized instance method.
|
|
59
|
-
#
|
|
60
|
-
# @param name [Symbol] the method name
|
|
61
|
-
# @yield block to compute the value
|
|
62
|
-
# @return [void]
|
|
63
|
-
#
|
|
64
|
-
# @example
|
|
65
|
-
# define_instance_cache_method(:expensive_thing) { compute_something }
|
|
66
|
-
def define_instance_cache_method(name, &block)
|
|
67
|
-
instance_key = :"@#{name}"
|
|
68
|
-
define_method(name) do
|
|
69
|
-
return instance_variable_get(instance_key) if instance_variable_defined?(instance_key)
|
|
70
|
-
|
|
71
|
-
instance_variable_set(instance_key, instance_exec(&block))
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
10
|
end
|
|
76
11
|
end
|
data/lib/mongory/version.rb
CHANGED
data/lib/mongory.rb
CHANGED
|
@@ -7,11 +7,8 @@ require 'singleton'
|
|
|
7
7
|
require_relative 'mongory/version'
|
|
8
8
|
require_relative 'mongory/utils'
|
|
9
9
|
require_relative 'mongory/matchers'
|
|
10
|
-
require_relative 'mongory/query_matcher'
|
|
11
|
-
require_relative 'mongory/query_builder'
|
|
12
10
|
require_relative 'mongory/query_operator'
|
|
13
11
|
require_relative 'mongory/converters'
|
|
14
|
-
require_relative 'mongory/rails' if defined?(Rails::Railtie)
|
|
15
12
|
require_relative 'mongory/mongoid' if defined?(Mongoid)
|
|
16
13
|
|
|
17
14
|
# Main namespace for Mongory DSL and configuration.
|
|
@@ -29,8 +26,6 @@ module Mongory
|
|
|
29
26
|
class Error < StandardError; end
|
|
30
27
|
class TypeError < Error; end
|
|
31
28
|
|
|
32
|
-
@c_extension_by_default = false
|
|
33
|
-
|
|
34
29
|
# Yields Mongory for configuration and freezes key components.
|
|
35
30
|
#
|
|
36
31
|
# @example Configure converters
|
|
@@ -61,7 +56,6 @@ module Mongory
|
|
|
61
56
|
def self.freeze
|
|
62
57
|
data_converter.freeze
|
|
63
58
|
condition_converter.freeze
|
|
64
|
-
@debugger = Utils::Debugger.instance
|
|
65
59
|
Matchers.freeze
|
|
66
60
|
super
|
|
67
61
|
end
|
|
@@ -80,33 +74,20 @@ module Mongory
|
|
|
80
74
|
@condition_converter ||= Converters::ConditionConverter.instance
|
|
81
75
|
end
|
|
82
76
|
|
|
83
|
-
# Returns the debugger instance.
|
|
84
|
-
#
|
|
85
|
-
# @return [Utils::Debugger]
|
|
86
|
-
def self.debugger
|
|
87
|
-
@debugger ||= Utils::Debugger.instance
|
|
88
|
-
end
|
|
89
|
-
|
|
90
77
|
# Builds a new query over the given record set.
|
|
91
|
-
# Uses `CQueryBuilder` when `enable_c_extension_by_default!` is enabled and the C extension is available;
|
|
92
|
-
# otherwise uses `QueryBuilder`.
|
|
93
78
|
#
|
|
94
79
|
# @param records [Enumerable] any enumerable object (Array, AR::Relation, etc.)
|
|
95
|
-
# @return [QueryBuilder
|
|
80
|
+
# @return [QueryBuilder] a new query builder
|
|
96
81
|
def self.build_query(records)
|
|
97
|
-
|
|
98
|
-
builder_class.new(records)
|
|
82
|
+
QueryBuilder.new(records)
|
|
99
83
|
end
|
|
100
84
|
|
|
101
85
|
# Builds a new matcher for the given condition.
|
|
102
|
-
# Uses `CMatcher` when `enable_c_extension_by_default!` is enabled and the C extension is available;
|
|
103
|
-
# otherwise uses `QueryMatcher`.
|
|
104
86
|
#
|
|
105
87
|
# @param condition [Hash] the query condition
|
|
106
|
-
# @return [
|
|
88
|
+
# @return [Matcher] a new matcher
|
|
107
89
|
def self.build_matcher(condition)
|
|
108
|
-
|
|
109
|
-
matcher_class.new(condition)
|
|
90
|
+
Matcher.new(condition)
|
|
110
91
|
end
|
|
111
92
|
|
|
112
93
|
# Registers a class to support `.mongory` query DSL.
|
|
@@ -128,51 +109,20 @@ module Mongory
|
|
|
128
109
|
Matchers.enable_symbol_snippets!
|
|
129
110
|
end
|
|
130
111
|
|
|
131
|
-
# Enables using the C extension (`CQueryBuilder`) by default when building queries
|
|
132
|
-
# via `Mongory.build_query` or `.mongory`.
|
|
133
|
-
#
|
|
134
|
-
# Automatically falls back to the pure Ruby `QueryBuilder` if the C extension is unavailable.
|
|
135
|
-
#
|
|
136
|
-
# @return [Boolean] true if C extension is available and enabled by default
|
|
137
|
-
def self.enable_c_extension_by_default!
|
|
138
|
-
@c_extension_by_default = !defined?(Mongory::CMatcher).nil?
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
singleton_class.alias_method :use_c_extension_by_default!, :enable_c_extension_by_default!
|
|
142
|
-
|
|
143
|
-
# Disables using the C extension by default, reverting `.mongory` and `Mongory.build_query`
|
|
144
|
-
# to the pure Ruby `QueryBuilder`.
|
|
145
|
-
#
|
|
146
|
-
# @return [void]
|
|
147
|
-
def self.disable_c_extension_by_default!
|
|
148
|
-
@c_extension_by_default = false
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
# Returns whether the C extension is used by default for queries.
|
|
152
|
-
#
|
|
153
|
-
# @return [Boolean]
|
|
154
|
-
def self.c_extension_by_default?
|
|
155
|
-
@c_extension_by_default == true && !defined?(Mongory::CMatcher).nil?
|
|
156
|
-
end
|
|
157
|
-
|
|
158
112
|
# Adds a `#mongory` method to the target class via inclusion.
|
|
159
113
|
#
|
|
160
114
|
# Typically used internally by `Mongory.register(...)`.
|
|
161
115
|
module ClassExtention
|
|
162
116
|
# Returns a query builder scoped to `self`.
|
|
163
117
|
#
|
|
164
|
-
# @return [QueryBuilder
|
|
118
|
+
# @return [QueryBuilder]
|
|
165
119
|
def mongory
|
|
166
120
|
Mongory.build_query(self)
|
|
167
121
|
end
|
|
168
122
|
end
|
|
169
123
|
end
|
|
170
124
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
require_relative 'mongory/c_matcher'
|
|
176
|
-
rescue LoadError => e
|
|
177
|
-
warn("Mongory C extension is disabled because mongory_ext is not loaded: #{e.message}")
|
|
178
|
-
end
|
|
125
|
+
abi = RUBY_VERSION.split('.').first(2).join('.')
|
|
126
|
+
require_relative "core/#{abi}/mongory_ext"
|
|
127
|
+
require_relative 'mongory/matcher'
|
|
128
|
+
require_relative 'mongory/query_builder'
|
data/script/bench.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'benchmark'
|
|
4
|
+
require_relative '../lib/mongory'
|
|
5
|
+
|
|
6
|
+
Mongory.register(Array)
|
|
7
|
+
Mongory.enable_symbol_snippets!
|
|
8
|
+
|
|
9
|
+
N = 100_000
|
|
10
|
+
ROUNDS = 5
|
|
11
|
+
|
|
12
|
+
records = Array.new(N) do |i|
|
|
13
|
+
{
|
|
14
|
+
'age' => 10 + (i % 50),
|
|
15
|
+
'status' => (i % 3).zero? ? 'active' : 'inactive'
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
puts "Ruby: #{RUBY_VERSION} (#{RUBY_PLATFORM}), records=#{N}, rounds=#{ROUNDS}"
|
|
20
|
+
|
|
21
|
+
def bench(label)
|
|
22
|
+
# Warmup
|
|
23
|
+
yield
|
|
24
|
+
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
25
|
+
count = 0
|
|
26
|
+
ROUNDS.times { count = yield }
|
|
27
|
+
elapsed_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000.0) / ROUNDS
|
|
28
|
+
ns_per_rec = (elapsed_ms * 1_000_000.0) / N
|
|
29
|
+
puts format(
|
|
30
|
+
'%<label>-34s %<ms>8.2f ms / 100k (%<ns>6.1f ns/rec, matched=%<count>d)',
|
|
31
|
+
label: label,
|
|
32
|
+
ms: elapsed_ms,
|
|
33
|
+
ns: ns_per_rec,
|
|
34
|
+
count: count
|
|
35
|
+
)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
bench('Plain Ruby (simple)') do
|
|
39
|
+
records.count { |r| r['age'].is_a?(Numeric) && r['age'] >= 18 }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
simple_m = Mongory::Matcher.new({ age: { :$gte => 18 } })
|
|
43
|
+
bench('Mongory::Matcher (simple)') do
|
|
44
|
+
records.count { |r| simple_m.match?(r) }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
bench('Plain Ruby ($or)') do
|
|
48
|
+
records.count { |r| (r['age'].is_a?(Numeric) && r['age'] >= 18) || r['status'] == 'active' }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
or_m = Mongory::Matcher.new({ :$or => [{ age: { :$gte => 18 } }, { status: 'active' }] })
|
|
52
|
+
bench('Mongory::Matcher ($or)') do
|
|
53
|
+
records.count { |r| or_m.match?(r) }
|
|
54
|
+
end
|
data/scripts/build_with_core.sh
CHANGED
|
@@ -99,7 +99,6 @@ init_submodules() {
|
|
|
99
99
|
# Function to build mongory-core if needed
|
|
100
100
|
build_core() {
|
|
101
101
|
# mongory-rb 直接由 extconf.rb 編譯 mongory-core 的源碼,不需要獨立建置靜態庫
|
|
102
|
-
# 同時避免觸發 mongory-core 的 CMake(其需要 cJSON 僅用於測試)
|
|
103
102
|
log $YELLOW "Skipping mongory-core standalone build (not required for mongory-rb)"
|
|
104
103
|
}
|
|
105
104
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongory
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: aarch64-linux
|
|
6
6
|
authors:
|
|
7
7
|
- koten0224
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A Mongo-like in-memory query DSL for Ruby
|
|
14
14
|
email:
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- examples/benchmark.rb
|
|
37
37
|
- ext/mongory_ext/extconf.rb
|
|
38
38
|
- ext/mongory_ext/mongory-core/include/mongory-core.h
|
|
39
|
+
- ext/mongory_ext/mongory-core/include/mongory-core/adapters/json.h
|
|
39
40
|
- ext/mongory_ext/mongory-core/include/mongory-core/foundations/array.h
|
|
40
41
|
- ext/mongory_ext/mongory-core/include/mongory-core/foundations/config.h
|
|
41
42
|
- ext/mongory_ext/mongory-core/include/mongory-core/foundations/error.h
|
|
@@ -56,31 +57,31 @@ files:
|
|
|
56
57
|
- ext/mongory_ext/mongory-core/src/foundations/utils.c
|
|
57
58
|
- ext/mongory_ext/mongory-core/src/foundations/utils.h
|
|
58
59
|
- ext/mongory_ext/mongory-core/src/foundations/value.c
|
|
59
|
-
- ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.c
|
|
60
|
-
- ext/mongory_ext/mongory-core/src/matchers/array_record_matcher.h
|
|
61
60
|
- ext/mongory_ext/mongory-core/src/matchers/base_matcher.c
|
|
62
61
|
- ext/mongory_ext/mongory-core/src/matchers/base_matcher.h
|
|
63
62
|
- ext/mongory_ext/mongory-core/src/matchers/compare_matcher.c
|
|
64
63
|
- ext/mongory_ext/mongory-core/src/matchers/compare_matcher.h
|
|
65
64
|
- ext/mongory_ext/mongory-core/src/matchers/composite_matcher.c
|
|
66
65
|
- ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h
|
|
67
|
-
- ext/mongory_ext/mongory-core/src/matchers/
|
|
68
|
-
- ext/mongory_ext/mongory-core/src/matchers/
|
|
66
|
+
- ext/mongory_ext/mongory-core/src/matchers/existence_matcher.c
|
|
67
|
+
- ext/mongory_ext/mongory-core/src/matchers/existence_matcher.h
|
|
69
68
|
- ext/mongory_ext/mongory-core/src/matchers/external_matcher.c
|
|
70
69
|
- ext/mongory_ext/mongory-core/src/matchers/external_matcher.h
|
|
70
|
+
- ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.c
|
|
71
|
+
- ext/mongory_ext/mongory-core/src/matchers/implicit_array_matcher.h
|
|
71
72
|
- ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.c
|
|
72
73
|
- ext/mongory_ext/mongory-core/src/matchers/inclusion_matcher.h
|
|
73
|
-
- ext/mongory_ext/mongory-core/src/matchers/literal_matcher.c
|
|
74
|
-
- ext/mongory_ext/mongory-core/src/matchers/literal_matcher.h
|
|
75
74
|
- ext/mongory_ext/mongory-core/src/matchers/matcher.c
|
|
76
75
|
- ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.c
|
|
77
76
|
- ext/mongory_ext/mongory-core/src/matchers/matcher_explainable.h
|
|
78
77
|
- ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.c
|
|
79
78
|
- ext/mongory_ext/mongory-core/src/matchers/matcher_traversable.h
|
|
79
|
+
- ext/mongory_ext/mongory-core/src/matchers/value_matcher.c
|
|
80
|
+
- ext/mongory_ext/mongory-core/src/matchers/value_matcher.h
|
|
80
81
|
- ext/mongory_ext/mongory_ext.c
|
|
81
82
|
- ext/mongory_ext/mongory_ext_internal.h
|
|
82
83
|
- ext/mongory_ext/rb_mongory_adapters.c
|
|
83
|
-
- ext/mongory_ext/
|
|
84
|
+
- ext/mongory_ext/rb_mongory_matcher.c
|
|
84
85
|
- ext/mongory_ext/rb_mongory_value.c
|
|
85
86
|
- lib/core/2.6/mongory_ext.so
|
|
86
87
|
- lib/core/2.7/mongory_ext.so
|
|
@@ -96,8 +97,6 @@ files:
|
|
|
96
97
|
- lib/generators/mongory/matcher/templates/matcher.rb.erb
|
|
97
98
|
- lib/generators/mongory/matcher/templates/matcher_spec.rb.erb
|
|
98
99
|
- lib/mongory.rb
|
|
99
|
-
- lib/mongory/c_matcher.rb
|
|
100
|
-
- lib/mongory/c_query_builder.rb
|
|
101
100
|
- lib/mongory/converters.rb
|
|
102
101
|
- lib/mongory/converters/abstract_converter.rb
|
|
103
102
|
- lib/mongory/converters/condition_converter.rb
|
|
@@ -105,42 +104,19 @@ files:
|
|
|
105
104
|
- lib/mongory/converters/data_converter.rb
|
|
106
105
|
- lib/mongory/converters/key_converter.rb
|
|
107
106
|
- lib/mongory/converters/value_converter.rb
|
|
107
|
+
- lib/mongory/matcher.rb
|
|
108
108
|
- lib/mongory/matchers.rb
|
|
109
109
|
- lib/mongory/matchers/abstract_matcher.rb
|
|
110
|
-
- lib/mongory/matchers/abstract_multi_matcher.rb
|
|
111
|
-
- lib/mongory/matchers/and_matcher.rb
|
|
112
|
-
- lib/mongory/matchers/array_record_matcher.rb
|
|
113
|
-
- lib/mongory/matchers/elem_match_matcher.rb
|
|
114
|
-
- lib/mongory/matchers/eq_matcher.rb
|
|
115
|
-
- lib/mongory/matchers/every_matcher.rb
|
|
116
|
-
- lib/mongory/matchers/exists_matcher.rb
|
|
117
|
-
- lib/mongory/matchers/field_matcher.rb
|
|
118
|
-
- lib/mongory/matchers/gt_matcher.rb
|
|
119
|
-
- lib/mongory/matchers/gte_matcher.rb
|
|
120
|
-
- lib/mongory/matchers/hash_condition_matcher.rb
|
|
121
|
-
- lib/mongory/matchers/in_matcher.rb
|
|
122
|
-
- lib/mongory/matchers/literal_matcher.rb
|
|
123
|
-
- lib/mongory/matchers/lt_matcher.rb
|
|
124
|
-
- lib/mongory/matchers/lte_matcher.rb
|
|
125
|
-
- lib/mongory/matchers/ne_matcher.rb
|
|
126
|
-
- lib/mongory/matchers/nin_matcher.rb
|
|
127
|
-
- lib/mongory/matchers/not_matcher.rb
|
|
128
|
-
- lib/mongory/matchers/or_matcher.rb
|
|
129
|
-
- lib/mongory/matchers/present_matcher.rb
|
|
130
|
-
- lib/mongory/matchers/regex_matcher.rb
|
|
131
|
-
- lib/mongory/matchers/size_matcher.rb
|
|
132
110
|
- lib/mongory/mongoid.rb
|
|
133
111
|
- lib/mongory/query_builder.rb
|
|
134
|
-
- lib/mongory/query_matcher.rb
|
|
135
112
|
- lib/mongory/query_operator.rb
|
|
136
|
-
- lib/mongory/rails.rb
|
|
137
113
|
- lib/mongory/utils.rb
|
|
138
114
|
- lib/mongory/utils/context.rb
|
|
139
|
-
- lib/mongory/utils/debugger.rb
|
|
140
|
-
- lib/mongory/utils/rails_patch.rb
|
|
141
115
|
- lib/mongory/utils/singleton_builder.rb
|
|
116
|
+
- lib/mongory/utils/tree_renderer.rb
|
|
142
117
|
- lib/mongory/version.rb
|
|
143
118
|
- mongory.gemspec
|
|
119
|
+
- script/bench.rb
|
|
144
120
|
- scripts/build_with_core.sh
|
|
145
121
|
- sig/mongory.rbs
|
|
146
122
|
homepage: https://mongoryhq.github.io/mongory-rb/
|
data/lib/mongory/c_matcher.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongory
|
|
4
|
-
# This class is the C extension of Mongory::QueryMatcher.
|
|
5
|
-
# It is used to match records using the C extension.
|
|
6
|
-
# @example
|
|
7
|
-
# matcher = Mongory::CMatcher.new(condition)
|
|
8
|
-
# matcher.match?(record) #=> true
|
|
9
|
-
# # or
|
|
10
|
-
# collection.mongory.c.where(condition).to_a
|
|
11
|
-
class CMatcher
|
|
12
|
-
# @!method self.new(condition)
|
|
13
|
-
# @param condition [Hash] the condition
|
|
14
|
-
# @return [Mongory::CMatcher] a new matcher
|
|
15
|
-
# @note This method is implemented in the C extension
|
|
16
|
-
# @!method self.trace_result_colorful=(colorful)
|
|
17
|
-
# @param colorful [Boolean] whether to enable colorful trace result
|
|
18
|
-
# @return [void]
|
|
19
|
-
# @note This method is implemented in the C extension
|
|
20
|
-
#
|
|
21
|
-
# @!method match?(record)
|
|
22
|
-
# @param record [Object] the record to match against
|
|
23
|
-
# @return [Boolean] true if the record matches the condition, false otherwise
|
|
24
|
-
# @note This method is implemented in the C extension
|
|
25
|
-
# @!method explain
|
|
26
|
-
# @return [void]
|
|
27
|
-
# @note This method will print matcher tree structure
|
|
28
|
-
# @note This method is implemented in the C extension
|
|
29
|
-
# @!method trace
|
|
30
|
-
# @return [Boolean] true if the record matches the condition, false otherwise
|
|
31
|
-
# @note This method will print matching process
|
|
32
|
-
# @note This method is implemented in the C extension
|
|
33
|
-
# @!method enable_trace
|
|
34
|
-
# @return [void]
|
|
35
|
-
# @note This method will enable trace
|
|
36
|
-
# @note This method is implemented in the C extension
|
|
37
|
-
# @!method disable_trace
|
|
38
|
-
# @return [void]
|
|
39
|
-
# @note This method will disable trace
|
|
40
|
-
# @note This method is implemented in the C extension
|
|
41
|
-
# @!method print_trace
|
|
42
|
-
# @return [void]
|
|
43
|
-
# @note This method will print trace result
|
|
44
|
-
# @note This method is implemented in the C extension
|
|
45
|
-
# @!method condition
|
|
46
|
-
# @return [Hash] the condition
|
|
47
|
-
# @note This method is implemented in the C extension
|
|
48
|
-
# @!method context
|
|
49
|
-
# @return [Utils::Context] the context
|
|
50
|
-
# @note This method is implemented in the C extension
|
|
51
|
-
|
|
52
|
-
# @return [Proc] a Proc that performs the matching operation
|
|
53
|
-
def to_proc
|
|
54
|
-
Proc.new { |record| match?(record) }
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'query_builder'
|
|
4
|
-
|
|
5
|
-
module Mongory
|
|
6
|
-
# Mongory::CQueryBuilder is a query builder for Mongory::CMatcher.
|
|
7
|
-
# It is used to build a query for a Mongory::CMatcher.
|
|
8
|
-
class CQueryBuilder < QueryBuilder
|
|
9
|
-
def each
|
|
10
|
-
return to_enum(:each) unless block_given?
|
|
11
|
-
|
|
12
|
-
@records.each do |record|
|
|
13
|
-
@context.current_record = record
|
|
14
|
-
yield record if @matcher.match?(record)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
alias_method :fast, :each
|
|
19
|
-
|
|
20
|
-
def explain
|
|
21
|
-
@matcher.match?(@records.first)
|
|
22
|
-
@matcher.explain
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def trace
|
|
26
|
-
return to_enum(:trace) unless block_given?
|
|
27
|
-
|
|
28
|
-
@matcher.enable_trace
|
|
29
|
-
@records.each do |record|
|
|
30
|
-
@context.current_record = record
|
|
31
|
-
yield record if @matcher.match?(record)
|
|
32
|
-
end
|
|
33
|
-
ensure
|
|
34
|
-
@matcher.print_trace
|
|
35
|
-
@matcher.disable_trace
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
|
|
40
|
-
def set_matcher(condition = {})
|
|
41
|
-
@matcher = CMatcher.new(condition, context: @context)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|