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,290 @@
|
|
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 LookupInSpec
|
17
|
+
# Fetches the content from a field (if present) at the given path
|
18
|
+
#
|
19
|
+
# @param [String, Symbol] path the path identifying where to get the value. When path is a symbol, the library will try to expand it as
|
20
|
+
# macro.
|
21
|
+
# @return [LookupInSpec]
|
22
|
+
def self.get(path)
|
23
|
+
case path
|
24
|
+
when Symbol
|
25
|
+
new(:get, expand_macro(path))
|
26
|
+
when ""
|
27
|
+
new(:get_doc, "")
|
28
|
+
else
|
29
|
+
new(:get, path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Checks if a value at the given path exists in the document
|
34
|
+
#
|
35
|
+
# @param [String] path the path to check if the field exists
|
36
|
+
# @return [LookupInSpec]
|
37
|
+
def self.exists(path)
|
38
|
+
new(:exists, path)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Counts the number of values at a given path in the document
|
42
|
+
#
|
43
|
+
# @param [String] path the path identifying where to count the values
|
44
|
+
# @return [LookupInSpec]
|
45
|
+
def self.count(path)
|
46
|
+
new(:count, path)
|
47
|
+
end
|
48
|
+
|
49
|
+
def xattr
|
50
|
+
@xattr = true
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
def xattr?
|
55
|
+
@xattr
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :type
|
59
|
+
attr_reader :path
|
60
|
+
|
61
|
+
# @api private
|
62
|
+
#
|
63
|
+
# @param [Symbol] macro
|
64
|
+
# @raise [Error::XattrUnknownMacro] if the macro cannot be expanded
|
65
|
+
def self.expand_macro(macro)
|
66
|
+
case macro
|
67
|
+
when :document
|
68
|
+
"$document"
|
69
|
+
when :expiry_time, :expiration_time
|
70
|
+
"$document.exptime"
|
71
|
+
when :cas
|
72
|
+
"$document.CAS"
|
73
|
+
when :seq_no, :sequence_number
|
74
|
+
"$document.seqno"
|
75
|
+
when :last_modified
|
76
|
+
"$document.last_modified"
|
77
|
+
when :is_deleted
|
78
|
+
"$document.deleted"
|
79
|
+
when :value_size_bytes
|
80
|
+
"$document.value_bytes"
|
81
|
+
when :rev_id, :revision_id
|
82
|
+
"$document.revid"
|
83
|
+
else
|
84
|
+
raise Error::XattrUnknownMacro, "unknown macro #{macro}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private_class_method :expand_macro
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
# @param [:get_doc, :get, :exists, :count] type of the lookup
|
93
|
+
# @param [String] path
|
94
|
+
def initialize(type, path)
|
95
|
+
@xattr = false
|
96
|
+
@type = type
|
97
|
+
@path = path
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class MutateInSpec
|
102
|
+
# Creates a command with the intention of replacing an existing value in a JSON document.
|
103
|
+
#
|
104
|
+
# If the path is empty (""), then the value will be used for the document's full body. Will
|
105
|
+
# error if the last element of the path does not exist.
|
106
|
+
#
|
107
|
+
# @param [String] path the path identifying where to replace the value.
|
108
|
+
# @param [Object, Symbol] value the value to replace with.
|
109
|
+
# When symbol specified and it is matches to known macro, it will be expanded
|
110
|
+
#
|
111
|
+
# @return [MutateInSpec]
|
112
|
+
def self.replace(path, value)
|
113
|
+
new(path.empty? ? :set_doc : :replace, path, value)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Creates a command with the intention of inserting a new value in a JSON object.
|
117
|
+
#
|
118
|
+
# Will error if the last element of the path already exists.
|
119
|
+
#
|
120
|
+
# @param [String] path the path identifying where to insert the value.
|
121
|
+
# @param [Object, Symbol] value the value to insert.
|
122
|
+
# When symbol specified and it is matches to known macro, it will be expanded
|
123
|
+
#
|
124
|
+
# @return [MutateInSpec]
|
125
|
+
def self.insert(path, value)
|
126
|
+
new(:dict_add, path, value)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Creates a command with the intention of removing an existing value in a JSON object.
|
130
|
+
#
|
131
|
+
# Will error if the path does not exist.
|
132
|
+
#
|
133
|
+
# @param path the path identifying what to remove.
|
134
|
+
#
|
135
|
+
# @return [MutateInSpec]
|
136
|
+
def self.remove(path)
|
137
|
+
new(path.empty? ? :remove_doc : :remove, path, nil)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Creates a command with the intention of upserting a value in a JSON object.
|
141
|
+
#
|
142
|
+
# That is, the value will be replaced if the path already exists, or inserted if not.
|
143
|
+
#
|
144
|
+
# @param [String] path the path identifying where to upsert the value.
|
145
|
+
# @param [Object, Symbol] value the value to upsert.
|
146
|
+
# When symbol specified and it is matches to known macro, it will be expanded
|
147
|
+
#
|
148
|
+
# @return [MutateInSpec]
|
149
|
+
def self.upsert(path, value)
|
150
|
+
new(:dict_upsert, path, value)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Creates a command with the intention of appending a value to an existing JSON array.
|
154
|
+
#
|
155
|
+
# Will error if the last element of the path does not exist or is not an array.
|
156
|
+
#
|
157
|
+
# @param [String] path the path identifying an array to which to append the value.
|
158
|
+
# @param [Array] values the value(s) to append.
|
159
|
+
#
|
160
|
+
# @return [MutateInSpec]
|
161
|
+
def self.array_append(path, values)
|
162
|
+
new(:array_push_last, path, values)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Creates a command with the intention of prepending a value to an existing JSON array.
|
166
|
+
#
|
167
|
+
# Will error if the last element of the path does not exist or is not an array.
|
168
|
+
#
|
169
|
+
# @param [String] path the path identifying an array to which to append the value.
|
170
|
+
# @param [Array] values the value(s) to prepend.
|
171
|
+
#
|
172
|
+
# @return [MutateInSpec]
|
173
|
+
def self.array_prepend(path, values)
|
174
|
+
new(:array_push_first, path, values)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Creates a command with the intention of inserting a value into an existing JSON array.
|
178
|
+
#
|
179
|
+
# Will error if the last element of the path does not exist or is not an array.
|
180
|
+
#
|
181
|
+
# @param [String] path the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"
|
182
|
+
# @param [Array] values the value(s) to insert.
|
183
|
+
#
|
184
|
+
# @return [MutateInSpec]
|
185
|
+
def self.array_insert(path, values)
|
186
|
+
new(:array_insert, path, values)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Creates a command with the intent of inserting a value into an existing JSON array, but only if the value
|
190
|
+
# is not already contained in the array (by way of string comparison).
|
191
|
+
#
|
192
|
+
# Will error if the last element of the path does not exist or is not an array.
|
193
|
+
#
|
194
|
+
# @param [String] path the path identifying an array to which to append the value, and an index. E.g. "foo.bar[3]"
|
195
|
+
# @param [Object, Symbol] value the value to insert.
|
196
|
+
#
|
197
|
+
# @return [MutateInSpec]
|
198
|
+
def self.array_add_unique(path, value)
|
199
|
+
new(:array_add_unique, path, value)
|
200
|
+
end
|
201
|
+
|
202
|
+
# Creates a command with the intent of incrementing a numerical field in a JSON object.
|
203
|
+
#
|
204
|
+
# If the field does not exist, then it is created and takes the value of +delta+
|
205
|
+
#
|
206
|
+
# @param [String] path the path identifying a numerical field to adjust or create
|
207
|
+
# @param [Integer] delta the value to increment the field by
|
208
|
+
#
|
209
|
+
# @return [MutateInSpec]
|
210
|
+
def self.increment(path, delta)
|
211
|
+
new(:counter, path, delta.abs)
|
212
|
+
end
|
213
|
+
|
214
|
+
# Creates a command with the intent of decrementing a numerical field in a JSON object.
|
215
|
+
#
|
216
|
+
# If the field does not exist, then it is created and takes the value of +delta+ * -1
|
217
|
+
#
|
218
|
+
# @param [String] path the path identifying a numerical field to adjust or create
|
219
|
+
# @param [Integer] delta the value to decrement the field by
|
220
|
+
#
|
221
|
+
# @return [MutateInSpec]
|
222
|
+
def self.decrement(path, delta)
|
223
|
+
new(:counter, path, -1 * delta.abs)
|
224
|
+
end
|
225
|
+
|
226
|
+
def xattr
|
227
|
+
@xattr = true
|
228
|
+
self
|
229
|
+
end
|
230
|
+
|
231
|
+
def create_path
|
232
|
+
@create_path = true
|
233
|
+
self
|
234
|
+
end
|
235
|
+
|
236
|
+
def xattr?
|
237
|
+
@xattr
|
238
|
+
end
|
239
|
+
|
240
|
+
def create_path?
|
241
|
+
@create_path
|
242
|
+
end
|
243
|
+
|
244
|
+
def expand_macros?
|
245
|
+
@expand_macros
|
246
|
+
end
|
247
|
+
|
248
|
+
CAS = "${Mutation.CAS}".freeze
|
249
|
+
SEQ_NO = "${Mutation.seqno}".freeze
|
250
|
+
VALUE_CRC32C = "${Mutation.value_crc32c}".freeze
|
251
|
+
|
252
|
+
attr_reader :type
|
253
|
+
attr_reader :path
|
254
|
+
attr_reader :param
|
255
|
+
|
256
|
+
private
|
257
|
+
|
258
|
+
def initialize(type, path, param)
|
259
|
+
@create_path = false
|
260
|
+
@param = nil
|
261
|
+
@xattr = false
|
262
|
+
@type = type
|
263
|
+
@path = path
|
264
|
+
@param =
|
265
|
+
case param
|
266
|
+
when :cas
|
267
|
+
CAS
|
268
|
+
when :seq_no, :sequence_number
|
269
|
+
SEQ_NO
|
270
|
+
when :value_crc32c, :value_crc
|
271
|
+
VALUE_CRC32C
|
272
|
+
else
|
273
|
+
param
|
274
|
+
end
|
275
|
+
@expand_macros = [CAS, SEQ_NO, VALUE_CRC32C].include?(@param)
|
276
|
+
@xattr = true if @expand_macros
|
277
|
+
return if @param.nil?
|
278
|
+
|
279
|
+
@param =
|
280
|
+
case type
|
281
|
+
when :counter
|
282
|
+
@param.to_i
|
283
|
+
when :array_push_first, :array_push_last, :array_insert
|
284
|
+
@param.map { |entry| JSON.generate(entry) }.join(",")
|
285
|
+
else
|
286
|
+
JSON.generate(@param)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright 2023. 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
|
+
# @api private
|
17
|
+
class TranscoderFlags
|
18
|
+
FORMAT_MAP = {
|
19
|
+
reserved: 0,
|
20
|
+
private: 1,
|
21
|
+
json: 2,
|
22
|
+
binary: 3,
|
23
|
+
string: 4,
|
24
|
+
}.freeze
|
25
|
+
INV_FORMAT_MAP = FORMAT_MAP.invert.freeze
|
26
|
+
|
27
|
+
COMPRESSION_MAP = {none: 0}.freeze
|
28
|
+
INV_COMPRESSION_MAP = COMPRESSION_MAP.invert
|
29
|
+
|
30
|
+
attr_reader :format
|
31
|
+
attr_reader :compression
|
32
|
+
attr_reader :lower_bits
|
33
|
+
|
34
|
+
def initialize(format:, compression: :none, lower_bits: 0)
|
35
|
+
@format = format
|
36
|
+
@compression = compression
|
37
|
+
@lower_bits = lower_bits
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.decode(flags)
|
41
|
+
return TranscoderFlags.new(format: flags) if flags.is_a?(Symbol)
|
42
|
+
|
43
|
+
common_flags = flags >> 24
|
44
|
+
lower_bits = flags & 0x00ffff
|
45
|
+
|
46
|
+
return TranscoderFlags.new(format: nil, lower_bits: lower_bits) if common_flags.zero?
|
47
|
+
|
48
|
+
compression_bits = common_flags >> 5
|
49
|
+
format_bits = common_flags & 0x0f
|
50
|
+
TranscoderFlags.new(
|
51
|
+
format: INV_FORMAT_MAP[format_bits],
|
52
|
+
compression: INV_COMPRESSION_MAP[compression_bits],
|
53
|
+
lower_bits: lower_bits
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def encode
|
58
|
+
common_flags = (COMPRESSION_MAP[@compression] << 5) | FORMAT_MAP[@format]
|
59
|
+
(common_flags << 24) | @lower_bits
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright 2021 Couchbase, Inc.
|
2
|
+
# Copyright 2020-Present Couchbase, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "time"
|
17
|
+
|
18
|
+
module Couchbase
|
19
|
+
module Utils
|
20
|
+
class GenericLoggerAdapter
|
21
|
+
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%6N".freeze
|
22
|
+
|
23
|
+
def initialize(logger, verbose: false)
|
24
|
+
@logger = logger
|
25
|
+
@verbose = verbose
|
26
|
+
end
|
27
|
+
|
28
|
+
def log(level, thread_id, seconds, nanoseconds, payload, filename, line, function)
|
29
|
+
return unless @logger.respond_to?(level)
|
30
|
+
|
31
|
+
progname = "cxxcbc##{thread_id}"
|
32
|
+
payload += " at #{filename}:#{line} #{function}" if @verbose && filename
|
33
|
+
@logger.send(level,
|
34
|
+
"[#{::Time.at(seconds, nanoseconds, :nanosecond).strftime(DATETIME_FORMAT)} #{progname}] #{level} -- #{payload}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright 2021 Couchbase, Inc.
|
2
|
+
# Copyright 2020-Present Couchbase, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "logger"
|
17
|
+
require "time"
|
18
|
+
|
19
|
+
module Couchbase
|
20
|
+
module Utils
|
21
|
+
class StdlibLoggerAdapter
|
22
|
+
def initialize(logger, verbose: false)
|
23
|
+
raise ArgumentError, "logger argument must be or derive from stdlib Logger class" unless logger.is_a?(::Logger)
|
24
|
+
|
25
|
+
@logger = logger
|
26
|
+
@verbose = verbose
|
27
|
+
end
|
28
|
+
|
29
|
+
def log(level, thread_id, seconds, nanoseconds, payload, filename, line, function)
|
30
|
+
logdev = @logger.instance_variable_get(:@logdev)
|
31
|
+
return unless logdev
|
32
|
+
|
33
|
+
severity = map_spdlog_level(level)
|
34
|
+
return unless severity
|
35
|
+
|
36
|
+
progname = "cxxcbc##{thread_id}"
|
37
|
+
payload += " at #{filename}:#{line} #{function}" if @verbose && filename
|
38
|
+
logdev.write(
|
39
|
+
@logger.send(:format_message, @logger.send(:format_severity, severity), ::Time.at(seconds, nanoseconds, :nanosecond), progname,
|
40
|
+
payload)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def map_spdlog_level(level)
|
47
|
+
case level
|
48
|
+
when :trace, :debug
|
49
|
+
::Logger::Severity::DEBUG
|
50
|
+
when :info
|
51
|
+
::Logger::Severity::INFO
|
52
|
+
when :warn
|
53
|
+
::Logger::Severity::WARN
|
54
|
+
when :error
|
55
|
+
::Logger::Severity::ERROR
|
56
|
+
when :critical
|
57
|
+
::Logger::Severity::FATAL
|
58
|
+
else # rubocop:disable Style/EmptyElse
|
59
|
+
# covers :off
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,69 @@
|
|
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 "time"
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
module Utils
|
19
|
+
# Various Time utilities
|
20
|
+
module Time
|
21
|
+
RELATIVE_EXPIRY_CUTOFF_SECONDS = 30 * 24 * 60 * 60
|
22
|
+
WORKAROUND_EXPIRY_CUTOFF_SECONDS = 50 * 365 * 24 * 60 * 60
|
23
|
+
|
24
|
+
module_function
|
25
|
+
|
26
|
+
# @param [Integer, #in_seconds, Time, nil] time_or_duration expiration time to associate with the document
|
27
|
+
def extract_expiry_time(time_or_duration)
|
28
|
+
if time_or_duration.respond_to?(:in_seconds) # Duration
|
29
|
+
[:duration, time_or_duration.in_seconds]
|
30
|
+
elsif time_or_duration.respond_to?(:tv_sec) # Time
|
31
|
+
[:time_point, time_or_duration.tv_sec]
|
32
|
+
elsif time_or_duration.is_a?(Integer)
|
33
|
+
if time_or_duration < RELATIVE_EXPIRY_CUTOFF_SECONDS
|
34
|
+
# looks like valid relative duration as specified in protocol (less than 30 days)
|
35
|
+
[:duration, time_or_duration]
|
36
|
+
elsif time_or_duration > WORKAROUND_EXPIRY_CUTOFF_SECONDS
|
37
|
+
effective_expiry = ::Time.at(time_or_duration).utc
|
38
|
+
warn "The specified expiry duration #{time_or_duration} is longer than 50 years. For bug-compatibility " \
|
39
|
+
"with previous versions of SDK 3.0.x, the number of seconds in the duration will be interpreted as " \
|
40
|
+
"the epoch second when the document should expire (#{effective_expiry}). Stuffing an epoch second " \
|
41
|
+
"into a Duration is deprecated and will no longer work in SDK 3.1. Consider using Time instance instead."
|
42
|
+
[:time_point, time_or_duration]
|
43
|
+
else
|
44
|
+
[:time_point, ::Time.now.tv_sec + time_or_duration]
|
45
|
+
end
|
46
|
+
else
|
47
|
+
[:duration, time_or_duration]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# This method converts its argument to milliseconds
|
52
|
+
#
|
53
|
+
# 1. Integer values are interpreted as a number of milliseconds
|
54
|
+
# 2. If the argument is a Duration-like object and responds to #in_milliseconds,
|
55
|
+
# then use it and convert result to Integer
|
56
|
+
# 3. Otherwise invoke #to_i on the argument and interpret it as a number of milliseconds
|
57
|
+
def extract_duration(number_or_duration)
|
58
|
+
return unless number_or_duration
|
59
|
+
return number_or_duration if number_or_duration.class == Integer # rubocop:disable Style/ClassEqualityComparison avoid overrides of #is_a?, #kind_of?
|
60
|
+
|
61
|
+
if number_or_duration.respond_to?(:in_milliseconds)
|
62
|
+
number_or_duration.public_send(:in_milliseconds)
|
63
|
+
else
|
64
|
+
number_or_duration
|
65
|
+
end.to_i
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
# Module for internal tools, extensions and utilities
|
17
|
+
module Utils
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require "couchbase/utils/time"
|
@@ -0,0 +1,23 @@
|
|
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
|
+
# Version of the library and all bundled dependencies
|
17
|
+
#
|
18
|
+
# @example Display version (+Couchbase::BUILD_INFO+ contains more details)
|
19
|
+
# $ ruby -rcouchbase -e 'pp Couchbase::VERSION'
|
20
|
+
# {:sdk=>"3.4.0", :ruby_abi=>"3.1.0", :revision=>"416fe68e6029ec8a4c40611cf6e6b30d3b90d20f"}
|
21
|
+
VERSION = {} unless defined?(VERSION) # rubocop:disable Style/MutableConstant
|
22
|
+
VERSION.update(:sdk => "3.5.0".freeze)
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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 "json"
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
class Bucket
|
19
|
+
class ViewRow
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :id
|
22
|
+
|
23
|
+
# @return [#to_json]
|
24
|
+
attr_accessor :key
|
25
|
+
|
26
|
+
# @return [#to_json]
|
27
|
+
attr_accessor :value
|
28
|
+
|
29
|
+
# @yieldparam [ViewRow] self
|
30
|
+
def initialize
|
31
|
+
yield self if block_given?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ViewMetaData
|
36
|
+
# @return [Integer]
|
37
|
+
attr_accessor :total_rows
|
38
|
+
|
39
|
+
# @api private
|
40
|
+
attr_writer :debug_info
|
41
|
+
|
42
|
+
def debug
|
43
|
+
JSON.parse(@debug_info)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @yieldparam [ViewMetaData] self
|
47
|
+
def initialize
|
48
|
+
yield self if block_given?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ViewResult
|
53
|
+
# @return [ViewMetaData] returns object representing additional metadata associated with this query
|
54
|
+
attr_accessor :meta_data
|
55
|
+
|
56
|
+
# @return [Array<ViewRow>]
|
57
|
+
attr_accessor :rows
|
58
|
+
|
59
|
+
# @yieldparam [ViewResult] self
|
60
|
+
def initialize
|
61
|
+
yield self if block_given?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/couchbase.rb
ADDED
@@ -0,0 +1,28 @@
|
|
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/version"
|
16
|
+
require "couchbase/libcouchbase"
|
17
|
+
require "couchbase/logger"
|
18
|
+
require "couchbase/cluster"
|
19
|
+
|
20
|
+
require "couchbase/railtie" if defined?(Rails)
|
21
|
+
|
22
|
+
# @!macro uncommitted
|
23
|
+
# @couchbase.stability
|
24
|
+
# Uncommitted: This API may change in the future.
|
25
|
+
#
|
26
|
+
# @!macro volatile
|
27
|
+
# @couchbase.stability
|
28
|
+
# Volatile: This API is subject to change at any time.
|
@@ -0,0 +1,27 @@
|
|
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
|
+
module Generators
|
17
|
+
class ConfigGenerator < Rails::Generators::Base
|
18
|
+
desc "Creates a Couchbase configuration file at config/couchbase.yml"
|
19
|
+
|
20
|
+
source_root File.expand_path(File.join("..", "templates"), __FILE__)
|
21
|
+
|
22
|
+
def create_config_file
|
23
|
+
template "couchbase.yml", File.join("config", "couchbase.yml")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|