korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.48k stars 222 forks source link

Add firebird connection function #113

Open turtle-bazon opened 11 years ago

turtle-bazon commented 11 years ago

And in future support for firebird but at this moment please include function to creating firebird connection. I've created following function you can review and please include it.

(defn firebird "Create a database specification for a firebird database. Opts should include keys for :db, :user, and :password. You can also optionally set host and port." [{:keys [host port db props] :or {host "localhost", port 3050, db "", props {}} :as opts}](let [me-to-string %28fn [me] %28str %28name %28key me%29%29 "=" %28val me)))] (merge {:classname "org.firebirdsql.jdbc.FBDriver" ; must be in classpath :subprotocol "firebirdsql" :subname (str host "/" port ":" db (if (> (count props) 0) (str "?" (reduce (fn [me1 me2](str %28if %28string? me1%29 me1 %28me-to-string me1%29%29 "&" %28me-to-string me2))) props))))} opts)))

turtle-bazon commented 11 years ago

Simplified version

(defn firebird
  "Create a database specification for a firebird database. Opts should include keys
  for :db, :user, and :password. You can also optionally set host and port."
  [{:keys [host port db props]
    :or {host "localhost", port 3050, db "", props {}}
    :as opts}]
  (merge {:classname "org.firebirdsql.jdbc.FBDriver" ; must be in classpath
          :subprotocol "firebirdsql"
          :subname (str host "/" port ":" db 
                        (if (> (count props) 0)
                          (str "?" 
                               (reduce (fn [pv1 pv2]
                                         (str pv1 "&" pv2))
                                       (for [[k v] props]
                                         (str (name k) "=" v))))))}
         opts))