Module: Couchbase

Defined in:
lib/couchbase.rb,
lib/couchbase/dns.rb,
lib/couchbase/view.rb,
lib/couchbase/utils.rb,
lib/couchbase/bucket.rb,
lib/couchbase/result.rb,
lib/couchbase/cluster.rb,
lib/couchbase/version.rb,
lib/couchbase/view_row.rb,
lib/couchbase/constants.rb,
lib/couchbase/transcoder.rb,
lib/couchbase/library_error.rb,
lib/couchbase/connection_pool.rb,
ext/couchbase_ext/couchbase_ext.c

Overview

Author

Couchbase <[email protected]>

Copyright

2018 Couchbase, Inc.

License

Apache License, Version 2.0

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Defined Under Namespace

Modules: Constants, DNS, Error, Transcoder Classes: Bucket, Cluster, ConnectionPool, DesignDoc, LibraryError, Result, Utils, View, ViewRow

Constant Summary collapse

VERSION =
'2.0.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.connection_optionsHash, String

Default connection options

Examples:

Using connection_options to change the bucket

Couchbase.connection_options = {:bucket => 'blog'}
Couchbase.bucket.name     #=> "blog"

Returns:

  • (Hash, String)

Since:

  • 1.1.0


71
72
73
# File 'lib/couchbase.rb', line 71

def connection_options
  @connection_options
end

Class Method Details

.bucket(name = 'default') ⇒ Bucket

The connection instance for current thread

Examples:

Couchbase.bucket.set("foo", "bar")

Set connection options using Hash

Couchbase.connection_options = {:node_list => ["example.com:8091"]}
Couchbase.bucket("slot1").set("foo", "bar")
Couchbase.bucket("slot1").bucket #=> "default"
Couchbase.connection_options[:bucket] = "test"
Couchbase.bucket("slot2").bucket #=> "test"

Set connection options using URI

Couchbase.connection_options = "http://example.com:8091/pools"
Couchbase.bucket("slot1").set("foo", "bar")
Couchbase.bucket("slot1").bucket #=> "default"
Couchbase.connection_options = "http://example.com:8091/pools/buckets/test"
Couchbase.bucket("slot2").bucket #=> "test"

Use named slots to keep a connection

Couchbase.connection_options = {
  :node_list => ["example.com", "example.org"],
  :bucket => "users"
}
Couchbase.bucket("users").set("john", {"balance" => 0})
Couchbase.connection_options[:bucket] = "orders"
Couchbase.bucket("other").set("john:1", {"products" => [42, 66]})

Returns:

See Also:

Since:

  • 1.1.0


122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/couchbase.rb', line 122

def bucket(name = 'default')
  verify_connection!
  thread_storage[:bucket][name] ||=
    case connection_options
    when String, Hash, nil
      connect(connection_options)
    when Array
      connect(*connection_options)
    else
      raise ArgumentError, "invalid connection_options type: #{connection_options.class}"
    end
end

.bucket=(connection, name = 'default') ⇒ Bucket Also known as: set_bucket

Set a connection instance for current thread

Returns:

Since:

  • 1.1.0


140
141
142
143
# File 'lib/couchbase.rb', line 140

def bucket=(connection, name = 'default')
  verify_connection!
  thread_storage[:bucket][name] = connection
end

.connect(connstr = 'couchbase://localhost/default', options = nil) ⇒ Bucket Also known as: new

The method connect initializes new Bucket instance with all arguments passed.

Examples:

Use default values for all options

Couchbase.connect

Establish connection with couchbase default pool and default bucket

Couchbase.connect("http://localhost:8091/pools/default")

Select custom bucket

Couchbase.connect("http://localhost:8091/pools/default", :bucket => 'blog')

Specify bucket credentials

Couchbase.connect("http://localhost:8091/pools/default", :bucket => 'blog', :username => 'bucket', :password => 'secret')

Use URL notation

Couchbase.connect("http://bucket:[email protected]:8091/pools/default/buckets/blog")

Returns:

  • (Bucket)

    connection instance

See Also:

Since:

  • 1.0.0


57
58
59
# File 'lib/couchbase.rb', line 57

def connect(connstr = 'couchbase://localhost/default', options = nil)
  Bucket.new(connstr, options)
end

.libcouchbase_versionString

Version of the libcouchbase library currently loaded

Returns:

  • (String)

Since:

  • 1.3.3


220
221
222
223
224
225
226
# File 'ext/couchbase_ext/couchbase_ext.c', line 220

static VALUE
cb_libcouchbase_version(VALUE self)
{
    const char *ver = lcb_get_version(NULL);
    (void)self;
    return STR_NEW_CSTR(ver);
}