Giter Site home page Giter Site logo

crate_ruby's Introduction

CrateDB Ruby Client

Build Status

Gem Version

Total downloads

A Ruby client library for the CrateDB HTTP interface.

  • Query execution support.
  • DDL command and schema introspection shortcuts.
  • Support for BLOB tables.
  • Foundation for the activerecord-crate-adapter.

Prerequisites

You will need Ruby 2.0 or greater.

Installation

The CrateDB Ruby client is available on RubyGems.org, see crate_ruby on RubyGems.org.

To use it, add this line to your application's Gemfile:

gem 'crate_ruby'

Or install it manually:

gem install crate_ruby

Synopsis

Set up the client.

require 'crate_ruby'

client = CrateRuby::Client.new()

Execute SQL queries.

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"]

Perform parameter substitution.

client.execute(
    "INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
    [1, "My life with crate", ['awesome', 'cool']])

Manipulate BLOBs.

require 'digest'

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)

A default schema can be set by passing in the schema name.

CrateRuby::Client.new(['localhost:4200'], schema: 'my_schema')

Authentication credentials can be passed to the client if needed.

CrateRuby::Client.new(['localhost:4200'], username: 'foo', password: 'supersecret')

SSL can be enabled.

CrateRuby::Client.new(['localhost:4200'], ssl: true)

Notes

See also CrateDB examples for Ruby for a basic example program, which exercises both the crate_ruby driver, as well as Ruby's canonical pg driver.

Contributing

This project is primarily maintained by Crate.IO GmbH, but we welcome community contributions!

See the developer docs and the contribution docs for more information.

Help

Looking for more help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.