couchbase 3.5.0-x86_64-linux-musl

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.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +339 -0
  6. data/lib/couchbase/3.1/libcouchbase.so +0 -0
  7. data/lib/couchbase/3.2/libcouchbase.so +0 -0
  8. data/lib/couchbase/3.3/libcouchbase.so +0 -0
  9. data/lib/couchbase/analytics_options.rb +107 -0
  10. data/lib/couchbase/authenticator.rb +64 -0
  11. data/lib/couchbase/binary_collection.rb +128 -0
  12. data/lib/couchbase/binary_collection_options.rb +24 -0
  13. data/lib/couchbase/bucket.rb +144 -0
  14. data/lib/couchbase/cluster.rb +460 -0
  15. data/lib/couchbase/cluster_registry.rb +49 -0
  16. data/lib/couchbase/collection.rb +705 -0
  17. data/lib/couchbase/collection_options.rb +399 -0
  18. data/lib/couchbase/config_profiles.rb +55 -0
  19. data/lib/couchbase/configuration.rb +56 -0
  20. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  21. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  22. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  23. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  24. data/lib/couchbase/datastructures.rb +24 -0
  25. data/lib/couchbase/diagnostics.rb +181 -0
  26. data/lib/couchbase/errors.rb +376 -0
  27. data/lib/couchbase/json_transcoder.rb +39 -0
  28. data/lib/couchbase/key_value_scan.rb +117 -0
  29. data/lib/couchbase/libcouchbase.rb +6 -0
  30. data/lib/couchbase/logger.rb +85 -0
  31. data/lib/couchbase/management/analytics_index_manager.rb +1127 -0
  32. data/lib/couchbase/management/bucket_manager.rb +443 -0
  33. data/lib/couchbase/management/collection_manager.rb +470 -0
  34. data/lib/couchbase/management/collection_query_index_manager.rb +222 -0
  35. data/lib/couchbase/management/query_index_manager.rb +617 -0
  36. data/lib/couchbase/management/scope_search_index_manager.rb +198 -0
  37. data/lib/couchbase/management/search_index_manager.rb +424 -0
  38. data/lib/couchbase/management/user_manager.rb +468 -0
  39. data/lib/couchbase/management/view_index_manager.rb +237 -0
  40. data/lib/couchbase/management.rb +29 -0
  41. data/lib/couchbase/mutation_state.rb +63 -0
  42. data/lib/couchbase/options.rb +2837 -0
  43. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  44. data/lib/couchbase/protostellar/bucket.rb +51 -0
  45. data/lib/couchbase/protostellar/client.rb +99 -0
  46. data/lib/couchbase/protostellar/cluster.rb +163 -0
  47. data/lib/couchbase/protostellar/collection.rb +152 -0
  48. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  49. data/lib/couchbase/protostellar/error_handling.rb +203 -0
  50. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
  51. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
  52. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
  53. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
  54. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
  55. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
  56. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
  57. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
  58. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
  59. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
  60. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
  61. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
  62. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
  63. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
  64. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
  65. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
  66. data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
  67. data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
  68. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
  69. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
  70. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
  71. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
  72. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
  74. data/lib/couchbase/protostellar/generated.rb +9 -0
  75. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  76. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  77. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  78. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  79. data/lib/couchbase/protostellar/management.rb +24 -0
  80. data/lib/couchbase/protostellar/request.rb +78 -0
  81. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  82. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  83. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
  84. data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
  85. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  86. data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
  87. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  88. data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
  89. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  90. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  91. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  92. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  93. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  94. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  95. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  96. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  97. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  98. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  99. data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
  100. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  101. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  102. data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
  103. data/lib/couchbase/protostellar/retry.rb +28 -0
  104. data/lib/couchbase/protostellar/scope.rb +57 -0
  105. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  106. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  107. data/lib/couchbase/protostellar.rb +29 -0
  108. data/lib/couchbase/query_options.rb +120 -0
  109. data/lib/couchbase/railtie.rb +45 -0
  110. data/lib/couchbase/raw_binary_transcoder.rb +37 -0
  111. data/lib/couchbase/raw_json_transcoder.rb +38 -0
  112. data/lib/couchbase/raw_string_transcoder.rb +40 -0
  113. data/lib/couchbase/scope.rb +256 -0
  114. data/lib/couchbase/search_options.rb +1622 -0
  115. data/lib/couchbase/subdoc.rb +290 -0
  116. data/lib/couchbase/transcoder_flags.rb +62 -0
  117. data/lib/couchbase/utils/generic_logger_adapter.rb +38 -0
  118. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  119. data/lib/couchbase/utils/time.rb +69 -0
  120. data/lib/couchbase/utils.rb +21 -0
  121. data/lib/couchbase/version.rb +23 -0
  122. data/lib/couchbase/view_options.rb +65 -0
  123. data/lib/couchbase.rb +28 -0
  124. data/lib/rails/generators/couchbase/config/config_generator.rb +27 -0
  125. metadata +190 -0
@@ -0,0 +1,49 @@
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
+ # frozen_string_literal: true
16
+
17
+ module Couchbase
18
+ module Protostellar
19
+ module Retry
20
+ module Strategies
21
+ class BestEffort
22
+ attr_reader :backoff_calculator
23
+
24
+ def initialize(backoff_calculator = nil)
25
+ # The default backoff calculator starts with a 1 millisecond backoff and doubles it after each retry
26
+ # attempt, up to a maximum of 500 milliseconds
27
+ @backoff_calculator =
28
+ if backoff_calculator.nil?
29
+ lambda { |retry_attempt_count| [2**retry_attempt_count, 500].min }
30
+ else
31
+ backoff_calculator
32
+ end
33
+ end
34
+
35
+ def retry_after(request, reason)
36
+ if request.idempotent || reason.allows_non_idempotent_retry
37
+ backoff = @backoff_calculator.call(request.retry_attempts)
38
+ Retry::Action.with_duration(backoff)
39
+ else
40
+ Retry::Action.no_retry
41
+ end
42
+ end
43
+
44
+ DEFAULT = BestEffort.new.freeze
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
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
+ # frozen_string_literal: true
16
+
17
+ require_relative "strategies/best_effort"
18
+
19
+ module Couchbase
20
+ module Protostellar
21
+ module Retry
22
+ module Strategies
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
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
+ # frozen_string_literal: true
16
+
17
+ require_relative "retry/strategies"
18
+ require_relative "retry/orchestrator"
19
+ require_relative "retry/reason"
20
+ require_relative "retry/action"
21
+
22
+ module Couchbase
23
+ module Protostellar
24
+ # @api private
25
+ module Retry
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,57 @@
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
+ # frozen_string_literal: true
16
+
17
+ require "couchbase/errors"
18
+ require "couchbase/options"
19
+
20
+ require_relative "request_generator/query"
21
+ require_relative "response_converter/query"
22
+ require_relative "collection"
23
+
24
+ module Couchbase
25
+ module Protostellar
26
+ class Scope
27
+ attr_reader :bucket_name
28
+ attr_reader :name
29
+
30
+ def initialize(client, bucket_name, name)
31
+ @client = client
32
+ @bucket_name = bucket_name
33
+ @name = name
34
+
35
+ @query_request_generator = RequestGenerator::Query.new(bucket_name: @bucket_name, scope_name: @name)
36
+ end
37
+
38
+ def collection(name)
39
+ Collection.new(@client, @bucket_name, @name, name)
40
+ end
41
+
42
+ def query(statement, options = Couchbase::Options::Query::DEFAULT)
43
+ req = @query_request_generator.query_request(statement, options)
44
+ resps = @client.send_request(req)
45
+ ResponseConverter::Query.to_query_result(resps)
46
+ end
47
+
48
+ def search_query(...)
49
+ raise Error::FeatureNotAvailable, "scope search not supported in #{Protostellar::NAME} mode"
50
+ end
51
+
52
+ def search(...)
53
+ raise Error::FeatureNotAvailable, "scope search not supported in #{Protostellar::NAME} mode"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,30 @@
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
+ # frozen_string_literal: true
16
+
17
+ module Couchbase
18
+ module Protostellar
19
+ # @api private
20
+ module TimeoutDefaults
21
+ KEY_VALUE = 2_500
22
+ KEY_VALUE_DURABLE = 10_000
23
+ VIEW = 75_000
24
+ QUERY = 75_000
25
+ ANALYTICS = 75_000
26
+ SEARCH = 75_000
27
+ MANAGEMENT = 75_000
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,83 @@
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
+ # frozen_string_literal: true
16
+
17
+ require_relative "timeout_defaults"
18
+
19
+ module Couchbase
20
+ module Protostellar
21
+ # @api private
22
+ class Timeouts
23
+ attr_reader :key_value_timeout
24
+ attr_reader :view_timeout
25
+ attr_reader :query_timeout
26
+ attr_reader :analytics_timeout
27
+ attr_reader :search_timeout
28
+ attr_reader :management_timeout
29
+
30
+ def initialize(
31
+ key_value_timeout: nil,
32
+ key_value_durable_timeout: nil,
33
+ view_timeout: nil,
34
+ query_timeout: nil,
35
+ analytics_timeout: nil,
36
+ search_timeout: nil,
37
+ management_timeout: nil
38
+ )
39
+ @key_value_durable_timeout = key_value_durable_timeout || TimeoutDefaults::KEY_VALUE_DURABLE
40
+ @key_value_timeout = key_value_timeout || TimeoutDefaults::KEY_VALUE
41
+ @view_timeout = view_timeout || TimeoutDefaults::VIEW
42
+ @query_timeout = query_timeout || TimeoutDefaults::QUERY
43
+ @analytics_timeout = analytics_timeout || TimeoutDefaults::ANALYTICS
44
+ @search_timeout = search_timeout || TimeoutDefaults::SEARCH
45
+ @management_timeout = management_timeout || TimeoutDefaults::MANAGEMENT
46
+ end
47
+
48
+ def timeout_for_request(request)
49
+ case request.service
50
+ when :analytics
51
+ @analytics_timeout
52
+ when :kv
53
+ if request.proto_request.respond_to?(:durability_level) && request.proto_request.has_durability_level?
54
+ @key_value_durable_timeout
55
+ else
56
+ @key_value_timeout
57
+ end
58
+ when :query
59
+ @query_timeout
60
+ when :search
61
+ @search_timeout
62
+ when :view
63
+ @view_timeout
64
+ when :bucket_admin, :collection_admin, :query_admin, :search_admin
65
+ @management_timeout
66
+ else
67
+ raise Couchbase::Error::CouchbaseError, "Service #{service} not recognised"
68
+ end
69
+ end
70
+
71
+ def self.from_cluster_options(options)
72
+ Timeouts.new(
73
+ key_value_timeout: options.key_value_timeout,
74
+ view_timeout: options.view_timeout,
75
+ query_timeout: options.query_timeout,
76
+ analytics_timeout: options.analytics_timeout,
77
+ search_timeout: options.search_timeout,
78
+ management_timeout: options.management_timeout
79
+ )
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,29 @@
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
+ # frozen_string_literal: true
16
+
17
+ require_relative "protostellar/cluster"
18
+
19
+ module Couchbase
20
+ # @api private
21
+ module Protostellar
22
+ NAME = "couchbase2"
23
+ SCHEMES = %w[couchbase2 protostellar].freeze
24
+
25
+ SCHEMES.each do |s|
26
+ Couchbase::ClusterRegistry.instance.register_connection_handler(/^#{s}:\/\/.*$/i, Protostellar::Cluster)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,120 @@
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 Cluster
19
+ class QueryResult
20
+ # @return [QueryMetaData] returns object representing additional metadata associated with this query
21
+ attr_accessor :meta_data
22
+
23
+ attr_accessor :transcoder
24
+
25
+ # Returns all rows converted using a transcoder
26
+ #
27
+ # @return [Array]
28
+ def rows(transcoder = self.transcoder)
29
+ @rows.lazy.map do |row|
30
+ if transcoder == :json
31
+ JSON.parse(row)
32
+ else
33
+ transcoder.call(row)
34
+ end
35
+ end
36
+ end
37
+
38
+ # @yieldparam [QueryResult] self
39
+ def initialize
40
+ yield self if block_given?
41
+ @transcoder = :json
42
+ end
43
+ end
44
+
45
+ class QueryMetaData
46
+ # @return [String] returns the request identifier string of the query request
47
+ attr_accessor :request_id
48
+
49
+ # @return [String] returns the client context identifier string set of the query request
50
+ attr_accessor :client_context_id
51
+
52
+ # @return [Symbol] returns raw query execution status as returned by the query engine
53
+ attr_accessor :status
54
+
55
+ # @return [Hash] returns the signature as returned by the query engine which is then decoded as JSON object
56
+ attr_accessor :signature
57
+
58
+ # @return [Hash] returns the profiling information returned by the query engine which is then decoded as JSON object
59
+ attr_accessor :profile
60
+
61
+ # @return [QueryMetrics] metrics as returned by the query engine, if enabled
62
+ attr_accessor :metrics
63
+
64
+ # @return [Array<QueryWarning>] list of warnings returned by the query engine
65
+ attr_accessor :warnings
66
+
67
+ # @yieldparam [QueryMetaData] self
68
+ def initialize
69
+ yield self if block_given?
70
+ end
71
+ end
72
+
73
+ class QueryMetrics
74
+ # @return [Integer] The total time taken for the request (in nanoseconds), that is the time from when the request
75
+ # was received until the results were returned.
76
+ attr_accessor :elapsed_time
77
+
78
+ # @return [Integer] The time taken for the execution of the request (in nanoseconds), that is the time from when
79
+ # query execution started until the results were returned
80
+ attr_accessor :execution_time
81
+
82
+ # @return [Integer] the total number of results selected by the engine before restriction through LIMIT clause.
83
+ attr_accessor :sort_count
84
+
85
+ # @return [Integer] The total number of objects in the results.
86
+ attr_accessor :result_count
87
+
88
+ # @return [Integer] The total number of bytes in the results.
89
+ attr_accessor :result_size
90
+
91
+ # @return [Integer] The number of mutations that were made during the request.
92
+ attr_accessor :mutation_count
93
+
94
+ # @return [Integer] The number of errors that occurred during the request.
95
+ attr_accessor :error_count
96
+
97
+ # @return [Integer] The number of warnings that occurred during the request.
98
+ attr_accessor :warning_count
99
+
100
+ # @yieldparam [QueryMetrics] self
101
+ def initialize
102
+ yield self if block_given?
103
+ end
104
+ end
105
+
106
+ # Represents a single warning returned from the query engine.
107
+ class QueryWarning
108
+ # @return [Integer]
109
+ attr_accessor :code
110
+
111
+ # @return [String]
112
+ attr_accessor :message
113
+
114
+ def initialize(code, message)
115
+ @code = code
116
+ @message = message
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,45 @@
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 "rails"
16
+
17
+ require "couchbase/configuration"
18
+
19
+ module Rails
20
+ module Couchbase
21
+ class Railtie < ::Rails::Railtie
22
+ def self.rescue_responses
23
+ {
24
+ "Couchbase::Error::DocumentNotFound" => :not_found,
25
+ }
26
+ end
27
+
28
+ config.action_dispatch.rescue_responses&.merge!(rescue_responses)
29
+
30
+ config.couchbase = ::Couchbase::Configuration.new
31
+
32
+ initializer "couchbase.load-config" do
33
+ config_path = Rails.root.join("config", "couchbase.yml")
34
+ if config_path.file?
35
+ begin
36
+ config.couchbase.load!(config_path)
37
+ rescue ::Couchbase::Error::CouchbaseError => e
38
+ puts "There is a configuration error with the current couchbase.yml"
39
+ puts e.message
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,37 @@
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
+ require "couchbase/transcoder_flags"
16
+
17
+ module Couchbase
18
+ class RawBinaryTranscoder
19
+ # @param [String] document
20
+ # @return [Array<String, Integer>] pair of encoded document and flags
21
+ def encode(document)
22
+ raise Error::EncodingFailure, "Only binary data supported by RawBinaryTranscoder" unless document.is_a?(String)
23
+
24
+ [document, TranscoderFlags.new(format: :binary).encode]
25
+ end
26
+
27
+ # @param [String] blob string of bytes, containing encoded representation of the document
28
+ # @param [Integer] flags bit field, describing how the data encoded
29
+ # @return [String] decoded document
30
+ def decode(blob, flags)
31
+ format = TranscoderFlags.decode(flags).format
32
+ raise Error::DecodingFailure, "Unable to decode #{format} with the RawBinaryTranscoder" unless format == :binary || format.nil?
33
+
34
+ blob
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,38 @@
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
+ require "couchbase/transcoder_flags"
16
+ require "couchbase/errors"
17
+
18
+ module Couchbase
19
+ class RawJsonTranscoder
20
+ # @param [String] document
21
+ # @return [Array<String, Integer>] pair of encoded document and flags
22
+ def encode(document)
23
+ raise Error::EncodingFailure, "Only String and binary data supported by RawJsonTranscoder" unless document.is_a?(String)
24
+
25
+ [document, TranscoderFlags.new(format: :json).encode]
26
+ end
27
+
28
+ # @param [String] blob string of bytes, containing encoded representation of the document
29
+ # @param [Integer] flags bit field, describing how the data encoded
30
+ # @return [String] decoded document
31
+ def decode(blob, flags)
32
+ format = TranscoderFlags.decode(flags).format
33
+ raise Error::DecodingFailure, "Unable to decode #{format} with the RawJsonTranscoder" unless format == :json || format.nil?
34
+
35
+ blob
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
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
+ require "couchbase/transcoder_flags"
16
+ require "couchbase/errors"
17
+
18
+ module Couchbase
19
+ class RawStringTranscoder
20
+ # @param [String] document
21
+ # @return [Array<String, Integer>] pair of encoded document and flags
22
+ def encode(document)
23
+ unless document.is_a?(String) && document.valid_encoding?
24
+ raise Error::EncodingFailure, "Only String data supported by RawStringTranscoder"
25
+ end
26
+
27
+ [document, TranscoderFlags.new(format: :string).encode]
28
+ end
29
+
30
+ # @param [String] blob string of bytes, containing encoded representation of the document
31
+ # @param [Integer] flags bit field, describing how the data encoded
32
+ # @return [String] decoded document
33
+ def decode(blob, flags)
34
+ format = TranscoderFlags.decode(flags).format
35
+ raise Error::DecodingFailure, "Unable to decode #{format} with the RawStringTranscoder" unless format == :string || format.nil?
36
+
37
+ blob
38
+ end
39
+ end
40
+ end