Example Ruby code for Data Warehouse

The following Ruby script provides a simple example for how to connect to Data Warehouse using JRuby and then to execute a simple query using Sequel:

#!/usr/bin/env ruby

require 'rubygems'
require 'sequel'
require 'jdbc/dss'

Jdbc::DSS.load_driver
Java.com.gooddata.dss.jdbc.driver.DssDriver

# replace with your Data Warehouse instance:
dss_jdbc_url = 'jdbc:gdc:datawarehouse://secure.gooddata.com/gdc/datawarehouse/instances/[DW_ID]'
# replace with your GoodData platform login name:
username = 'joe.user@example.com'
# replace with your GoodData platform password:
password = 'MyPassword'

# example query 
Sequel.connect dss_jdbc_url, :username => username, :password => password do |conn|
  conn.run "CREATE TABLE IF NOT EXISTS my_first_table (id INT, value VARCHAR(255))"
  conn.run "INSERT INTO my_first_table (id, value) VALUES (1, 'one')"
  conn.run "INSERT INTO my_first_table (id, value) VALUES (2, 'two')"
  conn.fetch "SELECT * FROM my_first_table WHERE id < ?", 3 do |row|
    puts row
  end
end