Skip to content

cwegrzyn/vertica

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vertica

Vertica is a pure Ruby library for connecting to Vertica databases. You can learn more about Vertica at http://www.vertica.com.

This library currently supports simple queries. Prepared statements are currently not supported but are being worked on. The gem is tested against Vertica version 5.0 and should work in both Ruby 1.8 and Ruby 1.9.

Install

$ gem install vertica

Source

Vertica's git repo is available on GitHub, which can be browsed at:

http://github.com/sprsquish/vertica

and cloned from:

git://github.com/sprsquish/vertica.git

Usage

Connecting

The Vertica.connect methods takes a connection parameter hash and returns a connection object. For most options, the gem will use a default value if no value is provided.

connection = Vertica.connect({
  :host     => 'db_server',
  :user     => 'user',
  :password => 'password',
  # :ssl         => false, # use SSL for the connection
  # :port        => 5433,  # default Vertica port: 5433
  # :database    => 'db',  # there is only one database
  # :role        => nil,   # the (additional) role(s) to enable for the user.
  # :search_path => nil,   # default: <user>,public,v_catalog
  # :row_style   => :hash  # can also be :array (see below)
})

To close the connection when you're done with it, run connection.close.

Querying

You can run simple queries using the query method, either in buffered and unbuffered mode. For large result sets, you probably do not want to use buffered results.

Unbuffered result

Get all the result rows without buffering by providing a block:

connection.query("SELECT id, name FROM my_table") do |row|
  puts row # => {:id => 123, :name => "Jim Bob"}
end

connection.close

Buffered result

Store the result of the query method as a variable to get a buffered resultset:

result = connection.query("SELECT id, name FROM my_table")
connection.close

result.rows # => [{:id => 123, :name => "Jim Bob"}, {:id => 456, :name => "Joe Jack"}]
result.row_count # => 2

result.each do |row|
  puts row # => {:id => 123, :name => "Jim Bob"}
end

Row format

By default, rows are returned as hashes, using symbols for the column names. Rows can also be returned as arrays by providing a row_style:

connection.query("SELECT id, name FROM my_table", :row_style => :array) do |row|
  puts row # => [123, "Jim Bob"]
end

By adding :row_style => :array to the connection hash, all results will be returned as array.

About

This package is MIT licensed. See the LICENSE file for more information.

Development

This project comes with a test suite. The unit tests in /test/unit do not need a database connection to run, the functional tests in /test/functional do need a working database connection. You can specify the connection parameters by copying the file /test/connection.yml.example to /test/connection.yml and filling out the necessary fields.

Note that the test suite requires write access to the default schema of the provided connection, although it tries to be as little invasive as possible: all tables it creates (and drops) are prefixed with test_ruby_vertica_.

TODO

  • Prepared statements
  • More tests

Authors

About

Ruby Adapter For Vertica Databases

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%