mongory 0.9.0-aarch64-linux → 2.0.0-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 +26 -0
- data/README.md +121 -422
- data/SUBMODULE_INTEGRATION.md +2 -2
- data/docs/clang_bridge.md +28 -59
- data/docs/migration.md +17 -0
- data/docs/performance.md +14 -51
- data/examples/benchmark.rb +10 -10
- 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 +69 -0
- data/ext/mongory_ext/mongory-core/src/matchers/base_matcher.h +15 -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 +167 -31
- data/ext/mongory_ext/mongory-core/src/matchers/composite_matcher.h +7 -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 +20 -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 +6 -5
- 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} +120 -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 -2
- data/ext/mongory_ext/{rb_mongory_cmatcher.c → rb_mongory_matcher.c} +157 -23
- 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/converted.rb +28 -6
- data/lib/mongory/converters/key_converter.rb +2 -0
- data/lib/mongory/matcher.rb +63 -0
- data/lib/mongory/matchers/abstract_matcher.rb +18 -164
- data/lib/mongory/matchers.rb +68 -84
- data/lib/mongory/query_builder.rb +30 -41
- data/lib/mongory/utils/tree_renderer.rb +108 -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
- 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 -124
- data/lib/mongory/matchers/and_matcher.rb +0 -72
- 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 -79
- data/lib/mongory/matchers/in_matcher.rb +0 -84
- data/lib/mongory/matchers/literal_matcher.rb +0 -121
- 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 -68
- 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
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongory
|
|
4
|
-
module Matchers
|
|
5
|
-
# Matcher for the `$size` operator.
|
|
6
|
-
#
|
|
7
|
-
# This matcher expects the input to be an array, and delegates the comparison
|
|
8
|
-
# to a literal matcher using the array's size as the value.
|
|
9
|
-
#
|
|
10
|
-
# For example, the condition `{ tags: { '$size' => 3 } }` will match any
|
|
11
|
-
# document where `tags` is an array of length 3.
|
|
12
|
-
#
|
|
13
|
-
# ### Supported compound usages:
|
|
14
|
-
#
|
|
15
|
-
# ```ruby
|
|
16
|
-
# Mongory.where(tags: { '$size' => 3 }) # exactly 3 elements
|
|
17
|
-
# Mongory.where(tags: { '$size' => { '$gt' => 1 } }) # more than 1
|
|
18
|
-
# Mongory.where(comments: { '$size' => { '$gt' => 1, '$lte' => 5 } }) # more than 1, up to 5 elements
|
|
19
|
-
# Mongory.where(tags: { '$size' => { '$in' => [1, 2, 3] } }) # 1, 2, or 3 elements
|
|
20
|
-
# ```
|
|
21
|
-
#
|
|
22
|
-
# @see LiteralMatcher
|
|
23
|
-
#
|
|
24
|
-
# @note Ruby's Symbol class already defines a `#size` method,
|
|
25
|
-
# that will return the size of the symbol object.
|
|
26
|
-
# So, this is the only operator that cannot be used with
|
|
27
|
-
# the symbol snippet syntax (e.g. `:tags.size`).
|
|
28
|
-
#
|
|
29
|
-
# Use string key syntax instead: `:"tags.$size" => ...`
|
|
30
|
-
class SizeMatcher < LiteralMatcher
|
|
31
|
-
# Creates a raw Proc that performs the size matching operation.
|
|
32
|
-
#
|
|
33
|
-
# The returned Proc checks if the input is an Array. If so, it calculates
|
|
34
|
-
# the array's size and passes it to the wrapped literal matcher Proc.
|
|
35
|
-
#
|
|
36
|
-
# @return [Proc] A proc that performs size-based matching
|
|
37
|
-
def raw_proc
|
|
38
|
-
super_proc = super
|
|
39
|
-
|
|
40
|
-
Proc.new do |record|
|
|
41
|
-
next false unless record.is_a?(Array)
|
|
42
|
-
|
|
43
|
-
super_proc.call(record.size)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def priority
|
|
48
|
-
2 + super
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
register(:size, '$size', SizeMatcher)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'utils'
|
|
4
|
-
|
|
5
|
-
module Mongory
|
|
6
|
-
# The top-level matcher for compiled query conditions.
|
|
7
|
-
#
|
|
8
|
-
# Delegates to {Matchers::LiteralMatcher} after transforming input
|
|
9
|
-
# via {Converters::ConditionConverter}.
|
|
10
|
-
#
|
|
11
|
-
# Typically used internally by `QueryBuilder`.
|
|
12
|
-
#
|
|
13
|
-
# Conversion via Mongory.data_converter is applied to the record
|
|
14
|
-
# before matching to ensure consistent data types.
|
|
15
|
-
#
|
|
16
|
-
# @example Basic matching
|
|
17
|
-
# matcher = QueryMatcher.new({ :age.gte => 18 })
|
|
18
|
-
# matcher.match?(record) # => true/false
|
|
19
|
-
#
|
|
20
|
-
# @example Complex condition
|
|
21
|
-
# matcher = QueryMatcher.new({
|
|
22
|
-
# :age.gte => 18,
|
|
23
|
-
# :$or => [
|
|
24
|
-
# { :name => /J/ },
|
|
25
|
-
# { :name.eq => 'Bob' }
|
|
26
|
-
# ]
|
|
27
|
-
# })
|
|
28
|
-
#
|
|
29
|
-
# @see Matchers::LiteralMatcher
|
|
30
|
-
# @see Converters::ConditionConverter
|
|
31
|
-
class QueryMatcher < Matchers::HashConditionMatcher
|
|
32
|
-
# Initializes a new query matcher with the given condition.
|
|
33
|
-
# The condition is converted using Mongory.condition_converter
|
|
34
|
-
# before being passed to the parent matcher.
|
|
35
|
-
#
|
|
36
|
-
# @param condition [Hash<Symbol, Object>] a query condition using operator-style symbol keys,
|
|
37
|
-
# e.g. { :age.gt => 18 }, which will be parsed by `Mongory.condition_converter`.
|
|
38
|
-
# @param context [Context] The query context containing configuration and current record
|
|
39
|
-
# @option context [Hash] :config The query configuration
|
|
40
|
-
# @option context [Object] :current_record The current record being processed
|
|
41
|
-
# @option context [Boolean] :need_convert Whether the record needs to be converted
|
|
42
|
-
def initialize(condition, context: Utils::Context.new)
|
|
43
|
-
super(Mongory.condition_converter.convert(condition), context: context)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Returns a Proc that can be used for fast matching.
|
|
47
|
-
# The Proc converts the record using Mongory.data_converter
|
|
48
|
-
# and delegates to the superclass's raw_proc.
|
|
49
|
-
#
|
|
50
|
-
# @return [Proc] A proc that performs query matching with context awareness
|
|
51
|
-
# @note The proc includes error handling and context-based record conversion
|
|
52
|
-
def raw_proc
|
|
53
|
-
super_proc = super
|
|
54
|
-
need_convert = @context.need_convert
|
|
55
|
-
data_converter = Mongory.data_converter
|
|
56
|
-
|
|
57
|
-
Proc.new do |record|
|
|
58
|
-
record = data_converter.convert(record) if need_convert
|
|
59
|
-
super_proc.call(record)
|
|
60
|
-
rescue StandardError
|
|
61
|
-
false
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Renders the full matcher tree for the current query.
|
|
66
|
-
# This method is intended to be the public entry point for rendering
|
|
67
|
-
# the matcher tree. It does not accept any arguments and internally
|
|
68
|
-
# handles rendering via the configured pretty-print logic.
|
|
69
|
-
#
|
|
70
|
-
# Subclasses or internal matchers should implement their own
|
|
71
|
-
# `#render_tree(prefix, is_last:)` for internal recursion.
|
|
72
|
-
#
|
|
73
|
-
# @return [void]
|
|
74
|
-
# @see Matchers::LiteralMatcher#render_tree
|
|
75
|
-
def render_tree
|
|
76
|
-
super
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Prepares the query for execution by ensuring all necessary matchers are initialized.
|
|
80
|
-
# This is called before query execution to avoid premature matcher tree construction.
|
|
81
|
-
#
|
|
82
|
-
# @return [void]
|
|
83
|
-
alias_method :prepare_query, :check_validity!
|
|
84
|
-
|
|
85
|
-
# Overrides the parent class's check_validity! to prevent premature matcher tree construction.
|
|
86
|
-
# This matcher does not require validation, so this is a no-op.
|
|
87
|
-
#
|
|
88
|
-
# @return [void]
|
|
89
|
-
def check_validity!
|
|
90
|
-
# No-op for this matcher
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
data/lib/mongory/rails.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails'
|
|
4
|
-
require_relative 'utils/rails_patch'
|
|
5
|
-
|
|
6
|
-
module Mongory
|
|
7
|
-
# @see Utils::RailsPatch
|
|
8
|
-
class Railtie < Rails::Railtie
|
|
9
|
-
initializer 'mongory.patch_utils' do
|
|
10
|
-
[Mongory::Utils, *Mongory::Utils.included_classes].each do |klass|
|
|
11
|
-
klass.prepend(Mongory::Utils::RailsPatch)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongory
|
|
4
|
-
module Utils
|
|
5
|
-
# Debugger provides an internal tracing system for query matching.
|
|
6
|
-
# It tracks matcher evaluation in a tree structure and provides tree-like format output.
|
|
7
|
-
#
|
|
8
|
-
# It captures each matcher evaluation with indentation and visualizes the hierarchy,
|
|
9
|
-
# helping developers understand nested matcher flows (e.g. `$and`, `$or`, etc).
|
|
10
|
-
#
|
|
11
|
-
# Usage:
|
|
12
|
-
# Debugger.instance.with_indent { ... } # wraps around matcher logic
|
|
13
|
-
# Debugger.instance.display # prints trace tree after execution
|
|
14
|
-
#
|
|
15
|
-
# Note:
|
|
16
|
-
# The trace is recorded in post-order (leaf nodes enter first),
|
|
17
|
-
# and `reorder_traces_for_display` is used to transform it into a
|
|
18
|
-
# pre-order format suitable for display.
|
|
19
|
-
#
|
|
20
|
-
# This class is a singleton and should be accessed via `Debugger.instance`.
|
|
21
|
-
#
|
|
22
|
-
# @example Enable debugging
|
|
23
|
-
# Debugger.instance.enable
|
|
24
|
-
# Mongory::QueryBuilder.new(...).filter(...)
|
|
25
|
-
#
|
|
26
|
-
class Debugger < SingletonBuilder
|
|
27
|
-
include Singleton
|
|
28
|
-
|
|
29
|
-
def initialize
|
|
30
|
-
super(self.class.name)
|
|
31
|
-
@indent_level = -1
|
|
32
|
-
@trace_entries = []
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Enables debug mode by aliasing `to_proc` to `debug_proc`.
|
|
36
|
-
# @return [void]
|
|
37
|
-
# @note Changes the behavior of to_proc to use debug_proc instead of cached_proc
|
|
38
|
-
def enable
|
|
39
|
-
Matchers::AbstractMatcher.alias_method :to_proc, :debug_proc
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Disables debug mode by restoring `to_proc` to `cached_proc`.
|
|
43
|
-
# @return [void]
|
|
44
|
-
# @note Restores the original behavior of to_proc
|
|
45
|
-
def disable
|
|
46
|
-
Matchers::AbstractMatcher.alias_method :to_proc, :cached_proc
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
# Wraps a matcher evaluation block with indentation control.
|
|
50
|
-
#
|
|
51
|
-
# It increments the internal indent level before the block,
|
|
52
|
-
# and decrements it after. The yielded block's return value
|
|
53
|
-
# is used as trace content and pushed onto the trace_entries.
|
|
54
|
-
#
|
|
55
|
-
# @yieldreturn [String] the trace content to log
|
|
56
|
-
# @return [Object] the result of the block
|
|
57
|
-
def with_indent
|
|
58
|
-
@indent_level += 1
|
|
59
|
-
display_string = yield
|
|
60
|
-
@trace_entries << TraceEntry.new(display_string, @indent_level)
|
|
61
|
-
ensure
|
|
62
|
-
@indent_level -= 1
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# Prints the visualized trace tree to STDOUT.
|
|
66
|
-
#
|
|
67
|
-
# This processes the internal trace_entries (post-order) into
|
|
68
|
-
# a structured pre-order list that represents nested matcher evaluation.
|
|
69
|
-
# @return [void]
|
|
70
|
-
def display
|
|
71
|
-
reorder_traces_for_display(@trace_entries).each do |trace|
|
|
72
|
-
puts trace.formatted
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
@trace_entries.clear
|
|
76
|
-
nil
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Recursively reorders trace lines by indentation level to produce a
|
|
80
|
-
# display-friendly structure where parents precede children.
|
|
81
|
-
#
|
|
82
|
-
# The original trace is built in post-order (leaf first), and this method
|
|
83
|
-
# transforms it into a pre-order structure suitable for tree display.
|
|
84
|
-
#
|
|
85
|
-
# @param traces [Array<TraceEntry>] the raw trace lines (leaf-first)
|
|
86
|
-
# @param level [Integer] current processing level
|
|
87
|
-
# @return [Array<TraceEntry>] reordered trace lines for display
|
|
88
|
-
def reorder_traces_for_display(traces, level = 0)
|
|
89
|
-
result = []
|
|
90
|
-
group = []
|
|
91
|
-
traces.each do |trace|
|
|
92
|
-
if trace.level == level
|
|
93
|
-
result << trace
|
|
94
|
-
result.concat reorder_traces_for_display(group, level + 1)
|
|
95
|
-
group = []
|
|
96
|
-
else
|
|
97
|
-
group << trace
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
result
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def clear
|
|
105
|
-
# Clears the internal trace buffer.
|
|
106
|
-
# This is useful when re-running a query and avoiding stale trace output.
|
|
107
|
-
# @return [void]
|
|
108
|
-
@trace_entries.clear
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
# @private
|
|
112
|
-
# A trace entry representing a single matcher output at a given indentation level.
|
|
113
|
-
#
|
|
114
|
-
# @!attribute text
|
|
115
|
-
# @return [String] the string to be printed
|
|
116
|
-
# @!attribute level
|
|
117
|
-
# @return [Integer] the indentation level of this entry
|
|
118
|
-
TraceEntry = Struct.new(:text, :level) do
|
|
119
|
-
def formatted
|
|
120
|
-
"#{' ' * level}#{text}"
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Mongory
|
|
4
|
-
module Utils
|
|
5
|
-
# Only loaded when Rails is present
|
|
6
|
-
module RailsPatch
|
|
7
|
-
# Use Object#present? which defined in Rails.
|
|
8
|
-
# @param target[Object]
|
|
9
|
-
# @return [Boolean]
|
|
10
|
-
def is_present?(target)
|
|
11
|
-
target.present?
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# Use Object#blank? which defined in Rails.
|
|
15
|
-
# @param target[Object]
|
|
16
|
-
# @return [Boolean]
|
|
17
|
-
def is_blank?(target)
|
|
18
|
-
target.blank?
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|