7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/cql/client/request_runner.rb', line 7
def execute(connection, request, timeout=nil)
connection.send_request(request, timeout).map do |response|
case response
when Protocol::RowsResultResponse
QueryResult.new(response.metadata, response.rows, response.trace_id)
when Protocol::VoidResultResponse
response.trace_id ? VoidResult.new(response.trace_id) : VoidResult::INSTANCE
when Protocol::ErrorResponse
cql = request.is_a?(Protocol::QueryRequest) ? request.cql : nil
details = response.respond_to?(:details) ? response.details : nil
raise QueryError.new(response.code, response.message, cql, details)
when Protocol::SetKeyspaceResultResponse
KeyspaceChanged.new(response.keyspace)
when Protocol::AuthenticateResponse
AuthenticationRequired.new(response.authentication_class)
when Protocol::SupportedResponse
response.options
else
if block_given?
yield response
else
nil
end
end
end
end
|