CrateRuby
Official Ruby library to access a Crate database.
Installation
This gem requires Ruby 2.0 or greater.
Add this line to your application's Gemfile:
gem 'crate_ruby'
Or install it yourself as:
$ gem install crate_ruby
Usage
Issueing SQL statements
require 'crate_ruby'
client = CrateRuby::Client.new
result = client.execute("Select * from posts")
=> #<CrateRuby::ResultSet:0x00000002a9c5e8 @rowcount=1, @duration=5>
result.each do |row|
puts row.inspect
end
=> [1, "test", 5]
result.cols
=> ["id", "my_column", "my_integer_col"]
Using parameter substitution
client.execute("INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
[1, "My life with crate", ['awesome', 'freaky']])
Up/Downloading data
digest = Digest::SHA1.file(file_path).hexdigest
# upload
f = File.read(file_path)
client.blob_put(table_name, digest, f)
# download
data = client.blob_get(table_name, digest)
open(file_path, "wb") do |file|
file.write(data)
end
# deletion
client.blob_delete(table_name, digest)
Tests
Start up the crate server before running the tests
ruby spec/test_server.rb /path/to/crate
Then run tests with
bundle exec rspec spec
Contributing
If you think something is missing, either create a pull request or log a new issue, so someone else can tackle it. Please refer to CONTRIBUTING.rst for further information.
Maintainer
License & Copyright
See LICENSE for details.