Hi everyone, after long preparations, I pleased to announce preview on next generation API for ruby client. In general it just aligns ruby client with all other SDKs, where new document-oriented API had been released about a month ago.

At the moment the release only accessible for JRuby implementation, CRuby is coming. Here is sneak-peek of new design.

require ‘couchbase’

cluster = Couchbase::Cluster.new([‘localhost’])
bucket = cluster.open_bucket(‘beer-sample’)

doc = bucket.get(‘abbaye_de_leffe-leffe_blonde’)
# => #<Couchbase::Document:0x207513da
#     @cas=255200433657064,
#     @content=
#      {“name”=>”Leffe Blonde”,
#       “abv”=>6.6,
#       “ibu”=>0.0,
#       “srm”=>0.0,
#       “upc”=>0,
#       “type”=>”beer”,
#       “brewery_id”=>”abbaye_de_leffe”,
#       “updated”=>”2010-07-22 20:00:20”,
#       “description”=>””,
#       “style”=>”Golden or Blonde Ale”,
#       “category”=>”North American Ale”},
#     @expiry=0,
#     @id=”abbaye_de_leffe-leffe_blonde”,
#     @transcode=true>

doc.content.update(‘ibu’ => 20, ‘description’ => <<EOD)
Leffe Blond is the flagship of Leffe. The unique recipe is the fruit
of centuries of experience in the art of brewing, which brings a broad
palette of aromas into balance.


doc = bucket.get(‘abbaye_de_leffe-leffe_blonde’)
# => 20

res = bucket.query(‘beer’, ‘by_location’, :group_level => 1)
puts ‘First 4 countries:’
res.rows.take(4).each do |row|
  puts “#{row[‘key’].first}: #{row[‘value’]}”

res.rows.each do |row|
  bucket.counter(‘beer_lovers’, +1, initial: 1) if row[‘value’] > 10
puts “There are #{bucket.get(‘beer_lovers’).content} countries with more than 10 breweries”

# >> First 4 countries:
# >> Argentina: 2
# >> Aruba: 1
# >> Australia: 14
# >> Austria: 10
# >> There are 171 countries with more than 10 breweries

The new version already available at https://rubygems.org/gems/couchbase/versions/2.0.0.pre.1-java and can be installed either with gem command:

$ jruby -S gem install couchbase –pre
Successfully installed couchbase-2.0.0.pre.1-java
Parsing documentation for couchbase-2.0.0.pre.1-java
Done installing documentation for couchbase after 0 seconds
1 gem installed

Or with gem bundler, just use the following Gemfile

source ‘https://rubygems.org’

gem ‘couchbase’, ‘~> 2.0.0.pre.1’

Please leave your feedback here in comments or on your new forum: https://www.couchbase.com/forums/c/ruby-sdk. Thanks


Posted by Sergey Avseyev, SDK Engineer, Couchbase

Sergey Avseyev is a SDK Engineer at Couchbase. Sergey Avseyev is responsible for development of Kafka connector, and underlying library, which implements DCP, Couchbase replication protocol. Also maintaining PHP SDK for Couchbase.

Leave a reply