Class: Couchbase::Management::QueryIndexManager

Inherits:
Object
  • Object
show all
Defined in:
lib/couchbase/management/query_index_manager.rb,
/Users/sergey.auseyau/code/couchbase-ruby-client/lib/couchbase/management/query_index_manager.rb
more...

Defined Under Namespace

Classes: BuildDeferredIndexOptions, CreateIndexOptions, CreatePrimaryIndexOptions, DropIndexOptions, DropPrimaryIndexOptions, GetAllIndexOptions, WatchIndexesOptions

Instance Method Summary collapse

Constructor Details

#initialize(backend) ⇒ QueryIndexManager

Returns a new instance of QueryIndexManager.

Parameters:

  • backend (Couchbase::Backend)
[View source]

23
24
25
# File 'lib/couchbase/management/query_index_manager.rb', line 23

def initialize(backend)
  @backend = backend
end

Instance Method Details

#build_deferred_indexes(bucket_name, options = BuildDeferredIndexOptions.new) ⇒ Object

Build all indexes which are currently in deferred state

Parameters:

  • bucket_name (String)

    name of the bucket

  • options (BuildDeferredIndexOptions) (defaults to: BuildDeferredIndexOptions.new)

Returns:

  • void

Raises:

  • (ArgumentError)
[View source]

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

def build_deferred_indexes(bucket_name, options = BuildDeferredIndexOptions.new)
  @backend.query_index_build_deferred(bucket_name, options.timeout)
end

#create_index(bucket_name, index_name, fields, options = CreateIndexOptions.new) ⇒ Object

Creates a new index

Parameters:

  • bucket_name (String)

    name of the bucket

  • index_name (String)

    name of the index

  • fields (Array<String>)

    the lists of fields to create th index over

  • options (CreateIndexOptions) (defaults to: CreateIndexOptions.new)

Returns:

  • void

Raises:

[View source]

65
66
67
68
69
70
71
72
73
74
# File 'lib/couchbase/management/query_index_manager.rb', line 65

def create_index(bucket_name, index_name, fields, options = CreateIndexOptions.new)
  @backend.query_index_create(bucket_name, index_name, fields, {
    ignore_if_exists: options.ignore_if_exists,
    condition: options.condition,
    deferred: options.deferred,
    num_replicas: options.num_replicas,
    scope_name: options.scope_name,
    collection_name: options.collection_name,
  }, options.timeout)
end

#create_primary_index(bucket_name, options = CreatePrimaryIndexOptions.new) ⇒ Object

Creates new primary index

Parameters:

  • bucket_name (String)

    name of the bucket

  • options (CreatePrimaryIndexOptions) (defaults to: CreatePrimaryIndexOptions.new)

Returns:

  • void

Raises:

[View source]

85
86
87
88
89
90
91
92
93
# File 'lib/couchbase/management/query_index_manager.rb', line 85

def create_primary_index(bucket_name, options = CreatePrimaryIndexOptions.new)
  @backend.query_index_create_primary(bucket_name, {
    ignore_if_exists: options.ignore_if_exists,
    deferred: options.deferred,
    num_replicas: options.num_replicas,
    scope_name: options.scope_name,
    collection_name: options.collection_name,
  }, options.timeout)
end

#drop_index(bucket_name, index_name, options = DropIndexOptions.new) ⇒ Object

Drops the index

Parameters:

  • bucket_name (String)

    name of the bucket

  • index_name (String)

    name of the index

  • options (DropIndexOptions) (defaults to: DropIndexOptions.new)

Returns:

  • void

Raises:

[View source]

105
106
107
108
109
110
111
112
# File 'lib/couchbase/management/query_index_manager.rb', line 105

def drop_index(bucket_name, index_name, options = DropIndexOptions.new)
  @backend.query_index_drop(bucket_name, index_name, {
    ignore_if_does_not_exist: options.ignore_if_does_not_exist,
    scope_name: options.scope_name,
    collection_name: options.collection_name,
  }, options.timeout)
  true
end

#drop_primary_index(bucket_name, options = DropPrimaryIndexOptions.new) ⇒ Object

Drops the primary index

Parameters:

  • bucket_name (String)

    name of the bucket

  • options (DropPrimaryIndexOptions) (defaults to: DropPrimaryIndexOptions.new)

Returns:

  • void

Raises:

[View source]

123
124
125
126
127
128
129
130
131
# File 'lib/couchbase/management/query_index_manager.rb', line 123

def drop_primary_index(bucket_name, options = DropPrimaryIndexOptions.new)
  @backend.query_index_drop_primary(bucket_name, {
    ignore_if_does_not_exist: options.ignore_if_does_not_exist,
    index_name: options.index_name,
    scope_name: options.scope_name,
    collection_name: options.collection_name,
  }, options.timeout)
  true
end

#get_all_indexes(bucket_name, options = GetAllIndexOptions.new) ⇒ Array<QueryIndex>

Fetches all indexes from the server

Parameters:

  • bucket_name (String)

    name of the bucket

  • options (GetAllIndexOptions) (defaults to: GetAllIndexOptions.new)

Returns:

Raises:

  • (ArgumentError)
[View source]

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/couchbase/management/query_index_manager.rb', line 35

def get_all_indexes(bucket_name, options = GetAllIndexOptions.new)
  res = @backend.query_index_get_all(bucket_name, options.timeout)
  res[:indexes].map do |idx|
    QueryIndex.new do |index|
      index.name = idx[:name]
      index.is_primary = idx[:is_primary]
      index.type = idx[:type]
      index.state = idx[:state]
      index.bucket = idx[:bucket_id]
      index.collection = idx[:collection_id]
      index.scope = idx[:scope_id]
      index.key_space = idx[:keyspace_id]
      index.name_space = idx[:namespace_id]
      index.index_key = idx[:index_key]
      index.condition = idx[:condition]
    end
  end
end

#watch_indexes(bucket_name, index_names, timeout, options = WatchIndexesOptions.new) ⇒ Object

Polls indexes until they are online

Parameters:

  • bucket_name (String)

    name of the bucket

  • index_names (Array<String>)

    names of the indexes to watch

  • timeout (Integer, #in_milliseconds)
  • options (WatchIndexesOptions) (defaults to: WatchIndexesOptions.new)

Raises:

[View source]

154
155
156
157
158
# File 'lib/couchbase/management/query_index_manager.rb', line 154

def watch_indexes(bucket_name, index_names, timeout, options = WatchIndexesOptions.new)
  @backend.query_index_watch(bucket_name, index_names, timeout, {
    watch_primary: options.watch_primary,
  })
end