 (defmacro def-db-component
   "Defines a new database component."
   [name & {:keys [auto-migration?]
-           :or {auto-migration? false}}]
+           :or   {auto-migration? false}}]
   ; 'configuration' must be provided during initialization
   ; 'datasource' is the internal state
   ; HINT: this component is itself a valid db-spec as its a map with the key 'datasource'

  (:import (com.jolbox.bonecp BoneCPDataSource)
           (org.flywaydb.core Flyway)
           (java.sql Timestamp)
           (java.io PrintWriter)))

(defn start-component [component auto-migration?]
  (if (:datasource component)

     (stop [this#]
       (stop-component this#))))

(def iso-format "yyyy-MM-dd'T'HH:mm:ss.SSSZ")

; provide json serialization
(defn- serialize-sql-timestamp
  "Serializes a sql timestamp to json."
  [^Timestamp timestamp #^PrintWriter out]
  (.print out (-> (SimpleDateFormat. iso-format)
                  (.format timestamp)
                  (json/write-str))))

; add json capability to java.sql.Timestamp
(extend Timestamp json/JSONWriter
