nepalez / query_builder

CQL statement builder
MIT License
4 stars 4 forks source link

QueryBuilder

Gem Version Build Status Dependency Status Code Climate Coverage Inline docs

Builder of CQL 3 (Cassandra Query Language) statements in OOP style.

Synopsis

require "query_builder"

include QueryBuilder::CQL::Operators # for operators like cql_gt, cql_lte below.

table = QueryBuilder::CQL.keyspace(:auth).table(:users)

statement = table
  .select(:id, :role)
  .select(name: :user)
  .where(id: cql_gt(1))
  .where(id: cql_lte(4))
  .using(consistency: :quorum)
  .limit(3)
# => #<QueryBuilder::CQL::Statements::Select ...>

statement.to_s
# => "SELECT id, role, user AS name FROM auth.users WHERE id > 1 AND id <= 4 USING consistency = 'quorum' LIMIT 3;"

See the list of all supported contexts, statements and operators.

The gem doesn't depend on any specific Cassandra driver. It could be used to extend official Datastax driver with features of CQL building.

It doesn't validate CQL statements, leaving this to either driver or Cassandra database.

Installation

Add this line to your application's Gemfile:

# Gemfile
gem "query_builder"

Then execute:

bundle

Or add it manually:

gem install query_builder

Compatibility

Tested under rubies compatible to MRI 1.9.3+.

Uses RSpec 3.0+ for testing and hexx-suit for dev/test tools collection.

Contributing

License

See the MIT LICENSE.