Database Reference
In-Depth Information
@cluster.execute(row_two)
end
Reading Data
When reading data, the query execution will return an iterable set of results that
will allow access to the values of the fields requested. Listing 9.27 shows query
execution and printing the results to the console.
Listing 9.27 Reading Data in Ruby
Click here to view code image
def print_results
fields = %w(ticker current_price current_change
current_change_percent)
results_query = <<-CQL
SELECT * FROM portfolio_demo.portfolio
WHERE portfolio_id =
756716f7-2e54-4715-9f00-91dcbea6cf50;
CQL
puts "Ticker\tPrice\tChange\tPCT"
puts '........+........+........+........'
results = @cluster.execute(results_query)
results.each do |row|
puts "%s\t%0.2f\t%0.2f\t%0.2f" % fields.map{|f|
row[f] }
end
end
Putting It All Together
Listing 9.28 shows the entire sample class as it would look in an application.
Listing 9.28 Full Ruby Example
Click here to view code image
require 'cql'
 
 
Search WWH ::




Custom Search