Skip to content

Commit

Permalink
Modified changes according to suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
astronomy88 committed Feb 23, 2014
1 parent 6719a96 commit 9326076
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 14 additions & 3 deletions lib/cassandra-cql/database.rb
Expand Up @@ -100,12 +100,12 @@ def prepare(statement, options={}, &block)
end
end

def execute(statement, consistency=CassandraCQL::Thrift::ConsistencyLevel::QUORUM, *bind_vars)
def execute_with_consistency(statement, consistency=CassandraCQL::Thrift::ConsistencyLevel::QUORUM, *bind_vars)
# consistency can include either of the following options:
# - CassandraCQL::Thrift::ConsistencyLevel::QUORUM
# - CassandraCQL::Thrift::ConsistencyLevel::LOCAL_QUORUM
# - CassandraCQL::Thrift::ConsistencyLevel::ONE
result = statement_class.new(self, statement).execute(bind_vars, consistency)
result = statement_class.new(self, statement).execute(bind_vars, {:consistency => consistency})
if block_given?
yield result
else
Expand All @@ -115,7 +115,18 @@ def execute(statement, consistency=CassandraCQL::Thrift::ConsistencyLevel::QUORU
raise Error::InvalidRequestException.new($!.why)
end

def execute_cql_query(cql, compression=CassandraCQL::Thrift::Compression::NONE, consistency)
def execute(statement, *bind_vars)
result = statement_class.new(self, statement).execute(bind_vars)
if block_given?
yield result
else
result
end
rescue CassandraCQL::Thrift::InvalidRequestException
raise Error::InvalidRequestException.new($!.why)
end

def execute_cql_query(cql, compression=CassandraCQL::Thrift::Compression::NONE, consistency=CassandraCQL::Thrift::ConsistencyLevel::QUORUM)
if use_cql3?
@connection.execute_cql3_query(cql, compression, consistency)
else
Expand Down
7 changes: 6 additions & 1 deletion lib/cassandra-cql/statement.rb
Expand Up @@ -36,14 +36,19 @@ def prepare(statement)
@statement = statement
end

def execute(bind_vars=[], consistency, options={})
def execute(bind_vars=[], options={})
sanitized_query = self.class.sanitize(@statement, bind_vars, @handle.use_cql3?)
compression_type = CassandraCQL::Thrift::Compression::NONE
if options[:compression]
compression_type = CassandraCQL::Thrift::Compression::GZIP
sanitized_query = Utility.compress(sanitized_query)
end

consistency = CassandraCQL::Thrift::ConsistencyLevel::QUORUM
if options[:consistency]
consistency = options[:consistency]
end

res = Result.new(@handle.execute_cql_query(sanitized_query, compression_type, consistency))

# Change our keyspace if required
Expand Down

0 comments on commit 9326076

Please sign in to comment.