The following code handles querying for user data in a multitenant Cassandra database. Each tenant has their own keyspace and within that keyspace data about each tenants users is stored.
This code will run as part of a webservice.
I'm looking on comments for how I handled managing the session so that connection pooling is used and only one session is made.
(defn- session []
(cc/connect ["localhost"]
{:credentials
{:username ""
:password ""}}))
(def memo-session (memoize session))
(defn get-recs-by-user-id [client-name client-id user-id]
(cql/use-keyspace (memo-session) client-name)
(cql/select (memo-session) "user_recommendations"
(where [[= :client_id client-id] [= :user_id user-id]])
(limit 1)))