In this example we will create a table storing recipes.
This is an example of how to connect to Cassandra in the easiest possible way.
This is an example of how to connect to Cassandra in the easiest possible way. The SimpleCassandraConnector is designed to get you up and running immediately, with almost 0 effort.
What you have to do now is to tell phantom what keyspace you will be using in Cassandra. This connector will automaticalyl try to connect to localhost:9042. If you want to tell the connector to use a different host:port combination, simply override the address inside it.
Otherwise, simply mixing this connector in will magically inject a database session for all your queries and you can immediately run them.
In this example we will create a simple table storing recipes.
In this example we will create a simple table storing recipes. Data modeling with com.websudos.phantom is trivial and covers some of the more advanced features of Cassandra.
Phantom will auto-generate the CQL3 table definition from your Scala code. And you can automatically insert the schema during tests or even live environments.
This is a very straightforward example, with a non composite Partition key
In this example we will create a table storing recipes with a SecondaryKey.
In this example we will create a table storing recipes with a SecondaryKey. This time we will use a non-composite Primary key with a SecondaryKey on author.
This is an example of how to connect to a custom set of hosts and ports.
This is an example of how to connect to a custom set of hosts and ports. First, we need to obtain a connector and keep a singleton reference to it. It's really important to guarantee we are using a singleton here, otherwise we will end up spawning a cluster on every call.
Now you might ask yourself how to use service discovery with phantom.
Now you might ask yourself how to use service discovery with phantom. The Datastax Java Driver can automatically connect to multiple clusters. Using some underlying magic, phantom can also help you painlessly connect to a series of nodes in a Cassandra cluster via ZooKeeper.
Once again, all you need to tell phantom is what your keyspace is. Phantom will make a series of assumptions about which path you are using in ZooKeeper. By default, it will try to connect to localhost:2181, fetch the "/cassandra" path and parse ports found in a "host:port, host1:port1, .." sequence. All these settings are trivial to override in the below connector and you can adjust all the settings to fit your environment.
In this example we will create a table storing recipes. This time we will use a composite key formed by name and id.