couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19
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 +4 -4
- data/.github/workflows/tests-6.0.3.yml +49 -0
- data/.github/workflows/tests.yml +47 -0
- data/.gitmodules +3 -0
- data/.idea/dictionaries/gem_terms.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +1 -0
- data/.idea/vcs.xml +1 -0
- data/Gemfile +1 -0
- data/README.md +55 -2
- data/Rakefile +18 -0
- data/bin/init-cluster +62 -0
- data/bin/setup +1 -0
- data/couchbase.gemspec +3 -2
- data/examples/crud.rb +1 -2
- data/examples/managing_buckets.rb +47 -0
- data/examples/managing_collections.rb +58 -0
- data/examples/managing_query_indexes.rb +63 -0
- data/examples/query.rb +3 -2
- data/examples/query_with_consistency.rb +76 -0
- data/examples/subdocument.rb +23 -1
- data/ext/.clang-format +1 -1
- data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
- data/ext/.idea/vcs.xml +1 -0
- data/ext/CMakeLists.txt +30 -12
- data/ext/build_version.hxx.in +26 -0
- data/ext/couchbase/bucket.hxx +69 -8
- data/ext/couchbase/cluster.hxx +70 -54
- data/ext/couchbase/collections_manifest.hxx +3 -3
- data/ext/couchbase/configuration.hxx +14 -0
- data/ext/couchbase/couchbase.cxx +2044 -383
- data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
- data/ext/couchbase/io/http_message.hxx +5 -1
- data/ext/couchbase/io/http_parser.hxx +2 -1
- data/ext/couchbase/io/http_session.hxx +6 -3
- data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
- data/ext/couchbase/io/mcbp_parser.hxx +99 -0
- data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
- data/ext/couchbase/io/session_manager.hxx +37 -22
- data/ext/couchbase/mutation_token.hxx +2 -1
- data/ext/couchbase/operations.hxx +38 -8
- data/ext/couchbase/operations/bucket_create.hxx +138 -0
- data/ext/couchbase/operations/bucket_drop.hxx +65 -0
- data/ext/couchbase/operations/bucket_flush.hxx +65 -0
- data/ext/couchbase/operations/bucket_get.hxx +69 -0
- data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
- data/ext/couchbase/operations/bucket_settings.hxx +111 -0
- data/ext/couchbase/operations/bucket_update.hxx +115 -0
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
- data/ext/couchbase/operations/collection_create.hxx +86 -0
- data/ext/couchbase/operations/collection_drop.hxx +82 -0
- data/ext/couchbase/operations/command.hxx +10 -10
- data/ext/couchbase/operations/document_decrement.hxx +80 -0
- data/ext/couchbase/operations/document_exists.hxx +80 -0
- data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
- data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
- data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
- data/ext/couchbase/operations/document_increment.hxx +80 -0
- data/ext/couchbase/operations/document_insert.hxx +74 -0
- data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
- data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
- data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
- data/ext/couchbase/operations/document_remove.hxx +67 -0
- data/ext/couchbase/operations/document_replace.hxx +76 -0
- data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
- data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
- data/ext/couchbase/operations/document_upsert.hxx +74 -0
- data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
- data/ext/couchbase/operations/query_index_create.hxx +134 -0
- data/ext/couchbase/operations/query_index_drop.hxx +108 -0
- data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/scope_create.hxx +81 -0
- data/ext/couchbase/operations/scope_drop.hxx +79 -0
- data/ext/couchbase/operations/scope_get_all.hxx +72 -0
- data/ext/couchbase/protocol/client_opcode.hxx +35 -0
- data/ext/couchbase/protocol/client_request.hxx +56 -9
- data/ext/couchbase/protocol/client_response.hxx +52 -15
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
- data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
- data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
- data/ext/couchbase/protocol/cmd_get.hxx +31 -8
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
- data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
- data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
- data/ext/couchbase/protocol/cmd_info.hxx +1 -0
- data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
- data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
- data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
- data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
- data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
- data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
- data/ext/couchbase/protocol/durability_level.hxx +67 -0
- data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
- data/ext/couchbase/protocol/hello_feature.hxx +137 -0
- data/ext/couchbase/protocol/server_opcode.hxx +57 -0
- data/ext/couchbase/protocol/server_request.hxx +122 -0
- data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
- data/ext/couchbase/utils/byteswap.hxx +1 -2
- data/ext/couchbase/utils/url_codec.hxx +225 -0
- data/ext/couchbase/version.hxx +3 -1
- data/ext/extconf.rb +4 -1
- data/ext/test/main.cxx +37 -113
- data/ext/third_party/snappy/.appveyor.yml +36 -0
- data/ext/third_party/snappy/.gitignore +8 -0
- data/ext/third_party/snappy/.travis.yml +98 -0
- data/ext/third_party/snappy/AUTHORS +1 -0
- data/ext/third_party/snappy/CMakeLists.txt +345 -0
- data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
- data/ext/third_party/snappy/COPYING +54 -0
- data/ext/third_party/snappy/NEWS +188 -0
- data/ext/third_party/snappy/README.md +148 -0
- data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
- data/ext/third_party/snappy/cmake/config.h.in +59 -0
- data/ext/third_party/snappy/docs/README.md +72 -0
- data/ext/third_party/snappy/format_description.txt +110 -0
- data/ext/third_party/snappy/framing_format.txt +135 -0
- data/ext/third_party/snappy/snappy-c.cc +90 -0
- data/ext/third_party/snappy/snappy-c.h +138 -0
- data/ext/third_party/snappy/snappy-internal.h +315 -0
- data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
- data/ext/third_party/snappy/snappy-sinksource.h +182 -0
- data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
- data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
- data/ext/third_party/snappy/snappy-test.cc +613 -0
- data/ext/third_party/snappy/snappy-test.h +526 -0
- data/ext/third_party/snappy/snappy.cc +1770 -0
- data/ext/third_party/snappy/snappy.h +209 -0
- data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
- data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
- data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
- data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
- data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
- data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
- data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
- data/ext/third_party/snappy/testdata/geo.protodata +0 -0
- data/ext/third_party/snappy/testdata/html +1 -0
- data/ext/third_party/snappy/testdata/html_x_4 +1 -0
- data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
- data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
- data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
- data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
- data/ext/third_party/snappy/testdata/urls.10K +10000 -0
- data/lib/couchbase/binary_collection.rb +33 -76
- data/lib/couchbase/binary_collection_options.rb +94 -0
- data/lib/couchbase/bucket.rb +9 -3
- data/lib/couchbase/cluster.rb +161 -23
- data/lib/couchbase/collection.rb +108 -191
- data/lib/couchbase/collection_options.rb +430 -0
- data/lib/couchbase/errors.rb +136 -134
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/management/analytics_index_manager.rb +185 -9
- data/lib/couchbase/management/bucket_manager.rb +84 -33
- data/lib/couchbase/management/collection_manager.rb +166 -1
- data/lib/couchbase/management/query_index_manager.rb +261 -0
- data/lib/couchbase/management/search_index_manager.rb +291 -0
- data/lib/couchbase/management/user_manager.rb +12 -10
- data/lib/couchbase/management/view_index_manager.rb +151 -1
- data/lib/couchbase/mutation_state.rb +11 -1
- data/lib/couchbase/scope.rb +4 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +113 -18
- data/.travis.yml +0 -7
- data/ext/couchbase/io/binary_parser.hxx +0 -64
- data/lib/couchbase/results.rb +0 -307
@@ -12,6 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
+
require "couchbase/binary_collection_options"
|
16
|
+
|
15
17
|
module Couchbase
|
16
18
|
class BinaryCollection
|
17
19
|
alias_method :inspect, :to_s
|
@@ -19,15 +21,16 @@ module Couchbase
|
|
19
21
|
# @param [Couchbase::Collection] collection parent collection
|
20
22
|
def initialize(collection)
|
21
23
|
@collection = collection
|
24
|
+
@backend = collection.instance_variable_get("@backend")
|
22
25
|
end
|
23
26
|
|
24
27
|
# Appends binary content to the document
|
25
|
-
#
|
28
|
+
#
|
26
29
|
# @param [String] id the document id which is used to uniquely identify it
|
27
30
|
# @param [String] content the binary content to append to the document
|
28
31
|
# @param [AppendOptions] options custom options to customize the request
|
29
32
|
#
|
30
|
-
# @return [MutationResult]
|
33
|
+
# @return [Collection::MutationResult]
|
31
34
|
def append(id, content, options = AppendOptions.new) end
|
32
35
|
|
33
36
|
# Prepends binary content to the document
|
@@ -36,93 +39,47 @@ module Couchbase
|
|
36
39
|
# @param [String] content the binary content to prepend to the document
|
37
40
|
# @param [PrependOptions] options custom options to customize the request
|
38
41
|
#
|
39
|
-
# @return [MutationResult]
|
42
|
+
# @return [Collection::MutationResult]
|
40
43
|
def prepend(id, content, options = PrependOptions.new) end
|
41
44
|
|
42
45
|
# Increments the counter document by one of the number defined in the options
|
43
|
-
#
|
46
|
+
#
|
44
47
|
# @param [String] id the document id which is used to uniquely identify it
|
45
48
|
# @param [IncrementOptions] options custom options to customize the request
|
46
49
|
#
|
47
50
|
# @return [CounterResult]
|
48
|
-
def increment(id, options = IncrementOptions.new)
|
51
|
+
def increment(id, options = IncrementOptions.new)
|
52
|
+
resp = @backend.document_increment(@collection.bucket_name, "#{@collection.scope_name}.#{@collection.name}", id, {
|
53
|
+
delta: options.delta,
|
54
|
+
initial_value: options.initial,
|
55
|
+
expiration: options.expiration,
|
56
|
+
durability_level: options.durability_level,
|
57
|
+
})
|
58
|
+
CounterResult.new do |res|
|
59
|
+
res.cas = resp[:cas]
|
60
|
+
res.content = resp[:content]
|
61
|
+
res.mutation_token = @collection.send(:extract_mutation_token, resp)
|
62
|
+
end
|
63
|
+
end
|
49
64
|
|
50
65
|
# Decrements the counter document by one of the number defined in the options
|
51
66
|
#
|
52
67
|
# @param [String] id the document id which is used to uniquely identify it
|
53
|
-
# @param [
|
68
|
+
# @param [DecrementOptions] options custom options to customize the request
|
54
69
|
#
|
55
70
|
# @return [CounterResult]
|
56
|
-
def decrement(id, options = DecrementOptions.new)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
class PrependOptions < CommonOptions
|
68
|
-
# @return [Integer] The default CAS used (0 means no CAS in this context)
|
69
|
-
attr_accessor :cas
|
70
|
-
|
71
|
-
def initialize
|
72
|
-
yield self if block_given?
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class IncrementOptions < CommonOptions
|
77
|
-
# @return [Integer] the delta for the operation
|
78
|
-
attr_reader :delta
|
79
|
-
|
80
|
-
# @return [Integer] if present, holds the initial value
|
81
|
-
attr_accessor :initial
|
82
|
-
|
83
|
-
# @return [Integer] if set, holds the expiration for the operation
|
84
|
-
attr_accessor :expiration
|
85
|
-
|
86
|
-
# @return [Integer] if set, holds the CAS value for this operation
|
87
|
-
attr_accessor :cas
|
88
|
-
|
89
|
-
def initialize
|
90
|
-
@delta = 1
|
91
|
-
yield self if block_given?
|
92
|
-
end
|
93
|
-
|
94
|
-
def delta=(value)
|
95
|
-
if delta < 0
|
96
|
-
raise ArgumentError, "the delta cannot be less than 0"
|
97
|
-
end
|
98
|
-
@delta = value
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
class DecrementOptions < CommonOptions
|
103
|
-
# @return [Integer] the delta for the operation
|
104
|
-
attr_reader :delta
|
105
|
-
|
106
|
-
# @return [Integer] if present, holds the initial value
|
107
|
-
attr_accessor :initial
|
108
|
-
|
109
|
-
# @return [Integer] if set, holds the expiration for the operation
|
110
|
-
attr_accessor :expiration
|
111
|
-
|
112
|
-
# @return [Integer] if set, holds the CAS value for this operation
|
113
|
-
attr_accessor :cas
|
114
|
-
|
115
|
-
def initialize
|
116
|
-
@delta = 1
|
117
|
-
yield self if block_given?
|
118
|
-
end
|
119
|
-
|
120
|
-
def delta=(value)
|
121
|
-
if delta < 0
|
122
|
-
raise ArgumentError, "the delta cannot be less than 0"
|
123
|
-
end
|
124
|
-
@delta = value
|
71
|
+
def decrement(id, options = DecrementOptions.new)
|
72
|
+
resp = @backend.document_decrement(@collection.bucket_name, "#{@collection.scope_name}.#{@collection.name}", id, {
|
73
|
+
delta: options.delta,
|
74
|
+
initial_value: options.initial,
|
75
|
+
expiration: options.expiration,
|
76
|
+
durability_level: options.durability_level,
|
77
|
+
})
|
78
|
+
CounterResult.new do |res|
|
79
|
+
res.cas = resp[:cas]
|
80
|
+
res.content = resp[:content]
|
81
|
+
res.mutation_token = @collection.send(:extract_mutation_token, resp)
|
125
82
|
end
|
126
83
|
end
|
127
84
|
end
|
128
|
-
end
|
85
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Copyright 2020 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_options"
|
16
|
+
|
17
|
+
module Couchbase
|
18
|
+
class BinaryCollection
|
19
|
+
class AppendOptions < CommonOptions
|
20
|
+
# @return [Integer] The default CAS used (0 means no CAS in this context)
|
21
|
+
attr_accessor :cas
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
yield self if block_given?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class PrependOptions < CommonOptions
|
29
|
+
# @return [Integer] The default CAS used (0 means no CAS in this context)
|
30
|
+
attr_accessor :cas
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
yield self if block_given?
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class IncrementOptions < CommonOptions
|
38
|
+
# @return [Integer] the delta for the operation
|
39
|
+
attr_reader :delta
|
40
|
+
|
41
|
+
# @return [Integer] if present, holds the initial value
|
42
|
+
attr_accessor :initial
|
43
|
+
|
44
|
+
# @return [Integer] if set, holds the expiration for the operation
|
45
|
+
attr_accessor :expiration
|
46
|
+
|
47
|
+
# @return [:none, :majority, :majority_and_persist_to_active, :persist_to_majority] level of durability
|
48
|
+
attr_accessor :durability_level
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@delta = 1
|
52
|
+
yield self if block_given?
|
53
|
+
end
|
54
|
+
|
55
|
+
def delta=(value)
|
56
|
+
if delta < 0
|
57
|
+
raise ArgumentError, "the delta cannot be less than 0"
|
58
|
+
end
|
59
|
+
@delta = value
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class DecrementOptions < CommonOptions
|
64
|
+
# @return [Integer] the delta for the operation
|
65
|
+
attr_reader :delta
|
66
|
+
|
67
|
+
# @return [Integer] if present, holds the initial value
|
68
|
+
attr_accessor :initial
|
69
|
+
|
70
|
+
# @return [Integer] if set, holds the expiration for the operation
|
71
|
+
attr_accessor :expiration
|
72
|
+
|
73
|
+
# @return [:none, :majority, :majority_and_persist_to_active, :persist_to_majority] level of durability
|
74
|
+
attr_accessor :durability_level
|
75
|
+
|
76
|
+
def initialize
|
77
|
+
@delta = 1
|
78
|
+
yield self if block_given?
|
79
|
+
end
|
80
|
+
|
81
|
+
def delta=(value)
|
82
|
+
if delta < 0
|
83
|
+
raise ArgumentError, "the delta cannot be less than 0"
|
84
|
+
end
|
85
|
+
@delta = value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class CounterResult < ::Couchbase::Collection::MutationResult
|
90
|
+
# @return [Integer] current value of the counter
|
91
|
+
attr_accessor :content
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/couchbase/bucket.rb
CHANGED
@@ -12,7 +12,8 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require
|
15
|
+
require "couchbase/scope"
|
16
|
+
require "couchbase/management/collection_manager"
|
16
17
|
|
17
18
|
module Couchbase
|
18
19
|
class Bucket
|
@@ -29,7 +30,7 @@ module Couchbase
|
|
29
30
|
#
|
30
31
|
# @return [Scope]
|
31
32
|
def default_scope
|
32
|
-
Scope.new(@backend, @name, :
|
33
|
+
Scope.new(@backend, @name, :_default)
|
33
34
|
end
|
34
35
|
|
35
36
|
# Get a named scope
|
@@ -57,6 +58,11 @@ module Couchbase
|
|
57
58
|
default_scope.default_collection
|
58
59
|
end
|
59
60
|
|
61
|
+
# @return [Management::CollectionManager]
|
62
|
+
def collections
|
63
|
+
Management::CollectionManager.new(@backend, @name)
|
64
|
+
end
|
65
|
+
|
60
66
|
# Performs application-level ping requests against services in the couchbase cluster
|
61
67
|
#
|
62
68
|
# @return [PingResult]
|
@@ -78,4 +84,4 @@ module Couchbase
|
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
81
|
-
end
|
87
|
+
end
|
data/lib/couchbase/cluster.rb
CHANGED
@@ -12,14 +12,14 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
require
|
16
|
-
require
|
15
|
+
require "couchbase/authenticator"
|
16
|
+
require "couchbase/bucket"
|
17
17
|
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
21
|
-
require
|
22
|
-
require
|
18
|
+
require "couchbase/management/user_manager"
|
19
|
+
require "couchbase/management/bucket_manager"
|
20
|
+
require "couchbase/management/query_index_manager"
|
21
|
+
require "couchbase/management/analytics_index_manager"
|
22
|
+
require "couchbase/management/search_index_manager"
|
23
23
|
|
24
24
|
module Couchbase
|
25
25
|
class Cluster
|
@@ -40,24 +40,36 @@ module Couchbase
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Performs a query against the query (N1QL) services
|
43
|
-
#
|
43
|
+
#
|
44
44
|
# @param [String] statement the N1QL query statement
|
45
45
|
# @param [QueryOptions] options the custom options for this query
|
46
46
|
#
|
47
47
|
# @return [QueryResult]
|
48
48
|
def query(statement, options = QueryOptions.new)
|
49
|
-
resp = @backend.
|
49
|
+
resp = @backend.document_query(statement, {
|
50
|
+
timeout: options.timeout,
|
50
51
|
adhoc: options.adhoc,
|
51
52
|
client_context_id: options.client_context_id,
|
52
53
|
max_parallelism: options.max_parallelism,
|
53
54
|
readonly: options.readonly,
|
55
|
+
scan_wait: options.scan_wait,
|
54
56
|
scan_cap: options.scan_cap,
|
55
57
|
pipeline_batch: options.pipeline_batch,
|
56
58
|
pipeline_cap: options.pipeline_cap,
|
57
59
|
metrics: options.metrics,
|
58
60
|
profile: options.profile,
|
59
61
|
positional_parameters: options.instance_variable_get("@positional_parameters")&.map { |p| JSON.dump(p) },
|
60
|
-
named_parameters: options.instance_variable_get("@named_parameters")&.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) }
|
62
|
+
named_parameters: options.instance_variable_get("@named_parameters")&.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) },
|
63
|
+
raw_parameters: options.instance_variable_get("@raw_parameters"),
|
64
|
+
scan_consistency: options.instance_variable_get("@scan_consistency"),
|
65
|
+
mutation_state: options.instance_variable_get("@mutation_state")&.tokens&.map { |t|
|
66
|
+
{
|
67
|
+
bucket_name: t.bucket_name,
|
68
|
+
partition_id: t.partition_id,
|
69
|
+
partition_uuid: t.partition_uuid,
|
70
|
+
sequence_number: t.sequence_number,
|
71
|
+
}
|
72
|
+
},
|
61
73
|
})
|
62
74
|
|
63
75
|
QueryResult.new do |res|
|
@@ -85,7 +97,7 @@ module Couchbase
|
|
85
97
|
end
|
86
98
|
|
87
99
|
# Performs an analytics query
|
88
|
-
#
|
100
|
+
#
|
89
101
|
# @param [String] statement the N1QL query statement
|
90
102
|
# @param [AnalyticsOptions] options the custom options for this query
|
91
103
|
#
|
@@ -101,24 +113,29 @@ module Couchbase
|
|
101
113
|
# @return [QueryResult]
|
102
114
|
def search_query(index_name, query, options = SearchOptions.new) end
|
103
115
|
|
116
|
+
# @return [Management::UserManager]
|
104
117
|
def users
|
105
|
-
UserManager.new(@backend)
|
118
|
+
Management::UserManager.new(@backend)
|
106
119
|
end
|
107
120
|
|
121
|
+
# @return [Management::BucketManager]
|
108
122
|
def buckets
|
109
|
-
BucketManager.new(@backend)
|
123
|
+
Management::BucketManager.new(@backend)
|
110
124
|
end
|
111
125
|
|
126
|
+
# @return [Management::QueryIndexManager]
|
112
127
|
def query_indexes
|
113
|
-
QueryIndexManager.new(@backend)
|
128
|
+
Management::QueryIndexManager.new(@backend)
|
114
129
|
end
|
115
130
|
|
131
|
+
# @return [Management::AnalyticsIndexManager]
|
116
132
|
def analytics_indexes
|
117
|
-
AnalyticsIndexManager.new(@backend)
|
133
|
+
Management::AnalyticsIndexManager.new(@backend)
|
118
134
|
end
|
119
135
|
|
136
|
+
# @return [Management::SearchIndexManager]
|
120
137
|
def search_indexes
|
121
|
-
SearchIndexManager.new(@backend)
|
138
|
+
Management::SearchIndexManager.new(@backend)
|
122
139
|
end
|
123
140
|
|
124
141
|
def disconnect
|
@@ -141,6 +158,9 @@ module Couchbase
|
|
141
158
|
end
|
142
159
|
|
143
160
|
class QueryOptions
|
161
|
+
# @return [Integer] Timeout in milliseconds
|
162
|
+
attr_accessor :timeout
|
163
|
+
|
144
164
|
# @return [Boolean] Allows turning this request into a prepared statement query
|
145
165
|
attr_accessor :adhoc
|
146
166
|
|
@@ -153,6 +173,14 @@ module Couchbase
|
|
153
173
|
# @return [Boolean] Allows explicitly marking a query as being readonly and not mutating and documents on the server side.
|
154
174
|
attr_accessor :readonly
|
155
175
|
|
176
|
+
# Allows customizing how long (in milliseconds) the query engine is willing to wait until the index catches up to whatever scan consistency is asked for in this query.
|
177
|
+
#
|
178
|
+
# @note that if +:not_bounded+ consistency level is used, this method doesn't do anything
|
179
|
+
# at all. If no value is provided to this method, the server default is used.
|
180
|
+
#
|
181
|
+
# @return [Integer] The maximum duration (in milliseconds) the query engine is willing to wait before failing.
|
182
|
+
attr_accessor :scan_wait
|
183
|
+
|
156
184
|
# @return [Integer] Supports customizing the maximum buffered channel size between the indexer and the query service
|
157
185
|
attr_accessor :scan_cap
|
158
186
|
|
@@ -169,34 +197,45 @@ module Couchbase
|
|
169
197
|
attr_accessor :profile
|
170
198
|
|
171
199
|
def initialize
|
200
|
+
@timeout = 75_000 # ms
|
172
201
|
@adhoc = true
|
173
|
-
|
202
|
+
@raw_parameters = {}
|
174
203
|
@positional_parameters = nil
|
175
204
|
@named_parameters = nil
|
205
|
+
@scan_consistency = nil
|
206
|
+
@mutation_state = nil
|
207
|
+
yield self if block_given?
|
176
208
|
end
|
177
209
|
|
178
210
|
# Allows providing custom JSON key/value pairs for advanced usage
|
179
211
|
#
|
180
212
|
# @param [String] key the parameter name (key of the JSON property)
|
181
213
|
# @param [Object] value the parameter value (value of the JSON property)
|
182
|
-
def raw(key, value)
|
214
|
+
def raw(key, value)
|
215
|
+
@raw_parameters[key] = JSON.generate(value)
|
216
|
+
end
|
183
217
|
|
184
218
|
# Customizes the consistency guarantees for this query
|
185
219
|
#
|
186
|
-
#
|
220
|
+
# @note overrides consistency level set by {#consistent_with}
|
187
221
|
#
|
188
|
-
#
|
222
|
+
# [+:not_bounded+] The indexer will return whatever state it has to the query engine at the time of query. This is the default (for single-statement requests).
|
189
223
|
#
|
190
|
-
#
|
224
|
+
# [+:request_plus+] The indexer will wait until all mutations have been processed at the time of request before returning to the query engine.
|
225
|
+
#
|
226
|
+
# @param [:not_bounded, :request_plus] level the index scan consistency to be used for this query
|
191
227
|
def scan_consistency=(level)
|
228
|
+
@mutation_state = nil if @mutation_state
|
192
229
|
@scan_consistency = level
|
193
230
|
end
|
194
231
|
|
195
232
|
# Sets the mutation tokens this query should be consistent with
|
196
233
|
#
|
234
|
+
# @note overrides consistency level set by {#scan_consistency=}
|
197
235
|
#
|
198
|
-
# @param [MutationState] the mutation state containing the mutation tokens
|
236
|
+
# @param [MutationState] mutation_state the mutation state containing the mutation tokens
|
199
237
|
def consistent_with(mutation_state)
|
238
|
+
@scan_consistency = nil if @scan_consistency
|
200
239
|
@mutation_state = mutation_state
|
201
240
|
end
|
202
241
|
|
@@ -217,6 +256,105 @@ module Couchbase
|
|
217
256
|
end
|
218
257
|
end
|
219
258
|
|
259
|
+
class QueryResult
|
260
|
+
# @return [QueryMetaData] returns object representing additional metadata associated with this query
|
261
|
+
attr_accessor :meta_data
|
262
|
+
|
263
|
+
attr_accessor :transcoder
|
264
|
+
|
265
|
+
# Returns all rows converted using a transcoder
|
266
|
+
#
|
267
|
+
# @return [Array]
|
268
|
+
def rows(transcoder = self.transcoder)
|
269
|
+
@rows.lazy.map do |row|
|
270
|
+
if transcoder == :json
|
271
|
+
JSON.parse(row)
|
272
|
+
else
|
273
|
+
transcoder.call(row)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
# @yieldparam [QueryResult] self
|
279
|
+
def initialize
|
280
|
+
yield self if block_given?
|
281
|
+
@transcoder = :json
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
class QueryMetaData
|
286
|
+
# @return [String] returns the request identifier string of the query request
|
287
|
+
attr_accessor :request_id
|
288
|
+
|
289
|
+
# @return [String] returns the client context identifier string set of the query request
|
290
|
+
attr_accessor :client_context_id
|
291
|
+
|
292
|
+
# @return [Symbol] returns raw query execution status as returned by the query engine
|
293
|
+
attr_accessor :status
|
294
|
+
|
295
|
+
# @return [Hash] returns the signature as returned by the query engine which is then decoded as JSON object
|
296
|
+
attr_accessor :signature
|
297
|
+
|
298
|
+
# @return [Hash] returns the profiling information returned by the query engine which is then decoded as JSON object
|
299
|
+
attr_accessor :profile
|
300
|
+
|
301
|
+
# @return [QueryMetrics] metrics as returned by the query engine, if enabled
|
302
|
+
attr_accessor :metrics
|
303
|
+
|
304
|
+
# @return [List<QueryWarning>] list of warnings returned by the query engine
|
305
|
+
attr_accessor :warnings
|
306
|
+
|
307
|
+
# @yieldparam [QueryMetaData] self
|
308
|
+
def initialize
|
309
|
+
yield self if block_given?
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
class QueryMetrics
|
314
|
+
# @return [Integer] The total time taken for the request, that is the time from when the request was received until the results were returned
|
315
|
+
attr_accessor :elapsed_time
|
316
|
+
|
317
|
+
# @return [Integer] The time taken for the execution of the request, that is the time from when query execution started until the results were returned
|
318
|
+
attr_accessor :execution_time
|
319
|
+
|
320
|
+
# @return [Integer] the total number of results selected by the engine before restriction through LIMIT clause.
|
321
|
+
attr_accessor :sort_count
|
322
|
+
|
323
|
+
# @return [Integer] The total number of objects in the results.
|
324
|
+
attr_accessor :result_count
|
325
|
+
|
326
|
+
# @return [Integer] The total number of bytes in the results.
|
327
|
+
attr_accessor :result_size
|
328
|
+
|
329
|
+
# @return [Integer] The number of mutations that were made during the request.
|
330
|
+
attr_accessor :mutation_count
|
331
|
+
|
332
|
+
# @return [Integer] The number of errors that occurred during the request.
|
333
|
+
attr_accessor :error_count
|
334
|
+
|
335
|
+
# @return [Integer] The number of warnings that occurred during the request.
|
336
|
+
attr_accessor :warning_count
|
337
|
+
|
338
|
+
# @yieldparam [QueryMetrics] self
|
339
|
+
def initialize
|
340
|
+
yield self if block_given?
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
# Represents a single warning returned from the query engine.
|
345
|
+
class QueryWarning
|
346
|
+
# @return [Integer]
|
347
|
+
attr_accessor :code
|
348
|
+
|
349
|
+
# @return [String]
|
350
|
+
attr_accessor :message
|
351
|
+
|
352
|
+
def initialize(code, message)
|
353
|
+
@code = code
|
354
|
+
@message = message
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
220
358
|
class AnalyticsOptions
|
221
359
|
def initialize
|
222
360
|
yield self if block_given?
|
@@ -253,4 +391,4 @@ module Couchbase
|
|
253
391
|
@backend.open(hostname, username, password)
|
254
392
|
end
|
255
393
|
end
|
256
|
-
end
|
394
|
+
end
|