README.md in couchbase-orm-0.2.0 vs README.md in couchbase-orm-0.2.1

- old
+ new

@@ -99,19 +99,42 @@ # Generates two functions: # * the by_author view above # * def find_by_author(author); end index_view :author + + # You can make compound keys by passing an array to :emit_key + # this allow to query by read/unread comments + view :by_read, emit_key: [:user_id, :read] + # this allow to query by view_count + view :by_view_count, emit_key: [:user_id, :view_count] +       + +       validates_presence_of :author, :body end ``` You can use `Comment.find_by_author('name')` to obtain all the comments by a particular author. The same thing, using the view directly would be: `Comment.by_author(key: 'name')` +When using a compound key, the usage is the same, you just give the full key : + +```ruby + Comment.by_read(key: '["'+user_id+'",false]') # gives all unread comments for one particular user + + # or even a range ! + + 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 +``` + +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 + +Ex : Compound keys allows to decide the order of the results, and you can reverse it by passing `descending: true` + ## Associations and Indexes There are common active record helpers available for use `belongs_to` and `has_many` ```ruby @@ -127,5 +150,24 @@ ensure_unique :email end ``` +## Performance Comparison with Couchbase-Ruby-Model + +Basically we migrated an application from [Couchbase Ruby Model](https://github.com/couchbase/couchbase-ruby-model) +to [Couchbase-ORM](https://github.com/acaprojects/couchbase-orm) (this project) + +* Rails 5 production +* Puma as the webserver +* Running on a 2015 Macbook Pro +* Performance test: `siege -c250 -r10 http://localhost:3000/auth/authority` + +The request above pulls the same database document each time and returns it. A simple O(1) operation. + +| Stat | Couchbase Ruby Model | Couchbase-ORM | +| :--- | :--- | :--- | +|Transactions|2500 hits|2500 hits| +|Elapsed time|12.24 secs|8.20 secs| +|Response time|0.88 secs|0.47 secs| +|Transaction rate|204.25 trans/sec|304.88 trans/sec| +|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)|