Yesterday the Cassandra java driver from Datastax reached 1.0.0, it's an exciting library for Cassandra users in many ways. To quote Datastax announcement:
- Full documentation
- Out-of-the-box best practices for node discovery, load balancing and fail over
- An asynchronous architecture provides simpler concurrency without any thread pool tuning Tracing support
- CQL with prepared statements is about 10% faster than Thrift, and we expect that gap to widen as the native protocol matures
It was just too tempting not to make this available to Clojure and start to build an ecosystem around it.
Hayt is a CQL library, with a DSL a bit similar to Korma/HoneySQL in some aspects. It also allows to easily build your own DSL on top of its map representation of queries. It covers everything defined by the CQL 3.0.3 specification, even supporting some features that will only be available on Cassandara 2.0. It is used by a couple of Cassandra client libraries already.
The tests are quite readable, if you are looking for examples you can find them here, it's a good overview of what it can do.
My goals were not to create a giant API (I already did that with thrift) but stay close to the original, keeping things simple to understand (a handful of function compose the public core of it), be performant, extensible and more importantly cover every single feature the wrapped library has to offer. What it means for instance: you can just as well use raw string queries, prepared statements or Hayt queries from the same functions. It supports synchronous/asynchronous modes, tons of options at the cluster level such as load balancing policy, reconnection policy, retry policy, pooling, metrics, auth, compression, but also per query consistency, routing, retry policy and tracing.
The asynchronous mode returns promises (in the form of Lamina
result-channels) with subscribed callbacks if you provide any to
execute-async, but you can also use them as regular
It also seems an async library might be included in clojure.core in the near future, the chosen approach would allow me to make Alia compatible with it without changing the API (maybe in clojure 1.6, fingers crossed).
The API can be used with or without dynamic bindings (
with-consistency, etc), it's somewhat of a controversial subject, some people, including myself, prefer to use function arguments over bindings. This is described in the docs.
Alia & Hayt both handle the various specific clojure datatypes transparently and provide separate namespaces for handling external types such as Joda DateTime.
Informations, docs & guides
There are more information about both of these libraries on their respective READMEs. Both are documented via codox and Alia also has a usage guide.
I have a couple of ideas for Alia, some taking inspiration from chunked sequences or streams, there are hints of what I have in mind in the issues, but I will be very conservative with what I add to this library.
It's done! To be released in 1.1.0. You can now create lazy sequences over CQL queries, it will trigger queries as needed, making dealing with wide rows a breeze (there are a lot of other useful use cases). Note also that this works with any query type and supports all
On the Hayt side, it's mostly a matter of syncing with the CQL3 specification, which is done almost daily as I see commits land in Cassandra repository, and also work on various optimizations. I don't think there is much to add to it at this point, but I might be wrong.