cql-rb 2.0.0.pre0 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -2
  3. data/lib/cql.rb +8 -3
  4. data/lib/cql/client.rb +21 -356
  5. data/lib/cql/client/authenticators.rb +70 -0
  6. data/lib/cql/client/batch.rb +54 -0
  7. data/lib/cql/client/{asynchronous_client.rb → client.rb} +241 -6
  8. data/lib/cql/client/connector.rb +3 -2
  9. data/lib/cql/client/{asynchronous_prepared_statement.rb → prepared_statement.rb} +103 -0
  10. data/lib/cql/protocol.rb +1 -2
  11. data/lib/cql/protocol/cql_byte_buffer.rb +285 -0
  12. data/lib/cql/protocol/cql_protocol_handler.rb +3 -3
  13. data/lib/cql/protocol/frame_decoder.rb +3 -3
  14. data/lib/cql/protocol/frame_encoder.rb +2 -2
  15. data/lib/cql/protocol/request.rb +0 -2
  16. data/lib/cql/protocol/requests/auth_response_request.rb +2 -2
  17. data/lib/cql/protocol/requests/batch_request.rb +10 -10
  18. data/lib/cql/protocol/requests/credentials_request.rb +2 -2
  19. data/lib/cql/protocol/requests/execute_request.rb +13 -13
  20. data/lib/cql/protocol/requests/options_request.rb +2 -2
  21. data/lib/cql/protocol/requests/prepare_request.rb +2 -2
  22. data/lib/cql/protocol/requests/query_request.rb +13 -13
  23. data/lib/cql/protocol/requests/register_request.rb +2 -2
  24. data/lib/cql/protocol/requests/startup_request.rb +2 -2
  25. data/lib/cql/protocol/response.rb +2 -4
  26. data/lib/cql/protocol/responses/auth_challenge_response.rb +2 -2
  27. data/lib/cql/protocol/responses/auth_success_response.rb +2 -2
  28. data/lib/cql/protocol/responses/authenticate_response.rb +2 -2
  29. data/lib/cql/protocol/responses/detailed_error_response.rb +15 -15
  30. data/lib/cql/protocol/responses/error_response.rb +4 -4
  31. data/lib/cql/protocol/responses/event_response.rb +3 -3
  32. data/lib/cql/protocol/responses/prepared_result_response.rb +4 -4
  33. data/lib/cql/protocol/responses/raw_rows_result_response.rb +1 -1
  34. data/lib/cql/protocol/responses/ready_response.rb +1 -1
  35. data/lib/cql/protocol/responses/result_response.rb +3 -3
  36. data/lib/cql/protocol/responses/rows_result_response.rb +22 -22
  37. data/lib/cql/protocol/responses/schema_change_event_response.rb +2 -2
  38. data/lib/cql/protocol/responses/schema_change_result_response.rb +2 -2
  39. data/lib/cql/protocol/responses/set_keyspace_result_response.rb +2 -2
  40. data/lib/cql/protocol/responses/status_change_event_response.rb +2 -2
  41. data/lib/cql/protocol/responses/supported_response.rb +2 -2
  42. data/lib/cql/protocol/responses/void_result_response.rb +1 -1
  43. data/lib/cql/protocol/type_converter.rb +78 -81
  44. data/lib/cql/time_uuid.rb +6 -0
  45. data/lib/cql/uuid.rb +2 -1
  46. data/lib/cql/version.rb +1 -1
  47. data/spec/cql/client/batch_spec.rb +8 -8
  48. data/spec/cql/client/{asynchronous_client_spec.rb → client_spec.rb} +162 -0
  49. data/spec/cql/client/connector_spec.rb +13 -3
  50. data/spec/cql/client/{asynchronous_prepared_statement_spec.rb → prepared_statement_spec.rb} +148 -1
  51. data/spec/cql/client/request_runner_spec.rb +2 -2
  52. data/spec/cql/protocol/cql_byte_buffer_spec.rb +895 -0
  53. data/spec/cql/protocol/cql_protocol_handler_spec.rb +1 -1
  54. data/spec/cql/protocol/frame_decoder_spec.rb +14 -14
  55. data/spec/cql/protocol/frame_encoder_spec.rb +7 -7
  56. data/spec/cql/protocol/requests/auth_response_request_spec.rb +4 -4
  57. data/spec/cql/protocol/requests/batch_request_spec.rb +21 -21
  58. data/spec/cql/protocol/requests/credentials_request_spec.rb +2 -2
  59. data/spec/cql/protocol/requests/execute_request_spec.rb +13 -13
  60. data/spec/cql/protocol/requests/options_request_spec.rb +1 -1
  61. data/spec/cql/protocol/requests/prepare_request_spec.rb +2 -2
  62. data/spec/cql/protocol/requests/query_request_spec.rb +13 -13
  63. data/spec/cql/protocol/requests/register_request_spec.rb +2 -2
  64. data/spec/cql/protocol/requests/startup_request_spec.rb +4 -4
  65. data/spec/cql/protocol/responses/auth_challenge_response_spec.rb +5 -5
  66. data/spec/cql/protocol/responses/auth_success_response_spec.rb +5 -5
  67. data/spec/cql/protocol/responses/authenticate_response_spec.rb +3 -3
  68. data/spec/cql/protocol/responses/detailed_error_response_spec.rb +15 -15
  69. data/spec/cql/protocol/responses/error_response_spec.rb +5 -5
  70. data/spec/cql/protocol/responses/event_response_spec.rb +8 -8
  71. data/spec/cql/protocol/responses/prepared_result_response_spec.rb +7 -7
  72. data/spec/cql/protocol/responses/raw_rows_result_response_spec.rb +1 -1
  73. data/spec/cql/protocol/responses/ready_response_spec.rb +2 -2
  74. data/spec/cql/protocol/responses/result_response_spec.rb +16 -16
  75. data/spec/cql/protocol/responses/rows_result_response_spec.rb +21 -21
  76. data/spec/cql/protocol/responses/schema_change_event_response_spec.rb +3 -3
  77. data/spec/cql/protocol/responses/schema_change_result_response_spec.rb +3 -3
  78. data/spec/cql/protocol/responses/set_keyspace_result_response_spec.rb +2 -2
  79. data/spec/cql/protocol/responses/status_change_event_response_spec.rb +3 -3
  80. data/spec/cql/protocol/responses/supported_response_spec.rb +3 -3
  81. data/spec/cql/protocol/responses/topology_change_event_response_spec.rb +3 -3
  82. data/spec/cql/protocol/responses/void_result_response_spec.rb +2 -2
  83. data/spec/cql/protocol/type_converter_spec.rb +25 -13
  84. data/spec/cql/time_uuid_spec.rb +17 -4
  85. data/spec/cql/uuid_spec.rb +5 -1
  86. data/spec/integration/protocol_spec.rb +48 -42
  87. data/spec/spec_helper.rb +0 -1
  88. metadata +27 -39
  89. data/lib/cql/byte_buffer.rb +0 -177
  90. data/lib/cql/client/synchronous_client.rb +0 -79
  91. data/lib/cql/client/synchronous_prepared_statement.rb +0 -63
  92. data/lib/cql/future.rb +0 -515
  93. data/lib/cql/io.rb +0 -15
  94. data/lib/cql/io/connection.rb +0 -220
  95. data/lib/cql/io/io_reactor.rb +0 -349
  96. data/lib/cql/protocol/decoding.rb +0 -187
  97. data/lib/cql/protocol/encoding.rb +0 -114
  98. data/spec/cql/byte_buffer_spec.rb +0 -337
  99. data/spec/cql/client/synchronous_client_spec.rb +0 -170
  100. data/spec/cql/client/synchronous_prepared_statement_spec.rb +0 -155
  101. data/spec/cql/future_spec.rb +0 -737
  102. data/spec/cql/io/connection_spec.rb +0 -484
  103. data/spec/cql/io/io_reactor_spec.rb +0 -402
  104. data/spec/cql/protocol/decoding_spec.rb +0 -547
  105. data/spec/cql/protocol/encoding_spec.rb +0 -386
  106. data/spec/integration/io_spec.rb +0 -283
  107. data/spec/support/fake_server.rb +0 -106
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b00538d250d975f9b1ed2795bf947d9baf97c35
4
- data.tar.gz: e1b27e7d7665bb8545b14c088fb7076ab5e76b01
3
+ metadata.gz: ee42c11d2d4d39946b1df62d6d0cd9ef240edf57
4
+ data.tar.gz: c2d82f55a791696d8ea9e1d0529f0c1fbec31c02
5
5
  SHA512:
6
- metadata.gz: 9b24cfa7ecbd973138d21c64e6f64ab02673deefc8f9bab46e0cc1658d041bf15b237326aaec3cfd6f83f8152a802d4efed71cef505fc3fe6102d3d87c7fd49e
7
- data.tar.gz: b3a5f99e920989e64ebde8669c3339890ee6b8bdd0c882e65ea2354d0055bd29bd48f2089355d13c279b64379fbb258cf0987306b6e9b11c49caec51d86adc54
6
+ metadata.gz: ced007c5c12672918218c0c3e24d792f77a84d81779c972aeb10b976355f9f5d860615835c1b7878f267380a19e8960a1f2cab347c15e978a65d3a287049a4be
7
+ data.tar.gz: 896789b373ba5310738f046c823dac12f261f544116000a39594d9f4dd6a30cef37a213e7fbef3a3267565f8469c3124762c4b86475dae79677fb066d9b7d537
data/README.md CHANGED
@@ -85,6 +85,18 @@ rows = client.execute('SELECT date, description FROM events'
85
85
  rows.metadata['date'].type # => :date
86
86
  ```
87
87
 
88
+ If you're using Cassandra 2.0 or later you no longer have to build CQL strings when you want to insert a value in a query, there's a new feature that lets you use bound values with reqular statements:
89
+
90
+ ```ruby
91
+ client.execute("UPDATE users SET age = ? WHERE user_name = ?", 41, 'Sam')
92
+ ```
93
+
94
+ If you find yourself doing this often, it's better to use prepared statements. As a rule of thumb, if your application is sending a request more than once, a prepared statement is almost always the right choice.
95
+
96
+ When you use bound values with regular statements the type of the values has to be guessed. Cassandra supports multiple different numeric types, but there's no reliable way of guessing whether or not a Ruby `Fixnum` should be encoded as a `BIGINT` or `INT`, or whether a Ruby `Float` is a `DOUBLE` or `FLOAT`. When there are multiple choices the encoder will pick the larger type (e.g. `BIGINT` over `INT`). For Ruby strings it will always guess `VARCHAR`, never `BLOB`.
97
+
98
+ You can override the guessing by passing type hints as an option, see the [API docs][1] for more information.
99
+
88
100
  Each call to `#execute` selects a random connection to run the query on.
89
101
 
90
102
  ## Creating keyspaces and tables
@@ -211,7 +223,7 @@ loop do
211
223
  result_page.each do |row|
212
224
  p row
213
225
  end
214
- if result_page.last?
226
+ if result_page.last_page?
215
227
  break
216
228
  else
217
229
  result_page = result_page.next_page
@@ -224,7 +236,7 @@ end
224
236
  You can specify the default consistency to use when you create a new `Client`:
225
237
 
226
238
  ```ruby
227
- client = Cql::Client.connect(hosts: %w[localhost], consistency: :all)
239
+ client = Cql::Client.connect(hosts: %w[localhost], default_consistency: :all)
228
240
  ```
229
241
 
230
242
  The `#execute` (of `Client` and `PreparedStatement`) method also supports setting the desired consistency level on a per-request basis:
data/lib/cql.rb CHANGED
@@ -1,14 +1,19 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'ione'
4
+
5
+
3
6
  module Cql
4
7
  CqlError = Class.new(StandardError)
8
+
9
+ Promise = Ione::Promise
10
+ Future = Ione::Future
11
+ Io = Ione::Io
12
+ IoError = Ione::IoError
5
13
  end
6
14
 
7
15
  require 'cql/uuid'
8
16
  require 'cql/time_uuid'
9
- require 'cql/byte_buffer'
10
- require 'cql/future'
11
- require 'cql/io'
12
17
  require 'cql/compression'
13
18
  require 'cql/protocol'
14
19
  require 'cql/client'
data/lib/cql/client.rb CHANGED
@@ -55,6 +55,24 @@ module Cql
55
55
  module Client
56
56
  InvalidKeyspaceNameError = Class.new(ClientError)
57
57
 
58
+ # @private
59
+ module SynchronousBacktrace
60
+ def synchronous_backtrace
61
+ yield
62
+ rescue CqlError => e
63
+ new_backtrace = caller
64
+ if new_backtrace.first.include?(SYNCHRONOUS_BACKTRACE_METHOD_NAME)
65
+ new_backtrace = new_backtrace.drop(1)
66
+ end
67
+ e.set_backtrace(new_backtrace)
68
+ raise
69
+ end
70
+
71
+ private
72
+
73
+ SYNCHRONOUS_BACKTRACE_METHOD_NAME = 'synchronous_backtrace'
74
+ end
75
+
58
76
  # Create a new client and connect to Cassandra.
59
77
  #
60
78
  # By default the client will connect to localhost port 9042, which can be
@@ -117,357 +135,6 @@ module Cql
117
135
  def self.connect(options={})
118
136
  SynchronousClient.new(AsynchronousClient.new(options)).connect
119
137
  end
120
-
121
- class Client
122
- # @!method connect
123
- #
124
- # Connect to all nodes. See {Cql::Client.connect} for the full
125
- # documentation.
126
- #
127
- # This method needs to be called before any other. Calling it again will
128
- # have no effect.
129
- #
130
- # @see Cql::Client.connect
131
- # @return [Cql::Client]
132
-
133
- # @!method close
134
- #
135
- # Disconnect from all nodes.
136
- #
137
- # @return [Cql::Client]
138
-
139
- # @!method connected?
140
- #
141
- # Returns whether or not the client is connected.
142
- #
143
- # @return [true, false]
144
-
145
- # @!method keyspace
146
- #
147
- # Returns the name of the current keyspace, or `nil` if no keyspace has been
148
- # set yet.
149
- #
150
- # @return [String]
151
-
152
- # @!method use(keyspace)
153
- #
154
- # Changes keyspace by sending a `USE` statement to all connections.
155
- #
156
- # The the second parameter is meant for internal use only.
157
- #
158
- # @param [String] keyspace
159
- # @raise [Cql::NotConnectedError] raised when the client is not connected
160
- # @return [nil]
161
-
162
- # @!method execute(cql, *values, options_or_consistency={})
163
- #
164
- # Execute a CQL statement, optionally passing bound values.
165
- #
166
- # When passing bound values the request encoder will have to guess what
167
- # types to encode the values as. For most types this will be no problem,
168
- # but for integers and floating point numbers the larger size will be
169
- # chosen (e.g. `BIGINT` and `DOUBLE` and not `INT` and `FLOAT`). You can
170
- # override the guessing with the `:type_hint` option. Don't use on-the-fly
171
- # bound values when you will issue the request multiple times, prepared
172
- # statements are almost always a better choice.
173
- #
174
- # @note On-the-fly bound values are not supported in Cassandra 1.2
175
- #
176
- # @example A simple CQL query
177
- # result = client.execute("SELECT * FROM users WHERE user_name = 'sue'")
178
- # result.each do |row|
179
- # p row
180
- # end
181
- #
182
- # @example Using on-the-fly bound values
183
- # client.execute('INSERT INTO users (user_name, full_name) VALUES (?, ?)', 'sue', 'Sue Smith')
184
- #
185
- # @example Using on-the-fly bound values with type hints
186
- # client.execute('INSERT INTO users (user_name, age) VALUES (?, ?)', 'sue', 33, type_hints: [nil, :int])
187
- #
188
- # @example Specifying the consistency as a symbol
189
- # client.execute("UPDATE users SET full_name = 'Sue S. Smith' WHERE user_name = 'sue'", consistency: :one)
190
- #
191
- # @example Specifying the consistency and other options
192
- # client.execute("SELECT * FROM users", consistency: :all, timeout: 1.5)
193
- #
194
- # @example Activating tracing for a query
195
- # result = client.execute("SELECT * FROM users", tracing: true)
196
- # p result.trace_id
197
- #
198
- # @param [String] cql
199
- # @param [Array] values Values to bind to any binding markers in the
200
- # query (i.e. "?" placeholders) -- using this feature is similar to
201
- # using a prepared statement, but without the type checking. The client
202
- # needs to guess which data types to encode the values as, and will err
203
- # on the side of caution, using types like BIGINT instead of INT for
204
- # integers, and DOUBLE instead of FLOAT for floating point numbers. It
205
- # is not recommended to use this feature for anything but convenience,
206
- # and the algorithm used to guess types is to be considered experimental.
207
- # @param [Hash] options_or_consistency Either a consistency as a symbol
208
- # (e.g. `:quorum`), or a options hash (see below). Passing a symbol is
209
- # equivalent to passing the options `consistency: <symbol>`.
210
- # @option options_or_consistency [Symbol] :consistency (:quorum) The
211
- # consistency to use for this query.
212
- # @option options_or_consistency [Symbol] :serial_consistency (nil) The
213
- # consistency to use for conditional updates (`:serial` or
214
- # `:local_serial`), see the CQL documentation for the semantics of
215
- # serial consistencies and conditional updates. The default is assumed
216
- # to be `:serial` by the server if none is specified. Ignored for non-
217
- # conditional queries.
218
- # @option options_or_consistency [Integer] :timeout (nil) How long to wait
219
- # for a response. If this timeout expires a {Cql::TimeoutError} will
220
- # be raised.
221
- # @option options_or_consistency [Boolean] :trace (false) Request tracing
222
- # for this request. See {Cql::Client::QueryResult} and
223
- # {Cql::Client::VoidResult} for how to retrieve the tracing data.
224
- # @option options_or_consistency [Array] :type_hints (nil) When passing
225
- # on-the-fly bound values the request encoder will have to guess what
226
- # types to encode the values as. Using this option you can give it hints
227
- # and avoid it guessing wrong. The hints must be an array that has the
228
- # same number of arguments as the number of bound values, and each
229
- # element should be the type of the corresponding value, or nil if you
230
- # prefer the encoder to guess. The types should be provided as lower
231
- # case symbols, e.g. `:int`, `:time_uuid`, etc.
232
- # @raise [Cql::NotConnectedError] raised when the client is not connected
233
- # @raise [Cql::TimeoutError] raised when a timeout was specified and no
234
- # response was received within the timeout.
235
- # @raise [Cql::QueryError] raised when the CQL has syntax errors or for
236
- # other situations when the server complains.
237
- # @return [nil, Cql::Client::QueryResult, Cql::Client::VoidResult] Some
238
- # queries have no result and return `nil`, but `SELECT` statements
239
- # return an `Enumerable` of rows (see {Cql::Client::QueryResult}), and
240
- # `INSERT` and `UPDATE` return a similar type
241
- # (see {Cql::Client::VoidResult}).
242
-
243
- # @!method prepare(cql)
244
- #
245
- # Returns a prepared statement that can be run over and over again with
246
- # different values.
247
- #
248
- # @see Cql::Client::PreparedStatement
249
- # @param [String] cql The CQL to prepare
250
- # @raise [Cql::NotConnectedError] raised when the client is not connected
251
- # @raise [Cql::Io::IoError] raised when there is an IO error, for example
252
- # if the server suddenly closes the connection
253
- # @raise [Cql::QueryError] raised when there is an error on the server
254
- # side, for example when you specify a malformed CQL query
255
- # @return [Cql::Client::PreparedStatement] an object encapsulating the
256
- # prepared statement
257
-
258
- # @!method batch(type=:logged, options={})
259
- #
260
- # Yields a batch when called with a block. The batch is automatically
261
- # executed at the end of the block and the result is returned.
262
- #
263
- # Returns a batch when called wihtout a block. The batch will remember
264
- # the options given and merge these with any additional options given
265
- # when {Cql::Client::Batch#execute} is called.
266
- #
267
- # Please note that the batch object returned by this method _is not thread
268
- # safe_.
269
- #
270
- # The type parameter can be ommitted and the options can then be given
271
- # as first parameter.
272
- #
273
- # @example Executing queries in a batch
274
- # client.batch do |batch|
275
- # batch.add(%(INSERT INTO metrics (id, time, value) VALUES (1234, NOW(), 23423)))
276
- # batch.add(%(INSERT INTO metrics (id, time, value) VALUES (2346, NOW(), 13)))
277
- # batch.add(%(INSERT INTO metrics (id, time, value) VALUES (2342, NOW(), 2367)))
278
- # batch.add(%(INSERT INTO metrics (id, time, value) VALUES (4562, NOW(), 1231)))
279
- # end
280
- #
281
- # @example Using the returned batch object
282
- # batch = client.batch(:counter, trace: true)
283
- # batch.add('UPDATE counts SET value = value + ? WHERE id = ?', 4, 87654)
284
- # batch.add('UPDATE counts SET value = value + ? WHERE id = ?', 3, 6572)
285
- # result = batch.execute(timeout: 10)
286
- # puts result.trace_id
287
- #
288
- # @example Providing type hints for on-the-fly bound values
289
- # batch = client.batch
290
- # batch.add('UPDATE counts SET value = value + ? WHERE id = ?', 4, type_hints: [:int])
291
- # batch.execute
292
- #
293
- # @see Cql::Client::Batch
294
- # @param [Symbol] type the type of batch, must be one of `:logged`,
295
- # `:unlogged` and `:counter`. The precise meaning of these is defined
296
- # in the CQL specification.
297
- # @yieldparam [Cql::Client::Batch] batch the batch
298
- # @return [Cql::Client::VoidResult, Cql::Client::Batch] when no block is
299
- # given the batch is returned, when a block is given the result of
300
- # executing the batch is returned (see {Cql::Client::Batch#execute}).
301
- end
302
-
303
- class PreparedStatement
304
- # Metadata describing the bound values
305
- #
306
- # @return [ResultMetadata]
307
- attr_reader :metadata
308
-
309
- # Metadata about the result (i.e. rows) that is returned when executing
310
- # this prepared statement.
311
- #
312
- # @return [ResultMetadata]
313
- attr_reader :result_metadata
314
-
315
- # Execute the prepared statement with a list of values to be bound to the
316
- # statements parameters.
317
- #
318
- # The number of arguments must equal the number of bound parameters. You
319
- # can also specify options as the last argument, or a symbol as a shortcut
320
- # for just specifying the consistency.
321
- #
322
- # Because you can specify options, or not, there is an edge case where if
323
- # the last parameter of your prepared statement is a map, and you forget
324
- # to specify a value for your map, the options will end up being sent to
325
- # Cassandra. Most other cases when you specify the wrong number of
326
- # arguments should result in an `ArgumentError` or `TypeError` being
327
- # raised.
328
- #
329
- # @param args [Array] the values for the bound parameters. The last
330
- # argument can also be an options hash or a symbol (as a shortcut for
331
- # specifying the consistency), see {Cql::Client::Client#execute} for
332
- # full details.
333
- # @raise [ArgumentError] raised when number of argument does not match
334
- # the number of parameters needed to be bound to the statement.
335
- # @raise [Cql::NotConnectedError] raised when the client is not connected
336
- # @raise [Cql::Io::IoError] raised when there is an IO error, for example
337
- # if the server suddenly closes the connection
338
- # @raise [Cql::QueryError] raised when there is an error on the server side
339
- # @return [nil, Cql::Client::QueryResult, Cql::Client::VoidResult] Some
340
- # queries have no result and return `nil`, but `SELECT` statements
341
- # return an `Enumerable` of rows (see {Cql::Client::QueryResult}), and
342
- # `INSERT` and `UPDATE` return a similar type
343
- # (see {Cql::Client::VoidResult}).
344
- def execute(*args)
345
- end
346
- end
347
-
348
- class Batch
349
- # @!method add(cql_or_prepared_statement, *bound_values)
350
- #
351
- # Add a query or a prepared statement to the batch.
352
- #
353
- # @example Adding a mix of statements to a batch
354
- # batch.add(%(UPDATE people SET name = 'Miriam' WHERE id = 3435))
355
- # batch.add(%(UPDATE people SET name = ? WHERE id = ?), 'Miriam', 3435)
356
- # batch.add(prepared_statement, 'Miriam', 3435)
357
- #
358
- # @param [String, Cql::Client::PreparedStatement] cql_or_prepared_statement
359
- # a CQL string or a prepared statement object (obtained through
360
- # {Cql::Client::Client#prepare})
361
- # @param [Array] bound_values a list of bound values -- only applies when
362
- # adding prepared statements and when there are binding markers in the
363
- # given CQL. If the last argument is a hash and it has the key
364
- # `:type_hints` this will be passed as type hints to the request encoder
365
- # (if the last argument is any other hash it will be assumed to be a
366
- # bound value of type MAP). See {Cql::Client::Client#execute} for more
367
- # info on type hints.
368
- # @return [nil]
369
-
370
- # @!method execute(options={})
371
- #
372
- # Execute the batch and return the result.
373
- #
374
- # @param options [Hash] an options hash or a symbol (as a shortcut for
375
- # specifying the consistency), see {Cql::Client::Client#execute} for
376
- # full details about how this value is interpreted.
377
- # @raise [Cql::QueryError] raised when there is an error on the server side
378
- # @raise [Cql::NotPreparedError] raised in the unlikely event that a
379
- # prepared statement was not prepared on the chosen connection
380
- # @return [Cql::Client::VoidResult] a batch always returns a void result
381
- end
382
-
383
- class PreparedStatementBatch
384
- # @!method add(*bound_values)
385
- #
386
- # Add the statement to the batch with the specified bound values.
387
- #
388
- # @param [Array] bound_values the values to bind to the added statement,
389
- # see {Cql::Client::PreparedStatement#execute}.
390
- # @return [nil]
391
-
392
- # @!method execute(options={})
393
- #
394
- # Execute the batch and return the result.
395
- #
396
- # @raise [Cql::QueryError] raised when there is an error on the server side
397
- # @raise [Cql::NotPreparedError] raised in the unlikely event that a
398
- # prepared statement was not prepared on the chosen connection
399
- # @return [Cql::Client::VoidResult] a batch always returns a void result
400
- end
401
-
402
- # An auth provider is a factory for {Cql::Client::Authenticator} instances
403
- # (or objects matching that interface). Its {#create_authenticator} will be
404
- # called once for each connection that requires authentication.
405
- #
406
- # If the authentication requires keeping state, keep that in the
407
- # authenticator instances, not in the auth provider.
408
- #
409
- # @note Creating an authenticator must absolutely not block, or the whole
410
- # connection process will block.
411
- #
412
- # @note Auth providers given to {Cql::Client.connect} as the `:auth_provider`
413
- # option don't need to be subclasses of this class, but need to
414
- # implement the same methods. This class exists only for documentation
415
- # purposes.
416
- class AuthProvider
417
- # @!method create_authenticator(authentication_class, protocol_version)
418
- #
419
- # Create a new authenticator object. This method will be called once per
420
- # connection that requires authentication. The auth provider can create
421
- # different authenticators for different authentication classes, or return
422
- # nil if it does not support the authentication class.
423
- #
424
- # @note This method must absolutely not block.
425
- #
426
- # @param authentication_class [String] the authentication class used by
427
- # the server.
428
- # @return [Cql::Client::Authenticator, nil] an object with an interface
429
- # matching {Cql::Client::Authenticator} or nil if the authentication
430
- # class is not supported.
431
- end
432
-
433
- # An authenticator handles the authentication challenge/response cycles of
434
- # a single connection. It can be stateful, but it must not for any reason
435
- # block. If any of the method calls block, the whole connection process
436
- # will be blocked.
437
- #
438
- # @note Authenticators created by auth providers don't need to be subclasses
439
- # of this class, but need to implement the same methods. This class exists
440
- # only for documentation purposes.
441
- class Authenticator
442
- # @!method initial_response
443
- #
444
- # This method must return the initial authentication token to be sent to
445
- # the server.
446
- #
447
- # @note This method must absolutely not block.
448
- #
449
- # @return [String] the initial authentication token
450
-
451
- # @!method challenge_response(token)
452
- #
453
- # If the authentication requires multiple challenge/response cycles this
454
- # method will be called when a challenge is returned by the server. A
455
- # response token must be created and will be sent back to the server.
456
- #
457
- # @note This method must absolutely not block.
458
- #
459
- # @param token [String] a challenge token sent by the server
460
- # @return [String] the authentication token to send back to the server
461
-
462
- # @!method authentication_successful(token)
463
- #
464
- # Called when the authentication is successful.
465
- #
466
- # @note This method must absolutely not block.
467
- #
468
- # @param token [String] a token sent by the server
469
- # @return [nil]
470
- end
471
138
  end
472
139
  end
473
140
 
@@ -479,13 +146,11 @@ require 'cql/client/result_metadata'
479
146
  require 'cql/client/query_trace'
480
147
  require 'cql/client/execute_options_decoder'
481
148
  require 'cql/client/keyspace_changer'
482
- require 'cql/client/asynchronous_client'
483
- require 'cql/client/asynchronous_prepared_statement'
484
- require 'cql/client/synchronous_client'
485
- require 'cql/client/synchronous_prepared_statement'
149
+ require 'cql/client/client'
150
+ require 'cql/client/prepared_statement'
486
151
  require 'cql/client/batch'
487
152
  require 'cql/client/query_result'
488
153
  require 'cql/client/void_result'
489
154
  require 'cql/client/request_runner'
490
155
  require 'cql/client/authenticators'
491
- require 'cql/client/peer_discovery'
156
+ require 'cql/client/peer_discovery'