0
\$\begingroup\$

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)))
\$\endgroup\$
1
\$\begingroup\$

This doesn't feel idiomatic to me.

I would prefer to use an atom or a dynamic variable if you must store the session outside, but really you should probably be passing the session in on each call.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.