mongo_ql 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 397c8071669a33bfe85662de3439d9746d26bcb80ccb69dcc602471224da7f12
|
4
|
+
data.tar.gz: 683ad4555c980a6ce2593a2dbf1efa20f182d836e0ca16ea98511638dadd8502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1fe54f5ffad72f4184202af5ab4cf5c923f6e79bb4e9b0de73d618668319f3f63c43a1529bbf73771ec7ca5886c393d623cc70ddca3b8e0a7c466fe003856f3
|
7
|
+
data.tar.gz: 563766df5b880b08870f9b084fbb866ce9883fc79f20a0d202f508ca5560f483053a37f74c2565a3b92e6fbe859c6ff1d3e4bc8b05892f2a5f767f283361ced5
|
@@ -14,12 +14,14 @@ module MongoQL
|
|
14
14
|
def initialize(val)
|
15
15
|
Expression::ValueNode.valid!(val)
|
16
16
|
@value = val
|
17
|
+
convert_to_date_if_possible
|
17
18
|
end
|
18
19
|
|
19
20
|
def to_ast
|
20
21
|
case value
|
21
22
|
when Date, DateTime
|
22
|
-
Expression::ValueNode.new(value.iso8601).to_date.to_ast
|
23
|
+
# Expression::ValueNode.new(value.iso8601).to_date.to_ast
|
24
|
+
{ "$toDate" => value.iso8601 }
|
23
25
|
when MongoQL::Expression::ValueNode
|
24
26
|
value.to_ast
|
25
27
|
else
|
@@ -27,6 +29,12 @@ module MongoQL
|
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
32
|
+
def convert_to_date_if_possible
|
33
|
+
self.value = DateTime.iso8601(value)
|
34
|
+
rescue => _
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
30
38
|
def self.valid?(value)
|
31
39
|
SUPPORTED_TYPES.any? { |type| value.is_a?(type) }
|
32
40
|
end
|
@@ -81,8 +81,8 @@ module MongoQL
|
|
81
81
|
else
|
82
82
|
if from&.respond_to?(:collection)
|
83
83
|
from&.collection&.name
|
84
|
-
elsif
|
85
|
-
from.
|
84
|
+
elsif from&.respond_to?(:field_name)
|
85
|
+
from.field_name
|
86
86
|
else
|
87
87
|
raise ArgumentError, "#{from} is not a valid collection"
|
88
88
|
end
|
@@ -9,6 +9,18 @@ module MongoQL
|
|
9
9
|
@injected_vars = {}
|
10
10
|
end
|
11
11
|
|
12
|
+
def scope(mongo_scope)
|
13
|
+
criteria = nil
|
14
|
+
if mongo_scope.respond_to?(:all)
|
15
|
+
criteria = mongo_scope.all.selector.transform_keys { |k| k.to_sym }
|
16
|
+
end
|
17
|
+
|
18
|
+
if mongo_scope.is_a?(Hash)
|
19
|
+
criteria = mongo_scope.transform_keys { |k| k.to_sym }
|
20
|
+
end
|
21
|
+
where(**criteria) if criteria
|
22
|
+
end
|
23
|
+
|
12
24
|
def where(*args)
|
13
25
|
pipeline << Stage::Match.new(self, *args)
|
14
26
|
end
|
@@ -69,7 +81,7 @@ module MongoQL
|
|
69
81
|
pipeline.map(&:to_ast)
|
70
82
|
end
|
71
83
|
|
72
|
-
%w(where match project select sort flatten unwind lookup join).each do |m|
|
84
|
+
%w(scope where match project select sort flatten unwind lookup join).each do |m|
|
73
85
|
alias_method :"#{m.capitalize}", m
|
74
86
|
end
|
75
87
|
end
|
data/lib/mongo_ql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_ql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xizheng Ding
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|