Skip to content

Commit

Permalink
generate store signature but leave jdbc url untouched (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
alekcz authored Apr 16, 2024
1 parent 886d141 commit 7ce289c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:deps {org.clojure/clojure {:mvn/version "1.11.1" :scope "provided"}
io.replikativ/konserve-jdbc {:mvn/version "0.2.82"}
io.replikativ/konserve-jdbc {:mvn/version "0.2.84"}
io.replikativ/datahike {:mvn/version "0.6.1554" :scope "provided"}}
:paths ["src"]
:aliases {:test {:extra-paths ["test"]
Expand Down
17 changes: 7 additions & 10 deletions src/datahike_jdbc/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
[clojure.spec.alpha :as s]
[clojure.string :as str]))

(defn prepare-config [cfg]
;; next.jdbc does not officially support the credentials in the format: driver://user:password@host/db
;; connection/uri->db-spec makes is possible but is rough around the edges
;; https://github.com/seancorfield/next-jdbc/issues/229
(defn generate-signature [cfg]
(if (contains? cfg :jdbcUrl)
(merge
(dissoc cfg :jdbcUrl)
Expand All @@ -20,22 +17,22 @@

(defmethod store-identity :jdbc [store-config]
;; the store signature is made up of the dbtype, dbname, and table
(let [{:keys [dbtype _host _port dbname table]} (prepare-config store-config)]
(let [{:keys [dbtype _host _port dbname table]} (generate-signature store-config)]
[:jdbc dbtype dbname table]))

(defmethod empty-store :jdbc [store-config]
(k/connect-store (prepare-config store-config)))
(k/connect-store store-config))

(defmethod delete-store :jdbc [store-config]
(k/delete-store (prepare-config store-config)))
(k/delete-store store-config))

(defmethod connect-store :jdbc [store-config]
(k/connect-store (prepare-config store-config)))
(k/connect-store store-config))

(defmethod default-config :jdbc [config]
;; with the introduction of the store-identity config data should derived from inputs and not set to default values
(let [env-config (prepare-config (map-from-env :datahike-store-config {}))
passed-config (prepare-config config)]
(let [env-config (map-from-env :datahike-store-config {})
passed-config config]
(merge env-config passed-config)))

(s/def :datahike.store.jdbc/backend #{:jdbc})
Expand Down

0 comments on commit 7ce289c

Please sign in to comment.