easymongo 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: e410057d0345f4702f71a094005449ca511dafca
4
- data.tar.gz: 8b2dab525f5da96fedc58715b2ecd1ead20ed93f
3
+ metadata.gz: 5e745e136312f00c928eda1e93c9d25661d59163
4
+ data.tar.gz: 233ef752b9c9fb6575aff9e29218a5a81f9b8dfb
5
5
  SHA512:
6
- metadata.gz: 18c0bb86735521dbf4baf0b67ae551120989c4ee0848bdf62a93ebefd19ea3420638641d12ef4e24ae60b1d5478693d835aa4409aa34db27e7d49678765a65e5
7
- data.tar.gz: f70bb4fedf16b5e3355cd0e18f14c1ff2b3055acdfb46c15212eba09ed10a6bc7075adf166f1d03905559edb5089c7f8af80168898dbc4a8690911e2b45ee962
6
+ metadata.gz: 792b2860abea639bfc8b54cf4aa5ceb7ec1df05a6452bfa4f3f6e34bb10670922e80e4a8392b3f6f08f2674c992ac8285eae05eebd4a09725bbfb2b7f7ed8484
7
+ data.tar.gz: 6d42ee3fd14a292b35c418a9ae7785375836986a3c69258935965a80e4d0fbc1995acf2b634a0418409f7fd3f4d7d722f15abf2066bcf88ad34429d45f644730
@@ -1,3 +1,7 @@
1
1
  **Version 0.0.1** - *2017-07-12*
2
2
 
3
+ - Added short cuts for count, first, last
4
+
5
+ **Version 0.0.1** - *2017-07-12*
6
+
3
7
  - Initial version
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.collection.get.first
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.collection.get.last
48
+ $db.users.get(:sun => 'close').last
49
+
50
+ # Count
51
+ $db.users.get(:life => 'humancentric').count
27
52
 
28
53
  # All
29
- $db.collection.get.all
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.collection.set(:name => name)
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.domains.delete(id)
73
+ $db.users.rm('596675a40aec08bfe7271e14')
74
+ $db.users.rm(:satellites => 'fragile')
36
75
 
37
76
  ```
38
77
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'easymongo'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.date = '2017-07-12'
5
5
  s.summary = "Super Easy MongoDB client"
6
6
  s.description = "The way MongoDB for Ruby should be, can't get easier than this"
@@ -53,39 +53,39 @@ module Easymongo
53
53
  end
54
54
 
55
55
  # Limit
56
- def limit(n)
57
- g!; s[:cursor] = cursor.limit(n.to_i); self
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!; s[:cursor] = cursor.sort(data); self
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!; cursor.first.tap{|r| return ed(r) if r; c!}
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!; cursor.sort(:$natural => -1).first.tap{|r| return ed(r) if r; c!}
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!; cursor.to_a.map{|r| ed(r)}.tap{ c!}
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!; cursor.count.tap{ c!}
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
- # Normalize data
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 dataever passed works
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!; get unless cursor; end
134
+ def g!(d = {}); get(d) unless cursor; end
135
135
 
136
136
  # Get the collection
137
137
  def coll; s[:coll]; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easymongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fugroup Limited