couchbase-orm 0.2.0 → 0.2.1

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: 30ece0939354be24d837389441c065a99526b79e
4
- data.tar.gz: 152e0ab95ae5b843e8c3aeb4d697f863666759b2
3
+ metadata.gz: 6db6e76268e2d3e78fe6312014d51a81b78dc687
4
+ data.tar.gz: 976ea9856de874fcd427c3ed8a60c827a4244a21
5
5
  SHA512:
6
- metadata.gz: 3a00046733b74236cb88e68075b1eecaa6c54a65696daace7847b643c871221647c07aff574d36b011a848142260f17ff54a8489d81c7a14b832603c503005b4
7
- data.tar.gz: 92d43d339fb8af9c4d07113d55868d17c766a037d2cf3c7ec04ae5db6b33434df7a6dbf1a27135c66c2d9fc0466287848383e7d8e12be841446592d4389e481e
6
+ metadata.gz: e647737e707d8d49399c86ef6455c226a333b941ad1ea793c45e09bcc6a42ac5d05116ef4ecbb075a286f12bbbcf04b7b7fb8e722b44dcd7750839156561fb34
7
+ data.tar.gz: afb572be2ba020827f32c7e945f57522c9f9ce0a41f78f5b6bbede66db78fd9e7a78a1c7d01d1be09b26d17e2c93ef374e8729d319099ae28200724028e4f588
data/README.md CHANGED
@@ -101,6 +101,15 @@ can then be used for filtering results or ordering.
101
101
  # * the by_author view above
102
102
  # * def find_by_author(author); end
103
103
  index_view :author
104
+
105
+ # You can make compound keys by passing an array to :emit_key
106
+ # this allow to query by read/unread comments
107
+ view :by_read, emit_key: [:user_id, :read]
108
+ # this allow to query by view_count
109
+ view :by_view_count, emit_key: [:user_id, :view_count]
110
+      
111
+
112
+      
104
113
 
105
114
  validates_presence_of :author, :body
106
115
  end
@@ -110,6 +119,20 @@ You can use `Comment.find_by_author('name')` to obtain all the comments by
110
119
  a particular author. The same thing, using the view directly would be:
111
120
  `Comment.by_author(key: 'name')`
112
121
 
122
+ When using a compound key, the usage is the same, you just give the full key :
123
+
124
+ ```ruby
125
+ Comment.by_read(key: '["'+user_id+'",false]') # gives all unread comments for one particular user
126
+
127
+ # or even a range !
128
+
129
+ Comment.by_view_count(startkey: '["'+user_id+'",10]', endkey: '["'+user_id+'",20]') # gives all comments that have been seen more than 10 times but less than 20
130
+ ```
131
+
132
+ Check this couchbase help page to learn more on what's possible with compound keys : https://developer.couchbase.com/documentation/server/3.x/admin/Views/views-translateSQL.html
133
+
134
+ Ex : Compound keys allows to decide the order of the results, and you can reverse it by passing `descending: true`
135
+
113
136
  ## Associations and Indexes
114
137
 
115
138
  There are common active record helpers available for use `belongs_to` and `has_many`
@@ -129,3 +152,22 @@ There are common active record helpers available for use `belongs_to` and `has_m
129
152
  ```
130
153
 
131
154
 
155
+ ## Performance Comparison with Couchbase-Ruby-Model
156
+
157
+ Basically we migrated an application from [Couchbase Ruby Model](https://github.com/couchbase/couchbase-ruby-model)
158
+ to [Couchbase-ORM](https://github.com/acaprojects/couchbase-orm) (this project)
159
+
160
+ * Rails 5 production
161
+ * Puma as the webserver
162
+ * Running on a 2015 Macbook Pro
163
+ * Performance test: `siege -c250 -r10 http://localhost:3000/auth/authority`
164
+
165
+ The request above pulls the same database document each time and returns it. A simple O(1) operation.
166
+
167
+ | Stat | Couchbase Ruby Model | Couchbase-ORM |
168
+ | :--- | :--- | :--- |
169
+ |Transactions|2500 hits|2500 hits|
170
+ |Elapsed time|12.24 secs|8.20 secs|
171
+ |Response time|0.88 secs|0.47 secs|
172
+ |Transaction rate|204.25 trans/sec|304.88 trans/sec|
173
+ |Request Code|[ruby-model-app](https://github.com/QuayPay/coauth/blob/95bbf5e5c3b3340e5af2da494b90c91c5e3d6eaa/app/controllers/auth/authorities_controller.rb#L6)|[couch-orm-app](https://github.com/QuayPay/coauth/blob/87f6fdeaab784ba252a5d38bbcf9e6b0477bb504/app/controllers/auth/authorities_controller.rb#L8)|
@@ -13,8 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.required_ruby_version = '>= 2.1.0'
14
14
  gem.require_paths = ["lib"]
15
15
 
16
- gem.add_runtime_dependency 'libcouchbase', '~> 0.1'
17
- gem.add_runtime_dependency 'activemodel', '~> 5.0'
16
+ gem.add_runtime_dependency 'libcouchbase', '~> 0.2'
17
+ gem.add_runtime_dependency 'activemodel', '>= 4.0', '< 6.0'
18
18
  gem.add_runtime_dependency 'radix', '~> 2.2' # converting numbers to and from any base
19
19
 
20
20
  gem.add_development_dependency 'rake', '~> 11.2'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true, encoding: ASCII-8BIT
2
2
 
3
3
  module CouchbaseOrm
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
@@ -23,7 +23,13 @@ module CouchbaseOrm
23
23
  # # ...
24
24
  # end
25
25
  def view(name, map: nil, emit_key: nil, reduce: nil, **options)
26
- raise "unknown emit_key attribute for view :#{name}, emit_key: :#{emit_key}" if emit_key && @attributes[emit_key].nil?
26
+ if emit_key.class == Array
27
+ emit_key.each do |key|
28
+ raise "unknown emit_key attribute for view :#{name}, emit_key: :#{key}" if key && @attributes[key].nil?
29
+ end
30
+ else
31
+ raise "unknown emit_key attribute for view :#{name}, emit_key: :#{emit_key}" if emit_key && @attributes[emit_key].nil?
32
+ end
27
33
 
28
34
  options = ViewDefaults.merge(options)
29
35
 
@@ -32,10 +38,19 @@ module CouchbaseOrm
32
38
  method_opts[:reduce] = reduce if reduce
33
39
 
34
40
  unless method_opts.has_key? :map
35
- emit_key = emit_key || :created_at
36
-
37
- if emit_key != :created_at && self.attributes[emit_key][:type].to_s == 'Array'
41
+ if emit_key.class == Array
38
42
  method_opts[:map] = <<-EMAP
43
+ function(doc) {
44
+ if (doc.type === "{{design_document}}") {
45
+ emit([#{emit_key.map{|key| "doc."+key.to_s}.join(',')}], null);
46
+ }
47
+ }
48
+ EMAP
49
+ else
50
+ emit_key = emit_key || :created_at
51
+
52
+ if emit_key != :created_at && self.attributes[emit_key][:type].to_s == 'Array'
53
+ method_opts[:map] = <<-EMAP
39
54
  function(doc) {
40
55
  var i;
41
56
  if (doc.type === "{{design_document}}") {
@@ -45,14 +60,15 @@ function(doc) {
45
60
  }
46
61
  }
47
62
  EMAP
48
- else
49
- method_opts[:map] = <<-EMAP
63
+ else
64
+ method_opts[:map] = <<-EMAP
50
65
  function(doc) {
51
66
  if (doc.type === "{{design_document}}") {
52
67
  emit(doc.#{emit_key}, null);
53
68
  }
54
69
  }
55
70
  EMAP
71
+ end
56
72
  end
57
73
  end
58
74
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase-orm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen von Takach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-27 00:00:00.000000000 Z
11
+ date: 2017-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libcouchbase
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ - - "<"
32
35
  - !ruby/object:Gem::Version
33
- version: '5.0'
36
+ version: '6.0'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '4.0'
44
+ - - "<"
39
45
  - !ruby/object:Gem::Version
40
- version: '5.0'
46
+ version: '6.0'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: radix
43
49
  requirement: !ruby/object:Gem::Requirement