easymongo 0.0.1 → 0.0.2
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 +4 -0
- data/README.md +44 -5
- data/easymongo.gemspec +1 -1
- data/lib/easymongo/query.rb +15 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e745e136312f00c928eda1e93c9d25661d59163
|
4
|
+
data.tar.gz: 233ef752b9c9fb6575aff9e29218a5a81f9b8dfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 792b2860abea639bfc8b54cf4aa5ceb7ec1df05a6452bfa4f3f6e34bb10670922e80e4a8392b3f6f08f2674c992ac8285eae05eebd4a09725bbfb2b7f7ed8484
|
7
|
+
data.tar.gz: 6d42ee3fd14a292b35c418a9ae7785375836986a3c69258935965a80e4d0fbc1995acf2b634a0418409f7fd3f4d7d722f15abf2066bcf88ad34429d45f644730
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -20,19 +20,58 @@ or add to Gemfile.
|
|
20
20
|
$db = Easymongo::Query.new(['127.0.0.1:27017'], :database => "easymongo_#{ENV['RACK_ENV']}")
|
21
21
|
|
22
22
|
# First
|
23
|
-
$db.
|
23
|
+
user = $db.users.get(:moon => 'animation').first
|
24
|
+
|
25
|
+
# Uses dot annotation
|
26
|
+
user.moon => 'animation'
|
27
|
+
user.name => 'Zetetic'
|
28
|
+
user.id => '596675a40aec08bfe7271e14'
|
29
|
+
user.bson_id => BSON::ObjectId('596675a40aec08bfe7271e14')
|
30
|
+
user.date => 2017-07-12 20:24:57 UTC
|
31
|
+
user.hello = 'Wake up' => Assign temporary value
|
32
|
+
|
33
|
+
# Hash annotation as well
|
34
|
+
user[:hello] => 'Wake up'
|
35
|
+
user.has_key?(:name) => true
|
36
|
+
|
37
|
+
# All these methods work on the document
|
38
|
+
http://www.rubydoc.info/github/mongodb/bson-ruby/master/BSON/Document
|
39
|
+
|
40
|
+
# Very flexible, also works like this for last and count
|
41
|
+
user = $db.users.first
|
42
|
+
user = $db.users.first(:id => '596675a40aec08bfe7271e14')
|
43
|
+
user = $db.users.first('596675a40aec08bfe7271e14')
|
44
|
+
user = $db.users.first(:tv => 'tull')
|
45
|
+
user = $db.users.get(:food => 'healthy').first
|
24
46
|
|
25
47
|
# Last
|
26
|
-
$db.
|
48
|
+
$db.users.get(:sun => 'close').last
|
49
|
+
|
50
|
+
# Count
|
51
|
+
$db.users.get(:life => 'humancentric').count
|
27
52
|
|
28
53
|
# All
|
29
|
-
$db.
|
54
|
+
$db.users.all
|
55
|
+
$db.users.get.all
|
56
|
+
$db.users.all(:spread => 'knowledge')
|
57
|
+
$db.users.get(:earth => 'beautiful').all
|
30
58
|
|
31
59
|
# Insert / Update
|
32
|
-
$db.
|
60
|
+
result = $db.users.set(:space => 'unreal')
|
61
|
+
result.date => 2017-07-12 20:24:57 UTC
|
62
|
+
result.id => '596675a40aec08bfe7271e14'
|
63
|
+
result.bson_id => BSON::ObjectId('596675a40aec08bfe7271e14')
|
64
|
+
|
65
|
+
# Access Mongo result
|
66
|
+
result.ok? => true
|
67
|
+
result.n => 1
|
68
|
+
|
69
|
+
# All these methods work on the result
|
70
|
+
http://api.mongodb.com/ruby/current/Mongo/Operation/Write/Update/Result.html
|
33
71
|
|
34
72
|
# Delete
|
35
|
-
$db.
|
73
|
+
$db.users.rm('596675a40aec08bfe7271e14')
|
74
|
+
$db.users.rm(:satellites => 'fragile')
|
36
75
|
|
37
76
|
```
|
38
77
|
|
data/easymongo.gemspec
CHANGED
data/lib/easymongo/query.rb
CHANGED
@@ -53,39 +53,39 @@ module Easymongo
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# Limit
|
56
|
-
def limit(n)
|
57
|
-
g
|
56
|
+
def limit(n, d = {})
|
57
|
+
g!(d); s[:cursor] = cursor.limit(n.to_i); self
|
58
58
|
end
|
59
59
|
|
60
60
|
# Sort
|
61
|
-
def sort(data)
|
62
|
-
g
|
61
|
+
def sort(data, d = {})
|
62
|
+
g!(d); s[:cursor] = cursor.sort(data); self
|
63
63
|
end
|
64
64
|
|
65
65
|
# Get first
|
66
|
-
def first
|
67
|
-
g
|
66
|
+
def first(d = {})
|
67
|
+
g!(d); cursor.first.tap{|r| return ed(r) if r; c!}
|
68
68
|
end
|
69
69
|
|
70
70
|
# Get last
|
71
|
-
def last
|
72
|
-
g
|
71
|
+
def last(d = {})
|
72
|
+
g!(d); cursor.sort(:$natural => -1).first.tap{|r| return ed(r) if r; c!}
|
73
73
|
end
|
74
74
|
|
75
75
|
# Get all
|
76
|
-
def all
|
77
|
-
g
|
76
|
+
def all(d = {})
|
77
|
+
g!(d); cursor.to_a.map{|r| ed(r)}.tap{ c!}
|
78
78
|
end
|
79
79
|
|
80
80
|
# Count
|
81
|
-
def count
|
82
|
-
g
|
81
|
+
def count(d = {})
|
82
|
+
g!(d); cursor.count.tap{ c!}
|
83
83
|
end
|
84
84
|
|
85
85
|
# Remove
|
86
86
|
def rm(data)
|
87
87
|
|
88
|
-
#
|
88
|
+
# Optimize data
|
89
89
|
data = ids(data)
|
90
90
|
|
91
91
|
# Delete doc
|
@@ -95,7 +95,7 @@ module Easymongo
|
|
95
95
|
Easymongo::Result.new(result, data).tap{ c!}
|
96
96
|
end
|
97
97
|
|
98
|
-
# Make sure
|
98
|
+
# Make sure data is optimal
|
99
99
|
def ids(data)
|
100
100
|
|
101
101
|
# Just return if nothing to do
|
@@ -131,7 +131,7 @@ module Easymongo
|
|
131
131
|
def c!; RequestStore.clear!; end
|
132
132
|
|
133
133
|
# Run get if no cursor
|
134
|
-
def g
|
134
|
+
def g!(d = {}); get(d) unless cursor; end
|
135
135
|
|
136
136
|
# Get the collection
|
137
137
|
def coll; s[:coll]; end
|