couchbase 3.5.2-x86_64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +202 -0
- data/README.md +154 -0
- data/ext/extconf.rb +0 -0
- data/lib/active_support/cache/couchbase_store.rb +342 -0
- data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
- data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
- data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
- data/lib/couchbase/analytics_options.rb +109 -0
- data/lib/couchbase/authenticator.rb +66 -0
- data/lib/couchbase/binary_collection.rb +130 -0
- data/lib/couchbase/binary_collection_options.rb +26 -0
- data/lib/couchbase/bucket.rb +146 -0
- data/lib/couchbase/cluster.rb +462 -0
- data/lib/couchbase/cluster_registry.rb +49 -0
- data/lib/couchbase/collection.rb +707 -0
- data/lib/couchbase/collection_options.rb +401 -0
- data/lib/couchbase/config_profiles.rb +57 -0
- data/lib/couchbase/configuration.rb +58 -0
- data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
- data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
- data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
- data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
- data/lib/couchbase/datastructures.rb +26 -0
- data/lib/couchbase/diagnostics.rb +183 -0
- data/lib/couchbase/errors.rb +414 -0
- data/lib/couchbase/json_transcoder.rb +41 -0
- data/lib/couchbase/key_value_scan.rb +119 -0
- data/lib/couchbase/libcouchbase.rb +6 -0
- data/lib/couchbase/logger.rb +87 -0
- data/lib/couchbase/management/analytics_index_manager.rb +1129 -0
- data/lib/couchbase/management/bucket_manager.rb +445 -0
- data/lib/couchbase/management/collection_manager.rb +472 -0
- data/lib/couchbase/management/collection_query_index_manager.rb +224 -0
- data/lib/couchbase/management/query_index_manager.rb +619 -0
- data/lib/couchbase/management/scope_search_index_manager.rb +200 -0
- data/lib/couchbase/management/search_index_manager.rb +426 -0
- data/lib/couchbase/management/user_manager.rb +470 -0
- data/lib/couchbase/management/view_index_manager.rb +239 -0
- data/lib/couchbase/management.rb +31 -0
- data/lib/couchbase/mutation_state.rb +65 -0
- data/lib/couchbase/options.rb +2846 -0
- data/lib/couchbase/protostellar/binary_collection.rb +55 -0
- data/lib/couchbase/protostellar/bucket.rb +55 -0
- data/lib/couchbase/protostellar/client.rb +99 -0
- data/lib/couchbase/protostellar/cluster.rb +171 -0
- data/lib/couchbase/protostellar/collection.rb +152 -0
- data/lib/couchbase/protostellar/connect_options.rb +63 -0
- data/lib/couchbase/protostellar/error_handling.rb +203 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
- data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated.rb +9 -0
- data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
- data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
- data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
- data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
- data/lib/couchbase/protostellar/management.rb +24 -0
- data/lib/couchbase/protostellar/request.rb +78 -0
- data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
- data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
- data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
- data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
- data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
- data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
- data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
- data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
- data/lib/couchbase/protostellar/request_generator.rb +26 -0
- data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
- data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
- data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
- data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
- data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
- data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
- data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
- data/lib/couchbase/protostellar/response_converter.rb +26 -0
- data/lib/couchbase/protostellar/retry/action.rb +38 -0
- data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
- data/lib/couchbase/protostellar/retry/reason.rb +67 -0
- data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
- data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
- data/lib/couchbase/protostellar/retry.rb +28 -0
- data/lib/couchbase/protostellar/scope.rb +57 -0
- data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
- data/lib/couchbase/protostellar/timeouts.rb +83 -0
- data/lib/couchbase/protostellar.rb +29 -0
- data/lib/couchbase/query_options.rb +122 -0
- data/lib/couchbase/railtie.rb +47 -0
- data/lib/couchbase/raw_binary_transcoder.rb +39 -0
- data/lib/couchbase/raw_json_transcoder.rb +40 -0
- data/lib/couchbase/raw_string_transcoder.rb +42 -0
- data/lib/couchbase/scope.rb +258 -0
- data/lib/couchbase/search_options.rb +1650 -0
- data/lib/couchbase/subdoc.rb +293 -0
- data/lib/couchbase/transcoder_flags.rb +64 -0
- data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
- data/lib/couchbase/utils/stdlib_logger_adapter.rb +67 -0
- data/lib/couchbase/utils/time.rb +71 -0
- data/lib/couchbase/utils.rb +23 -0
- data/lib/couchbase/version.rb +25 -0
- data/lib/couchbase/view_options.rb +67 -0
- data/lib/couchbase.rb +30 -0
- data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
- metadata +190 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "couchbase/collection"
|
18
|
+
require "couchbase/options"
|
19
|
+
require "couchbase/errors"
|
20
|
+
|
21
|
+
module Couchbase
|
22
|
+
module Datastructures
|
23
|
+
# A {CouchbaseMap} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
|
24
|
+
# a JSON array).
|
25
|
+
#
|
26
|
+
# Note that as such, a {CouchbaseMap} is restricted to the types that JSON array can contain.
|
27
|
+
class CouchbaseMap
|
28
|
+
include Enumerable
|
29
|
+
|
30
|
+
# Create a new Map, backed by the document identified by +id+ in +collection+.
|
31
|
+
#
|
32
|
+
# @param [String] id the id of the document to back the map.
|
33
|
+
# @param [Collection] collection the Couchbase collection through which to interact with the document.
|
34
|
+
# @param [Options::CouchbaseMap] options customization of the datastructure
|
35
|
+
def initialize(id, collection, options = Options::CouchbaseMap.new)
|
36
|
+
@id = id
|
37
|
+
@collection = collection
|
38
|
+
@options = options
|
39
|
+
@cas = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calls the given block once for each element in the map, passing that element as a parameter.
|
43
|
+
#
|
44
|
+
# @yieldparam [Object] item
|
45
|
+
#
|
46
|
+
# @return [CouchbaseMap, Enumerable]
|
47
|
+
def each(&)
|
48
|
+
if block_given?
|
49
|
+
begin
|
50
|
+
result = @collection.get(@id, @options.get_options)
|
51
|
+
current = result.content
|
52
|
+
@cas = result.cas
|
53
|
+
rescue Error::DocumentNotFound
|
54
|
+
current = []
|
55
|
+
@cas = 0
|
56
|
+
end
|
57
|
+
current.each(&)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
enum_for(:each)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Integer] returns the number of elements in the map.
|
65
|
+
def length
|
66
|
+
result = @collection.lookup_in(@id, [
|
67
|
+
LookupInSpec.count(""),
|
68
|
+
], @options.lookup_in_options)
|
69
|
+
result.content(0)
|
70
|
+
rescue Error::DocumentNotFound
|
71
|
+
0
|
72
|
+
end
|
73
|
+
|
74
|
+
alias size length
|
75
|
+
|
76
|
+
# @return [Boolean] returns true if map is empty
|
77
|
+
def empty?
|
78
|
+
size.zero?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Removes all elements from the map
|
82
|
+
def clear
|
83
|
+
@collection.remove(@id, @options.remove_options)
|
84
|
+
nil
|
85
|
+
rescue Error::DocumentNotFound
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns a value from the map for the given key.
|
90
|
+
#
|
91
|
+
# If the key cannot be found, there are several options:
|
92
|
+
#
|
93
|
+
# * with no other arguments, it will raise a KeyError exception
|
94
|
+
# * if +default+ is given, then that will be returned
|
95
|
+
# * if the optional code +block+ is specified, then that will be run and its result returned
|
96
|
+
#
|
97
|
+
# @overload fetch(key)
|
98
|
+
# Gets the value, associated with the key, or raise KeyError if key could not be found
|
99
|
+
# @param key [String] key
|
100
|
+
#
|
101
|
+
# @overload fetch(key, default)
|
102
|
+
# Gets the value, associated with the key, or return +default+ if key could not be found
|
103
|
+
# @param key [String] key
|
104
|
+
#
|
105
|
+
# @overload fetch(key, &block)
|
106
|
+
# Gets the value, associated with the key, or invoke specified +block+ and propagate its return value
|
107
|
+
# if key could not be found
|
108
|
+
# @param key [String] key
|
109
|
+
# @yieldreturn [Object] the default value to return in case the key could not be found
|
110
|
+
#
|
111
|
+
# @return [Object]
|
112
|
+
def fetch(key, *rest)
|
113
|
+
result = @collection.lookup_in(@id, [
|
114
|
+
LookupInSpec.get(key),
|
115
|
+
], @options.lookup_in_options)
|
116
|
+
result.content(0)
|
117
|
+
rescue Error::DocumentNotFound, Error::PathNotFound
|
118
|
+
return yield if block_given?
|
119
|
+
return rest.first unless rest.empty?
|
120
|
+
|
121
|
+
raise KeyError, "key not found: #{key}"
|
122
|
+
end
|
123
|
+
|
124
|
+
# Returns a value from the map for the given key.
|
125
|
+
#
|
126
|
+
# If the key cannot be found, +nil+ will be returned.
|
127
|
+
#
|
128
|
+
# @param [String] key
|
129
|
+
#
|
130
|
+
# @return [Object, nil] value, associated with the key or +nil+
|
131
|
+
def [](key)
|
132
|
+
fetch(key, nil)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Associate the value given by +value+ with the key given by +key+.
|
136
|
+
#
|
137
|
+
# @param [String] key
|
138
|
+
# @param [Object] value
|
139
|
+
#
|
140
|
+
# @return [void]
|
141
|
+
def []=(key, value)
|
142
|
+
@collection.mutate_in(@id, [
|
143
|
+
MutateInSpec.upsert(key, value),
|
144
|
+
], @options.mutate_in_options)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Deletes the key-value pair from the map.
|
148
|
+
#
|
149
|
+
# @param [String] key
|
150
|
+
#
|
151
|
+
# @return void
|
152
|
+
def delete(key)
|
153
|
+
@collection.mutate_in(@id, [
|
154
|
+
MutateInSpec.remove(key),
|
155
|
+
])
|
156
|
+
rescue Error::DocumentNotFound, Error::PathNotFound
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
|
160
|
+
# Returns +true+ if the given key is present
|
161
|
+
#
|
162
|
+
# @param [String] key
|
163
|
+
# @return [Boolean]
|
164
|
+
def key?(key)
|
165
|
+
result = @collection.lookup_in(@id, [
|
166
|
+
LookupInSpec.exists(key),
|
167
|
+
], @options.lookup_in_options)
|
168
|
+
result.exists?(0)
|
169
|
+
rescue Error::DocumentNotFound, Error::PathNotFound
|
170
|
+
false
|
171
|
+
end
|
172
|
+
|
173
|
+
alias member? key?
|
174
|
+
alias include? key?
|
175
|
+
|
176
|
+
# Returns a new array populated with the keys from the map.
|
177
|
+
#
|
178
|
+
# @return [Array]
|
179
|
+
def keys
|
180
|
+
map { |key, _value| key }
|
181
|
+
end
|
182
|
+
|
183
|
+
# Returns a new array populated with the values from the map.
|
184
|
+
#
|
185
|
+
# @return [Array]
|
186
|
+
def values
|
187
|
+
map { |_key, value| value }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# @api private
|
192
|
+
CouchbaseMapOptions = ::Couchbase::Options::CouchbaseMap
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "couchbase/collection"
|
18
|
+
require "couchbase/options"
|
19
|
+
require "couchbase/errors"
|
20
|
+
|
21
|
+
module Couchbase
|
22
|
+
module Datastructures
|
23
|
+
# A {CouchbaseQueue} is implements FIFO queue with +Enumerable+ interface and backed by {Collection} document
|
24
|
+
# (more specifically a JSON array).
|
25
|
+
#
|
26
|
+
# Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
|
27
|
+
class CouchbaseQueue
|
28
|
+
include Enumerable
|
29
|
+
|
30
|
+
# Create a new List, backed by the document identified by +id+ in +collection+.
|
31
|
+
#
|
32
|
+
# @param [String] id the id of the document to back the queue.
|
33
|
+
# @param [Collection] collection the collection through which to interact with the document.
|
34
|
+
# @param [Options::CouchbaseList] options customization of the datastructure
|
35
|
+
def initialize(id, collection, options = Options::CouchbaseQueue.new)
|
36
|
+
@id = id
|
37
|
+
@collection = collection
|
38
|
+
@options = options
|
39
|
+
@cas = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calls the given block once for each element in the queue, passing that element as a parameter.
|
43
|
+
#
|
44
|
+
# @yieldparam [Object] item
|
45
|
+
#
|
46
|
+
# @return [CouchbaseQueue, Enumerable]
|
47
|
+
def each(&)
|
48
|
+
if block_given?
|
49
|
+
begin
|
50
|
+
result = @collection.get(@id, @options.get_options)
|
51
|
+
current = result.content
|
52
|
+
@cas = result.cas
|
53
|
+
rescue Error::DocumentNotFound
|
54
|
+
current = []
|
55
|
+
@cas = 0
|
56
|
+
end
|
57
|
+
current.each(&)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
enum_for(:each)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Integer] returns the number of elements in the queue.
|
65
|
+
def length
|
66
|
+
result = @collection.lookup_in(@id, [
|
67
|
+
LookupInSpec.count(""),
|
68
|
+
], @options.lookup_in_options)
|
69
|
+
result.content(0)
|
70
|
+
rescue Error::DocumentNotFound
|
71
|
+
0
|
72
|
+
end
|
73
|
+
|
74
|
+
alias size length
|
75
|
+
|
76
|
+
# @return [Boolean] returns true if queue is empty
|
77
|
+
def empty?
|
78
|
+
size.zero?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Removes all elements from the queue
|
82
|
+
def clear
|
83
|
+
@collection.remove(@id, @options.remove_options)
|
84
|
+
nil
|
85
|
+
rescue Error::DocumentNotFound
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
# Adds the given value to the queue
|
90
|
+
#
|
91
|
+
# @param [Object] obj
|
92
|
+
# @return [CouchbaseQueue]
|
93
|
+
def push(obj)
|
94
|
+
begin
|
95
|
+
@collection.mutate_in(@id, [
|
96
|
+
MutateInSpec.array_prepend("", [obj]),
|
97
|
+
], @options.mutate_in_options)
|
98
|
+
rescue Error::PathExists
|
99
|
+
# ignore
|
100
|
+
end
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
alias enq push
|
105
|
+
alias << push
|
106
|
+
|
107
|
+
# Retrieves object from the queue
|
108
|
+
#
|
109
|
+
# @return [Object, nil] queue entry or nil
|
110
|
+
def pop
|
111
|
+
result = @collection.lookup_in(@id, [
|
112
|
+
LookupInSpec.get("[-1]"),
|
113
|
+
], @options.lookup_in_options)
|
114
|
+
obj = result.exists?(0) ? result.content(0) : nil
|
115
|
+
options = Collection::MutateInOptions.new
|
116
|
+
options.cas = result.cas
|
117
|
+
@collection.mutate_in(@id, [
|
118
|
+
MutateInSpec.remove("[-1]"),
|
119
|
+
], options)
|
120
|
+
obj
|
121
|
+
rescue Error::CasMismatch
|
122
|
+
retry
|
123
|
+
rescue Error::DocumentNotFound, Error::PathNotFound
|
124
|
+
nil
|
125
|
+
end
|
126
|
+
|
127
|
+
alias deq pop
|
128
|
+
alias shift pop
|
129
|
+
end
|
130
|
+
|
131
|
+
# @api private
|
132
|
+
CouchbaseQueueOptions = ::Couchbase::Options::CouchbaseQueue
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "couchbase/collection"
|
18
|
+
require "couchbase/options"
|
19
|
+
require "couchbase/errors"
|
20
|
+
|
21
|
+
module Couchbase
|
22
|
+
module Datastructures
|
23
|
+
# A {CouchbaseSet} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
|
24
|
+
# a JSON array).
|
25
|
+
#
|
26
|
+
# Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
|
27
|
+
class CouchbaseSet
|
28
|
+
include Enumerable
|
29
|
+
|
30
|
+
# Create a new List, backed by the document identified by +id+ in +collection+.
|
31
|
+
#
|
32
|
+
# @param [String] id the id of the document to back the set.
|
33
|
+
# @param [Collection] collection the collection through which to interact with the document.
|
34
|
+
# @param [Options::CouchbaseSet] options customization of the datastructure
|
35
|
+
def initialize(id, collection, options = Options::CouchbaseSet.new)
|
36
|
+
@id = id
|
37
|
+
@collection = collection
|
38
|
+
@options = options
|
39
|
+
@cas = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calls the given block once for each element in the set, passing that element as a parameter.
|
43
|
+
#
|
44
|
+
# @yieldparam [Object] item
|
45
|
+
#
|
46
|
+
# @return [CouchbaseSet, Enumerable]
|
47
|
+
def each(&)
|
48
|
+
if block_given?
|
49
|
+
begin
|
50
|
+
result = @collection.get(@id, @options.get_options)
|
51
|
+
current = result.content
|
52
|
+
@cas = result.cas
|
53
|
+
rescue Error::DocumentNotFound
|
54
|
+
current = []
|
55
|
+
@cas = 0
|
56
|
+
end
|
57
|
+
current.each(&)
|
58
|
+
self
|
59
|
+
else
|
60
|
+
enum_for(:each)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Integer] returns the number of elements in the set.
|
65
|
+
def length
|
66
|
+
result = @collection.lookup_in(@id, [
|
67
|
+
LookupInSpec.count(""),
|
68
|
+
], @options.lookup_in_options)
|
69
|
+
result.content(0)
|
70
|
+
rescue Error::DocumentNotFound
|
71
|
+
0
|
72
|
+
end
|
73
|
+
|
74
|
+
alias size length
|
75
|
+
|
76
|
+
# @return [Boolean] returns true if set is empty
|
77
|
+
def empty?
|
78
|
+
size.zero?
|
79
|
+
end
|
80
|
+
|
81
|
+
# Adds the given value to the set
|
82
|
+
#
|
83
|
+
# @param [Object] obj
|
84
|
+
# @return [CouchbaseSet]
|
85
|
+
def add(obj)
|
86
|
+
begin
|
87
|
+
@collection.mutate_in(@id, [
|
88
|
+
MutateInSpec.array_add_unique("", obj),
|
89
|
+
], @options.mutate_in_options)
|
90
|
+
rescue Error::PathExists
|
91
|
+
# ignore
|
92
|
+
end
|
93
|
+
self
|
94
|
+
end
|
95
|
+
|
96
|
+
# Removes all elements from the set
|
97
|
+
def clear
|
98
|
+
@collection.remove(@id, @options.remove_options)
|
99
|
+
nil
|
100
|
+
rescue Error::DocumentNotFound
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
|
104
|
+
# Deletes the given object from the set.
|
105
|
+
#
|
106
|
+
# @return [Boolean] true if the value has been removed
|
107
|
+
def delete(obj)
|
108
|
+
result = @collection.get(@id)
|
109
|
+
idx = result.content.index(obj)
|
110
|
+
return false unless idx
|
111
|
+
|
112
|
+
options = Collection::MutateInOptions.new
|
113
|
+
options.cas = result.cas
|
114
|
+
@collection.mutate_in(@id, [
|
115
|
+
MutateInSpec.remove("[#{idx}]"),
|
116
|
+
], options)
|
117
|
+
true
|
118
|
+
rescue Error::CasMismatch
|
119
|
+
retry
|
120
|
+
rescue Error::DocumentNotFound
|
121
|
+
false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# @api private
|
126
|
+
CouchbaseSetOptions = ::Couchbase::Options::CouchbaseSet
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
# This namespace includes easy-to-use wrappers for various concurrent data-structures.
|
19
|
+
module Datastructures
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
require "couchbase/datastructures/couchbase_list"
|
24
|
+
require "couchbase/datastructures/couchbase_set"
|
25
|
+
require "couchbase/datastructures/couchbase_queue"
|
26
|
+
require "couchbase/datastructures/couchbase_map"
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
class DiagnosticsResult
|
19
|
+
class ServiceInfo
|
20
|
+
# @return [String] endpoint unique identifier
|
21
|
+
attr_accessor :id
|
22
|
+
|
23
|
+
# Possible states are:
|
24
|
+
#
|
25
|
+
# :disconnected:: the endpoint is not reachable
|
26
|
+
# :connecting:: currently connecting (includes auth, handshake, etc.)
|
27
|
+
# :connected:: connected and ready
|
28
|
+
# :disconnecting:: disconnecting (after being connected)
|
29
|
+
#
|
30
|
+
# @return [Symbol] state of the endpoint
|
31
|
+
attr_accessor :state
|
32
|
+
|
33
|
+
# @return [String, nil] optional string with additional explanation for the state
|
34
|
+
attr_accessor :details
|
35
|
+
|
36
|
+
# @return [Integer] how long ago the endpoint was active (in microseconds)
|
37
|
+
attr_accessor :last_activity_us
|
38
|
+
|
39
|
+
# @return [String] remote address of the connection
|
40
|
+
attr_accessor :remote
|
41
|
+
|
42
|
+
# @return [String] local address of the connection
|
43
|
+
attr_accessor :local
|
44
|
+
|
45
|
+
# @yieldparam [ServiceInfo] self
|
46
|
+
def initialize
|
47
|
+
yield self if block_given?
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_json(*args)
|
51
|
+
data = {
|
52
|
+
id: @id,
|
53
|
+
state: @state,
|
54
|
+
remote: @remote,
|
55
|
+
local: @local,
|
56
|
+
}
|
57
|
+
data[:details] = @details if @details
|
58
|
+
data[:last_activity_us] = @last_activity_us if @last_activity_us
|
59
|
+
data.to_json(*args)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [String] report id
|
64
|
+
attr_accessor :id
|
65
|
+
|
66
|
+
# @return [String] SDK identifier
|
67
|
+
attr_accessor :sdk
|
68
|
+
|
69
|
+
# Returns information about currently service endpoints, that known to the library at the moment.
|
70
|
+
#
|
71
|
+
# :kv:: Key/Value data service
|
72
|
+
# :query:: N1QL query service
|
73
|
+
# :analytics:: Analtyics service
|
74
|
+
# :search:: Full text search service
|
75
|
+
# :views:: Views service
|
76
|
+
# :mgmt:: Management service
|
77
|
+
#
|
78
|
+
# @return [Hash<Symbol, ServiceInfo>] map service types to info
|
79
|
+
attr_accessor :services
|
80
|
+
|
81
|
+
# @yieldparam [DiagnosticsResult] self
|
82
|
+
def initialize
|
83
|
+
@services = {}
|
84
|
+
yield self if block_given?
|
85
|
+
end
|
86
|
+
|
87
|
+
# @api private
|
88
|
+
# @return [Integer] version
|
89
|
+
attr_accessor :version
|
90
|
+
|
91
|
+
def to_json(*args)
|
92
|
+
{
|
93
|
+
version: @version,
|
94
|
+
id: @id,
|
95
|
+
sdk: @sdk,
|
96
|
+
services: @services,
|
97
|
+
}.to_json(*args)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class PingResult
|
102
|
+
class ServiceInfo
|
103
|
+
# @return [String] endpoint unique identifier
|
104
|
+
attr_accessor :id
|
105
|
+
|
106
|
+
# Possible states are:
|
107
|
+
#
|
108
|
+
# :ok:: endpoint is healthy
|
109
|
+
# :timeout:: endpoint didn't respond in time
|
110
|
+
# :error:: request to endpoint has failed, see {#error} for additional details
|
111
|
+
#
|
112
|
+
# @return [Symbol] state of the endpoint
|
113
|
+
attr_accessor :state
|
114
|
+
|
115
|
+
# @return [String, nil] optional string with additional explanation for the state
|
116
|
+
attr_accessor :error
|
117
|
+
|
118
|
+
# @return [Integer] how long ago the endpoint was active (in microseconds)
|
119
|
+
attr_accessor :latency
|
120
|
+
|
121
|
+
# @return [String] remote address of the connection
|
122
|
+
attr_accessor :remote
|
123
|
+
|
124
|
+
# @return [String] local address of the connection
|
125
|
+
attr_accessor :local
|
126
|
+
|
127
|
+
# @yieldparam [ServiceInfo] self
|
128
|
+
def initialize
|
129
|
+
@error = nil
|
130
|
+
yield self if block_given?
|
131
|
+
end
|
132
|
+
|
133
|
+
def to_json(*args)
|
134
|
+
data = {
|
135
|
+
id: @id,
|
136
|
+
state: @state,
|
137
|
+
remote: @remote,
|
138
|
+
local: @local,
|
139
|
+
latency: @latency,
|
140
|
+
}
|
141
|
+
data[:error] = @error if @error
|
142
|
+
data.to_json(*args)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# @return [String] report id
|
147
|
+
attr_accessor :id
|
148
|
+
|
149
|
+
# @return [String] SDK identifier
|
150
|
+
attr_accessor :sdk
|
151
|
+
|
152
|
+
# Returns information about currently service endpoints, that known to the library at the moment.
|
153
|
+
#
|
154
|
+
# :kv:: Key/Value data service
|
155
|
+
# :query:: N1QL query service
|
156
|
+
# :analytics:: Analtyics service
|
157
|
+
# :search:: Full text search service
|
158
|
+
# :views:: Views service
|
159
|
+
# :mgmt:: Management service
|
160
|
+
#
|
161
|
+
# @return [Hash<Symbol, ServiceInfo>] map service types to info
|
162
|
+
attr_accessor :services
|
163
|
+
|
164
|
+
# @yieldparam [DiagnosticsResult] self
|
165
|
+
def initialize
|
166
|
+
@services = {}
|
167
|
+
yield self if block_given?
|
168
|
+
end
|
169
|
+
|
170
|
+
# @api private
|
171
|
+
# @return [Integer] version
|
172
|
+
attr_accessor :version
|
173
|
+
|
174
|
+
def to_json(*args)
|
175
|
+
{
|
176
|
+
version: @version,
|
177
|
+
id: @id,
|
178
|
+
sdk: @sdk,
|
179
|
+
services: @services,
|
180
|
+
}.to_json(*args)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|