lib/superstore/adapters/cassandra_adapter.rb in superstore-1.1.1 vs lib/superstore/adapters/cassandra_adapter.rb in superstore-1.1.2
- old
+ new
@@ -52,11 +52,14 @@
end
def connection
@connection ||= begin
thrift_options = (config[:thrift] || {})
- CassandraCQL::Database.new(servers, {keyspace: config[:keyspace]}, thrift_options)
+ CassandraCQL::Database.new(
+ servers,
+ {keyspace: config[:keyspace], username: username, password: password, cql_version: '2.0.0'},
+ thrift_options)
end
end
def servers
Array.wrap(config[:servers] || "127.0.0.1:9160")
@@ -127,14 +130,17 @@
def drop_table(table_name)
schema_execute "DROP TABLE #{table_name}", config[:keyspace]
end
def schema_execute(cql, keyspace)
- schema_db = CassandraCQL::Database.new(Superstore::Base.adapter.servers, {keyspace: keyspace}, {connect_timeout: 30, timeout: 30})
+ schema_db = CassandraCQL::Database.new(
+ servers,
+ {keyspace: keyspace, username: username, password: password, cql_version: '2.0.0'},
+ {connect_timeout: 30, timeout: 30}
+ )
schema_db.execute cql
end
- # /SCHEMA
def consistency
@consistency ||= config[:consistency]
end
@@ -165,9 +171,17 @@
sql = ids.is_a?(Array) ? "#{primary_key_column} IN (?)" : "#{primary_key_column} = ?"
sanitize(sql, ids)
end
private
+
+ def username
+ config[:username].presence
+ end
+
+ def password
+ config[:password].presence
+ end
def sanitize(statement, *bind_vars)
CassandraCQL::Statement.sanitize(statement, bind_vars).force_encoding(Encoding::UTF_8)
end