mongery 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +1 -8
- data/lib/mongery/version.rb +1 -1
- data/lib/mongery.rb +9 -8
- data/spec/mongery/builder_spec.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1124d4cc8a8887a26daf6cd0167b395692eb2b80
|
4
|
+
data.tar.gz: e0cc0961e38626e40cc26f079471e0e0c52186c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4de70968015998d26f1bd15e15e8e08c24a67356ae1ba3351f1be7ca6baed823a8c7688bab266b3fddb7dd9a31cbdfbb5540b1e81d06235bea504ab5e294409
|
7
|
+
data.tar.gz: 8861688d905bb127308cde48cd9797903d00620f500c15d89413527a20fce2bca18262af44761ee237611eb4923576f0c7dbf0abc33a414c8b21a096cf13454b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,6 @@ CREATE TABLE objects (
|
|
24
24
|
|
25
25
|
Currently Mongery assumes the `id` values are stored as `_id` key duplicated in the json data as well. This can be customized in the future updates.
|
26
26
|
|
27
|
-
### Selects
|
28
|
-
|
29
27
|
```ruby
|
30
28
|
builder = Mongery::Builder.new(:objects)
|
31
29
|
|
@@ -34,12 +32,6 @@ builder.find({ _id: 'abcd' }).limit(1).to_sql
|
|
34
32
|
|
35
33
|
builder.find({ age: {"$gte" => 21 } }).sort({ name: -1 }).to_sql
|
36
34
|
# => SELECT data FROM objects WHERE (data->>'age')::integer >= 21 ORDER BY data->>'name' DESC
|
37
|
-
```
|
38
|
-
|
39
|
-
### Inserts, Updates and Deletes
|
40
|
-
|
41
|
-
```ruby
|
42
|
-
builder = Mongery::Builder.new(:objects)
|
43
35
|
|
44
36
|
builder.insert({ _id: 'foobar' }).to_sql
|
45
37
|
# => INSERT INTO "objects" ("id", "data") VALUES ('foobar', '{"_id":"foobar"}')
|
@@ -49,6 +41,7 @@ builder.find({ age: {"$gte" => 21 } }).update({ name: "John" }).to_sql
|
|
49
41
|
|
50
42
|
builder.find({ age: {"$eq" => 55 } }).delete.to_sql
|
51
43
|
# => DELETE FROM "objects" WHERE (data->>'age')::integer = 21
|
44
|
+
```
|
52
45
|
|
53
46
|
## See Also
|
54
47
|
|
data/lib/mongery/version.rb
CHANGED
data/lib/mongery.rb
CHANGED
@@ -2,8 +2,6 @@ require "mongery/version"
|
|
2
2
|
require "arel"
|
3
3
|
|
4
4
|
module Mongery
|
5
|
-
# Translate Mongo query to Arel AST
|
6
|
-
|
7
5
|
class Builder
|
8
6
|
attr_reader :model, :table
|
9
7
|
|
@@ -192,13 +190,16 @@ module Mongery
|
|
192
190
|
end
|
193
191
|
|
194
192
|
def sql_json_path(col)
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
193
|
+
paths = col.to_s.split('.')
|
194
|
+
if paths.size > 1
|
195
|
+
Arel.sql("data#>>#{json_pathize(paths)}")
|
196
|
+
else
|
197
|
+
Arel.sql("data->>#{quote(paths.first)}")
|
200
198
|
end
|
201
|
-
|
199
|
+
end
|
200
|
+
|
201
|
+
def json_pathize(paths)
|
202
|
+
quote("{#{paths.join(',')}}")
|
202
203
|
end
|
203
204
|
|
204
205
|
def quote(str)
|
@@ -41,7 +41,9 @@ describe Mongery::Builder do
|
|
41
41
|
[ { bool: true }, { },
|
42
42
|
/WHERE data->>'bool' = 'true'$/ ],
|
43
43
|
[ { 'email.address' => 'john@example.com' }, { },
|
44
|
-
/WHERE data
|
44
|
+
/WHERE data#>>'{email,address}' = 'john@example.com'$/ ],
|
45
|
+
[ { "x'y.z" => 'john' }, { },
|
46
|
+
/WHERE data#>>'{x''y,z}' = 'john'$/ ],
|
45
47
|
[ { type: "food", "$or" => [{name: "miso"}, {name: "tofu"}]}, { },
|
46
48
|
/WHERE data->>'type' = 'food' AND \(data->>'name' = 'miso' OR data->>'name' = 'tofu'\)$/ ],
|
47
49
|
[ { "$or" => [{ _id: "foo" }, { _id: "bar" }] }, { },
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuhiko Miyagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: arel
|