 (ns er-cassandra.session.alia
   (:require
    [plumbing.core :refer :all]
+   [taoensso.timbre :refer [trace debug info warn error]]
    [clojure.string :as str]
    [qbits.alia :as alia]
    [qbits.alia.policy.load-balancing :as lb]

    SpySession
    KeyspaceProvider]))

(def ^:dynamic debug nil)

(defmacro with-debug
  [& forms]
  `(binding [debug true]
     ~@forms))

(defn- execute*
  [alia-session statement opts]
  (aliam/execute
   alia-session
   (if (string? statement)
     statement
     (do
       (when debug
         (prn statement))
       (h/->raw statement)))
   opts))


  (reset-spy-log [_] (reset! spy-log-atom [])))

(defnk create-spy-session
  [contact-points datacenter keyspace {truncate-on-close nil} :as args]
  (->AliaSpySession
   keyspace
   (create-alia-session* (dissoc args :truncate-on-close))
   (atom [])
   truncate-on-close))

