couchbase 3.5.2-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
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 +342 -0
  6. data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
  7. data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
  8. data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
  9. data/lib/couchbase/analytics_options.rb +109 -0
  10. data/lib/couchbase/authenticator.rb +66 -0
  11. data/lib/couchbase/binary_collection.rb +130 -0
  12. data/lib/couchbase/binary_collection_options.rb +26 -0
  13. data/lib/couchbase/bucket.rb +146 -0
  14. data/lib/couchbase/cluster.rb +462 -0
  15. data/lib/couchbase/cluster_registry.rb +49 -0
  16. data/lib/couchbase/collection.rb +707 -0
  17. data/lib/couchbase/collection_options.rb +401 -0
  18. data/lib/couchbase/config_profiles.rb +57 -0
  19. data/lib/couchbase/configuration.rb +58 -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 +26 -0
  25. data/lib/couchbase/diagnostics.rb +183 -0
  26. data/lib/couchbase/errors.rb +414 -0
  27. data/lib/couchbase/json_transcoder.rb +41 -0
  28. data/lib/couchbase/key_value_scan.rb +119 -0
  29. data/lib/couchbase/libcouchbase.rb +6 -0
  30. data/lib/couchbase/logger.rb +87 -0
  31. data/lib/couchbase/management/analytics_index_manager.rb +1129 -0
  32. data/lib/couchbase/management/bucket_manager.rb +445 -0
  33. data/lib/couchbase/management/collection_manager.rb +472 -0
  34. data/lib/couchbase/management/collection_query_index_manager.rb +224 -0
  35. data/lib/couchbase/management/query_index_manager.rb +619 -0
  36. data/lib/couchbase/management/scope_search_index_manager.rb +200 -0
  37. data/lib/couchbase/management/search_index_manager.rb +426 -0
  38. data/lib/couchbase/management/user_manager.rb +470 -0
  39. data/lib/couchbase/management/view_index_manager.rb +239 -0
  40. data/lib/couchbase/management.rb +31 -0
  41. data/lib/couchbase/mutation_state.rb +65 -0
  42. data/lib/couchbase/options.rb +2846 -0
  43. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  44. data/lib/couchbase/protostellar/bucket.rb +55 -0
  45. data/lib/couchbase/protostellar/client.rb +99 -0
  46. data/lib/couchbase/protostellar/cluster.rb +171 -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 +122 -0
  109. data/lib/couchbase/railtie.rb +47 -0
  110. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  111. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  112. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  113. data/lib/couchbase/scope.rb +258 -0
  114. data/lib/couchbase/search_options.rb +1650 -0
  115. data/lib/couchbase/subdoc.rb +293 -0
  116. data/lib/couchbase/transcoder_flags.rb +64 -0
  117. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  118. data/lib/couchbase/utils/stdlib_logger_adapter.rb +67 -0
  119. data/lib/couchbase/utils/time.rb +71 -0
  120. data/lib/couchbase/utils.rb +23 -0
  121. data/lib/couchbase/version.rb +25 -0
  122. data/lib/couchbase/view_options.rb +67 -0
  123. data/lib/couchbase.rb +30 -0
  124. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -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,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "json"
18
+
19
+ module Couchbase
20
+ class Cluster
21
+ class QueryResult
22
+ # @return [QueryMetaData] returns object representing additional metadata associated with this query
23
+ attr_accessor :meta_data
24
+
25
+ attr_accessor :transcoder
26
+
27
+ # Returns all rows converted using a transcoder
28
+ #
29
+ # @return [Array]
30
+ def rows(transcoder = self.transcoder)
31
+ @rows.lazy.map do |row|
32
+ if transcoder == :json
33
+ JSON.parse(row)
34
+ else
35
+ transcoder.call(row)
36
+ end
37
+ end
38
+ end
39
+
40
+ # @yieldparam [QueryResult] self
41
+ def initialize
42
+ yield self if block_given?
43
+ @transcoder = :json
44
+ end
45
+ end
46
+
47
+ class QueryMetaData
48
+ # @return [String] returns the request identifier string of the query request
49
+ attr_accessor :request_id
50
+
51
+ # @return [String] returns the client context identifier string set of the query request
52
+ attr_accessor :client_context_id
53
+
54
+ # @return [Symbol] returns raw query execution status as returned by the query engine
55
+ attr_accessor :status
56
+
57
+ # @return [Hash] returns the signature as returned by the query engine which is then decoded as JSON object
58
+ attr_accessor :signature
59
+
60
+ # @return [Hash] returns the profiling information returned by the query engine which is then decoded as JSON object
61
+ attr_accessor :profile
62
+
63
+ # @return [QueryMetrics] metrics as returned by the query engine, if enabled
64
+ attr_accessor :metrics
65
+
66
+ # @return [Array<QueryWarning>] list of warnings returned by the query engine
67
+ attr_accessor :warnings
68
+
69
+ # @yieldparam [QueryMetaData] self
70
+ def initialize
71
+ yield self if block_given?
72
+ end
73
+ end
74
+
75
+ class QueryMetrics
76
+ # @return [Integer] The total time taken for the request (in nanoseconds), that is the time from when the request
77
+ # was received until the results were returned.
78
+ attr_accessor :elapsed_time
79
+
80
+ # @return [Integer] The time taken for the execution of the request (in nanoseconds), that is the time from when
81
+ # query execution started until the results were returned
82
+ attr_accessor :execution_time
83
+
84
+ # @return [Integer] the total number of results selected by the engine before restriction through LIMIT clause.
85
+ attr_accessor :sort_count
86
+
87
+ # @return [Integer] The total number of objects in the results.
88
+ attr_accessor :result_count
89
+
90
+ # @return [Integer] The total number of bytes in the results.
91
+ attr_accessor :result_size
92
+
93
+ # @return [Integer] The number of mutations that were made during the request.
94
+ attr_accessor :mutation_count
95
+
96
+ # @return [Integer] The number of errors that occurred during the request.
97
+ attr_accessor :error_count
98
+
99
+ # @return [Integer] The number of warnings that occurred during the request.
100
+ attr_accessor :warning_count
101
+
102
+ # @yieldparam [QueryMetrics] self
103
+ def initialize
104
+ yield self if block_given?
105
+ end
106
+ end
107
+
108
+ # Represents a single warning returned from the query engine.
109
+ class QueryWarning
110
+ # @return [Integer]
111
+ attr_accessor :code
112
+
113
+ # @return [String]
114
+ attr_accessor :message
115
+
116
+ def initialize(code, message)
117
+ @code = code
118
+ @message = message
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "rails"
18
+
19
+ require "couchbase/configuration"
20
+
21
+ module Rails
22
+ module Couchbase
23
+ class Railtie < ::Rails::Railtie
24
+ def self.rescue_responses
25
+ {
26
+ "Couchbase::Error::DocumentNotFound" => :not_found,
27
+ }
28
+ end
29
+
30
+ config.action_dispatch.rescue_responses&.merge!(rescue_responses)
31
+
32
+ config.couchbase = ::Couchbase::Configuration.new
33
+
34
+ initializer "couchbase.load-config" do
35
+ config_path = Rails.root.join("config", "couchbase.yml")
36
+ if config_path.file?
37
+ begin
38
+ config.couchbase.load!(config_path)
39
+ rescue ::Couchbase::Error::CouchbaseError => e
40
+ puts "There is a configuration error with the current couchbase.yml"
41
+ puts e.message
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023. Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/transcoder_flags"
18
+
19
+ module Couchbase
20
+ class RawBinaryTranscoder
21
+ # @param [String] document
22
+ # @return [Array<String, Integer>] pair of encoded document and flags
23
+ def encode(document)
24
+ raise Error::EncodingFailure, "Only binary data supported by RawBinaryTranscoder" unless document.is_a?(String)
25
+
26
+ [document, TranscoderFlags.new(format: :binary).encode]
27
+ end
28
+
29
+ # @param [String] blob string of bytes, containing encoded representation of the document
30
+ # @param [Integer] flags bit field, describing how the data encoded
31
+ # @return [String] decoded document
32
+ def decode(blob, flags)
33
+ format = TranscoderFlags.decode(flags).format
34
+ raise Error::DecodingFailure, "Unable to decode #{format} with the RawBinaryTranscoder" unless format == :binary || format.nil?
35
+
36
+ blob
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023. Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/transcoder_flags"
18
+ require "couchbase/errors"
19
+
20
+ module Couchbase
21
+ class RawJsonTranscoder
22
+ # @param [String] document
23
+ # @return [Array<String, Integer>] pair of encoded document and flags
24
+ def encode(document)
25
+ raise Error::EncodingFailure, "Only String and binary data supported by RawJsonTranscoder" unless document.is_a?(String)
26
+
27
+ [document, TranscoderFlags.new(format: :json).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 RawJsonTranscoder" unless format == :json || format.nil?
36
+
37
+ blob
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2023. Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/transcoder_flags"
18
+ require "couchbase/errors"
19
+
20
+ module Couchbase
21
+ class RawStringTranscoder
22
+ # @param [String] document
23
+ # @return [Array<String, Integer>] pair of encoded document and flags
24
+ def encode(document)
25
+ unless document.is_a?(String) && document.valid_encoding?
26
+ raise Error::EncodingFailure, "Only String data supported by RawStringTranscoder"
27
+ end
28
+
29
+ [document, TranscoderFlags.new(format: :string).encode]
30
+ end
31
+
32
+ # @param [String] blob string of bytes, containing encoded representation of the document
33
+ # @param [Integer] flags bit field, describing how the data encoded
34
+ # @return [String] decoded document
35
+ def decode(blob, flags)
36
+ format = TranscoderFlags.decode(flags).format
37
+ raise Error::DecodingFailure, "Unable to decode #{format} with the RawStringTranscoder" unless format == :string || format.nil?
38
+
39
+ blob
40
+ end
41
+ end
42
+ end