Database Reference
In-Depth Information
Disconnecting
To disconnect from the cluster, all you need to do is call close on the cluster ob-
ject. Listing 9.24 shows how to do this.
Listing 9.24 Using Ruby to Disconnect from a Cluster
def close
@cluster.close
end
Schema Creation
Now that all of the connections have been created, we can create our schema.
When creating the schema, we can use the optional IF NOT EXISTS condi-
tional, which will allow running the command multiple times without error. When
this conditional is not specified, additional executions of the schema creation code
will result in an error. This conditional is available only in Cassandra 2.0 and later.
Listing 9.25 shows how to create a keyspace and a sample table.
Listing 9.25 Creating a Schema in Ruby
Click here to view code image
def create_schema
create_keyspace = <<-CQL
CREATE KEYSPACE IF NOT EXISTS portfolio_demo
WITH REPLICATION = { 'class': 'Sim-
pleStrategy',
'replication_factor': 1
};
CQL
create_portfolio = <<-CQL
CREATE TABLE IF NOT EXISTS portfo-
lio_demo.portfolio (
portfolio_id UUID,
ticker TEXT,
current_price DECIMAL,
current_change DECIMAL,
 
 
Search WWH ::




Custom Search