couchbase 3.5.0-x86_64-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- 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 +339 -0
- data/lib/couchbase/3.1/libcouchbase.so +0 -0
- data/lib/couchbase/3.2/libcouchbase.so +0 -0
- data/lib/couchbase/3.3/libcouchbase.so +0 -0
- data/lib/couchbase/analytics_options.rb +107 -0
- data/lib/couchbase/authenticator.rb +64 -0
- data/lib/couchbase/binary_collection.rb +128 -0
- data/lib/couchbase/binary_collection_options.rb +24 -0
- data/lib/couchbase/bucket.rb +144 -0
- data/lib/couchbase/cluster.rb +460 -0
- data/lib/couchbase/cluster_registry.rb +49 -0
- data/lib/couchbase/collection.rb +705 -0
- data/lib/couchbase/collection_options.rb +399 -0
- data/lib/couchbase/config_profiles.rb +55 -0
- data/lib/couchbase/configuration.rb +56 -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 +24 -0
- data/lib/couchbase/diagnostics.rb +181 -0
- data/lib/couchbase/errors.rb +376 -0
- data/lib/couchbase/json_transcoder.rb +39 -0
- data/lib/couchbase/key_value_scan.rb +117 -0
- data/lib/couchbase/libcouchbase.rb +6 -0
- data/lib/couchbase/logger.rb +85 -0
- data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
- data/lib/couchbase/management/bucket_manager.rb +443 -0
- data/lib/couchbase/management/collection_manager.rb +470 -0
- data/lib/couchbase/management/collection_query_index_manager.rb +222 -0
- data/lib/couchbase/management/query_index_manager.rb +617 -0
- data/lib/couchbase/management/scope_search_index_manager.rb +198 -0
- data/lib/couchbase/management/search_index_manager.rb +424 -0
- data/lib/couchbase/management/user_manager.rb +468 -0
- data/lib/couchbase/management/view_index_manager.rb +237 -0
- data/lib/couchbase/management.rb +29 -0
- data/lib/couchbase/mutation_state.rb +63 -0
- data/lib/couchbase/options.rb +2837 -0
- data/lib/couchbase/protostellar/binary_collection.rb +55 -0
- data/lib/couchbase/protostellar/bucket.rb +51 -0
- data/lib/couchbase/protostellar/client.rb +99 -0
- data/lib/couchbase/protostellar/cluster.rb +163 -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 +120 -0
- data/lib/couchbase/railtie.rb +45 -0
- data/lib/couchbase/raw_binary_transcoder.rb +37 -0
- data/lib/couchbase/raw_json_transcoder.rb +38 -0
- data/lib/couchbase/raw_string_transcoder.rb +40 -0
- data/lib/couchbase/scope.rb +256 -0
- data/lib/couchbase/search_options.rb +1622 -0
- data/lib/couchbase/subdoc.rb +290 -0
- data/lib/couchbase/transcoder_flags.rb +62 -0
- data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
- data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
- data/lib/couchbase/utils/time.rb +69 -0
- data/lib/couchbase/utils.rb +21 -0
- data/lib/couchbase/version.rb +23 -0
- data/lib/couchbase/view_options.rb +65 -0
- data/lib/couchbase.rb +28 -0
- data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
- metadata +190 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "couchbase/collection"
|
16
|
+
require "couchbase/options"
|
17
|
+
require "couchbase/errors"
|
18
|
+
|
19
|
+
module Couchbase
|
20
|
+
module Datastructures
|
21
|
+
# A {CouchbaseMap} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
|
22
|
+
# a JSON array).
|
23
|
+
#
|
24
|
+
# Note that as such, a {CouchbaseMap} is restricted to the types that JSON array can contain.
|
25
|
+
class CouchbaseMap
|
26
|
+
include Enumerable
|
27
|
+
|
28
|
+
# Create a new Map, backed by the document identified by +id+ in +collection+.
|
29
|
+
#
|
30
|
+
# @param [String] id the id of the document to back the map.
|
31
|
+
# @param [Collection] collection the Couchbase collection through which to interact with the document.
|
32
|
+
# @param [Options::CouchbaseMap] options customization of the datastructure
|
33
|
+
def initialize(id, collection, options = Options::CouchbaseMap.new)
|
34
|
+
@id = id
|
35
|
+
@collection = collection
|
36
|
+
@options = options
|
37
|
+
@cas = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
# Calls the given block once for each element in the map, passing that element as a parameter.
|
41
|
+
#
|
42
|
+
# @yieldparam [Object] item
|
43
|
+
#
|
44
|
+
# @return [CouchbaseMap, Enumerable]
|
45
|
+
def each
|
46
|
+
if block_given?
|
47
|
+
begin
|
48
|
+
result = @collection.get(@id, @options.get_options)
|
49
|
+
current = result.content
|
50
|
+
@cas = result.cas
|
51
|
+
rescue Error::DocumentNotFound
|
52
|
+
current = []
|
53
|
+
@cas = 0
|
54
|
+
end
|
55
|
+
current.each do |key, value|
|
56
|
+
yield key, value
|
57
|
+
end
|
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
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "couchbase/collection"
|
16
|
+
require "couchbase/options"
|
17
|
+
require "couchbase/errors"
|
18
|
+
|
19
|
+
module Couchbase
|
20
|
+
module Datastructures
|
21
|
+
# A {CouchbaseQueue} is implements FIFO queue with +Enumerable+ interface and backed by {Collection} document
|
22
|
+
# (more specifically a JSON array).
|
23
|
+
#
|
24
|
+
# Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
|
25
|
+
class CouchbaseQueue
|
26
|
+
include Enumerable
|
27
|
+
|
28
|
+
# Create a new List, backed by the document identified by +id+ in +collection+.
|
29
|
+
#
|
30
|
+
# @param [String] id the id of the document to back the queue.
|
31
|
+
# @param [Collection] collection the collection through which to interact with the document.
|
32
|
+
# @param [Options::CouchbaseList] options customization of the datastructure
|
33
|
+
def initialize(id, collection, options = Options::CouchbaseQueue.new)
|
34
|
+
@id = id
|
35
|
+
@collection = collection
|
36
|
+
@options = options
|
37
|
+
@cas = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
# Calls the given block once for each element in the queue, passing that element as a parameter.
|
41
|
+
#
|
42
|
+
# @yieldparam [Object] item
|
43
|
+
#
|
44
|
+
# @return [CouchbaseQueue, Enumerable]
|
45
|
+
def each
|
46
|
+
if block_given?
|
47
|
+
begin
|
48
|
+
result = @collection.get(@id, @options.get_options)
|
49
|
+
current = result.content
|
50
|
+
@cas = result.cas
|
51
|
+
rescue Error::DocumentNotFound
|
52
|
+
current = []
|
53
|
+
@cas = 0
|
54
|
+
end
|
55
|
+
current.each do |entry|
|
56
|
+
yield entry
|
57
|
+
end
|
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
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "couchbase/collection"
|
16
|
+
require "couchbase/options"
|
17
|
+
require "couchbase/errors"
|
18
|
+
|
19
|
+
module Couchbase
|
20
|
+
module Datastructures
|
21
|
+
# A {CouchbaseSet} is implements +Enumerable+ interface and backed by {Collection} document (more specifically
|
22
|
+
# a JSON array).
|
23
|
+
#
|
24
|
+
# Note: sets are restricted to containing primitive types only due to server-side comparison restrictions.
|
25
|
+
class CouchbaseSet
|
26
|
+
include Enumerable
|
27
|
+
|
28
|
+
# Create a new List, backed by the document identified by +id+ in +collection+.
|
29
|
+
#
|
30
|
+
# @param [String] id the id of the document to back the set.
|
31
|
+
# @param [Collection] collection the collection through which to interact with the document.
|
32
|
+
# @param [Options::CouchbaseSet] options customization of the datastructure
|
33
|
+
def initialize(id, collection, options = Options::CouchbaseSet.new)
|
34
|
+
@id = id
|
35
|
+
@collection = collection
|
36
|
+
@options = options
|
37
|
+
@cas = 0
|
38
|
+
end
|
39
|
+
|
40
|
+
# Calls the given block once for each element in the set, passing that element as a parameter.
|
41
|
+
#
|
42
|
+
# @yieldparam [Object] item
|
43
|
+
#
|
44
|
+
# @return [CouchbaseSet, Enumerable]
|
45
|
+
def each
|
46
|
+
if block_given?
|
47
|
+
begin
|
48
|
+
result = @collection.get(@id, @options.get_options)
|
49
|
+
current = result.content
|
50
|
+
@cas = result.cas
|
51
|
+
rescue Error::DocumentNotFound
|
52
|
+
current = []
|
53
|
+
@cas = 0
|
54
|
+
end
|
55
|
+
current.each do |entry|
|
56
|
+
yield entry
|
57
|
+
end
|
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,24 @@
|
|
1
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Couchbase
|
16
|
+
# This namespace includes easy-to-use wrappers for various concurrent data-structures.
|
17
|
+
module Datastructures
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require "couchbase/datastructures/couchbase_list"
|
22
|
+
require "couchbase/datastructures/couchbase_set"
|
23
|
+
require "couchbase/datastructures/couchbase_queue"
|
24
|
+
require "couchbase/datastructures/couchbase_map"
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# Copyright 2020-2021 Couchbase, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Couchbase
|
16
|
+
class DiagnosticsResult
|
17
|
+
class ServiceInfo
|
18
|
+
# @return [String] endpoint unique identifier
|
19
|
+
attr_accessor :id
|
20
|
+
|
21
|
+
# Possible states are:
|
22
|
+
#
|
23
|
+
# :disconnected:: the endpoint is not reachable
|
24
|
+
# :connecting:: currently connecting (includes auth, handshake, etc.)
|
25
|
+
# :connected:: connected and ready
|
26
|
+
# :disconnecting:: disconnecting (after being connected)
|
27
|
+
#
|
28
|
+
# @return [Symbol] state of the endpoint
|
29
|
+
attr_accessor :state
|
30
|
+
|
31
|
+
# @return [String, nil] optional string with additional explanation for the state
|
32
|
+
attr_accessor :details
|
33
|
+
|
34
|
+
# @return [Integer] how long ago the endpoint was active (in microseconds)
|
35
|
+
attr_accessor :last_activity_us
|
36
|
+
|
37
|
+
# @return [String] remote address of the connection
|
38
|
+
attr_accessor :remote
|
39
|
+
|
40
|
+
# @return [String] local address of the connection
|
41
|
+
attr_accessor :local
|
42
|
+
|
43
|
+
# @yieldparam [ServiceInfo] self
|
44
|
+
def initialize
|
45
|
+
yield self if block_given?
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_json(*args)
|
49
|
+
data = {
|
50
|
+
id: @id,
|
51
|
+
state: @state,
|
52
|
+
remote: @remote,
|
53
|
+
local: @local,
|
54
|
+
}
|
55
|
+
data[:details] = @details if @details
|
56
|
+
data[:last_activity_us] = @last_activity_us if @last_activity_us
|
57
|
+
data.to_json(*args)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [String] report id
|
62
|
+
attr_accessor :id
|
63
|
+
|
64
|
+
# @return [String] SDK identifier
|
65
|
+
attr_accessor :sdk
|
66
|
+
|
67
|
+
# Returns information about currently service endpoints, that known to the library at the moment.
|
68
|
+
#
|
69
|
+
# :kv:: Key/Value data service
|
70
|
+
# :query:: N1QL query service
|
71
|
+
# :analytics:: Analtyics service
|
72
|
+
# :search:: Full text search service
|
73
|
+
# :views:: Views service
|
74
|
+
# :mgmt:: Management service
|
75
|
+
#
|
76
|
+
# @return [Hash<Symbol, ServiceInfo>] map service types to info
|
77
|
+
attr_accessor :services
|
78
|
+
|
79
|
+
# @yieldparam [DiagnosticsResult] self
|
80
|
+
def initialize
|
81
|
+
@services = {}
|
82
|
+
yield self if block_given?
|
83
|
+
end
|
84
|
+
|
85
|
+
# @api private
|
86
|
+
# @return [Integer] version
|
87
|
+
attr_accessor :version
|
88
|
+
|
89
|
+
def to_json(*args)
|
90
|
+
{
|
91
|
+
version: @version,
|
92
|
+
id: @id,
|
93
|
+
sdk: @sdk,
|
94
|
+
services: @services,
|
95
|
+
}.to_json(*args)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class PingResult
|
100
|
+
class ServiceInfo
|
101
|
+
# @return [String] endpoint unique identifier
|
102
|
+
attr_accessor :id
|
103
|
+
|
104
|
+
# Possible states are:
|
105
|
+
#
|
106
|
+
# :ok:: endpoint is healthy
|
107
|
+
# :timeout:: endpoint didn't respond in time
|
108
|
+
# :error:: request to endpoint has failed, see {#error} for additional details
|
109
|
+
#
|
110
|
+
# @return [Symbol] state of the endpoint
|
111
|
+
attr_accessor :state
|
112
|
+
|
113
|
+
# @return [String, nil] optional string with additional explanation for the state
|
114
|
+
attr_accessor :error
|
115
|
+
|
116
|
+
# @return [Integer] how long ago the endpoint was active (in microseconds)
|
117
|
+
attr_accessor :latency
|
118
|
+
|
119
|
+
# @return [String] remote address of the connection
|
120
|
+
attr_accessor :remote
|
121
|
+
|
122
|
+
# @return [String] local address of the connection
|
123
|
+
attr_accessor :local
|
124
|
+
|
125
|
+
# @yieldparam [ServiceInfo] self
|
126
|
+
def initialize
|
127
|
+
@error = nil
|
128
|
+
yield self if block_given?
|
129
|
+
end
|
130
|
+
|
131
|
+
def to_json(*args)
|
132
|
+
data = {
|
133
|
+
id: @id,
|
134
|
+
state: @state,
|
135
|
+
remote: @remote,
|
136
|
+
local: @local,
|
137
|
+
latency: @latency,
|
138
|
+
}
|
139
|
+
data[:error] = @error if @error
|
140
|
+
data.to_json(*args)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# @return [String] report id
|
145
|
+
attr_accessor :id
|
146
|
+
|
147
|
+
# @return [String] SDK identifier
|
148
|
+
attr_accessor :sdk
|
149
|
+
|
150
|
+
# Returns information about currently service endpoints, that known to the library at the moment.
|
151
|
+
#
|
152
|
+
# :kv:: Key/Value data service
|
153
|
+
# :query:: N1QL query service
|
154
|
+
# :analytics:: Analtyics service
|
155
|
+
# :search:: Full text search service
|
156
|
+
# :views:: Views service
|
157
|
+
# :mgmt:: Management service
|
158
|
+
#
|
159
|
+
# @return [Hash<Symbol, ServiceInfo>] map service types to info
|
160
|
+
attr_accessor :services
|
161
|
+
|
162
|
+
# @yieldparam [DiagnosticsResult] self
|
163
|
+
def initialize
|
164
|
+
@services = {}
|
165
|
+
yield self if block_given?
|
166
|
+
end
|
167
|
+
|
168
|
+
# @api private
|
169
|
+
# @return [Integer] version
|
170
|
+
attr_accessor :version
|
171
|
+
|
172
|
+
def to_json(*args)
|
173
|
+
{
|
174
|
+
version: @version,
|
175
|
+
id: @id,
|
176
|
+
sdk: @sdk,
|
177
|
+
services: @services,
|
178
|
+
}.to_json(*args)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|