Skip to content

Commit

Permalink
apply the sql architectural changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolap committed Jan 28, 2022
1 parent 6181495 commit dc4a5b6
Show file tree
Hide file tree
Showing 18 changed files with 160 additions and 170 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Change Log

## 28.01.2022

### `io.github.kit-clj/kit-mysql {:mvn/version 1.0.0}`

- Initial release [PR #18](https://github.com/kit-clj/kit/pull/18)

### `io.github.kit-clj/kit-sql {:mvn/version 1.1.0}`

- Change: Now just a bare bones wrapper that imports kit-sql-conman and kit-sql-migratus for compatibility purposes

### `io.github.kit-clj/kit-sql-conman {:mvn/version 1.0.0}`

- Initial release

### `io.github.kit-clj/kit-sql-hikari {:mvn/version 1.0.1}`

- Initial release

### `io.github.kit-clj/kit-sql-migratus {:mvn/version 1.0.0}`

- Initial release

### `io.github.kit-clj/lein-template {:mvn/version "0.1.6"}`

- Template updated for the sql variants

## 23.01.2022

### `io.github.kit-clj/lein-template {:mvn/version "0.1.5"}`
Expand Down
2 changes: 1 addition & 1 deletion build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
(if (contains? dep-mappings lib)
(if (not-empty (dep/transitive-dependencies graph lib))
(doseq [lib' (concat (dep/transitive-dependencies graph lib) [lib])]
(all (= lib' lib) lib'))
(all (and publish? (= lib' lib)) lib'))
(all publish? lib))
(println "Can't find: " artifact-id))))

Expand Down
3 changes: 1 addition & 2 deletions libs/kit-mysql/deps.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{:paths ["src"]
:deps {mysql/mysql-connector-java {:mvn/version "8.0.27"}
}}
:deps {mysql/mysql-connector-java {:mvn/version "8.0.28"}}}
4 changes: 4 additions & 0 deletions libs/kit-sql-conman/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:paths ["src"]
:deps {integrant/integrant {:mvn/version "0.8.0"}
conman/conman {:mvn/version "0.9.3"}
io.github.kit-clj/kit-core {:mvn/version "1.0.1"}}}
30 changes: 30 additions & 0 deletions libs/kit-sql-conman/src/kit/edge/db/sql/conman.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(ns kit.edge.db.sql.conman
(:require
[conman.core :as conman]
[integrant.core :as ig]
[kit.ig-utils :as ig-utils]
[migratus.core :as migratus]))

(defmethod ig/init-key :db.sql/connection
[_ pool-spec]
(conman/connect! pool-spec))

(defmethod ig/suspend-key! :db.sql/connection [_ _])

(defmethod ig/halt-key! :db.sql/connection
[_ conn]
(conman/disconnect! conn))

(defmethod ig/resume-key :db.sql/connection
[key opts old-opts old-impl]
(ig-utils/resume-handler key opts old-opts old-impl))

(defmethod ig/init-key :db.sql/query-fn
[_ {:keys [conn options filename]
:or {options {}}}]
(let [queries (conman/bind-connection-map conn options filename)]
(fn
([query params]
(conman/query queries query params))
([conn query params & opts]
(apply conman/query conn queries query params opts)))))
5 changes: 0 additions & 5 deletions libs/kit-sql-general/deps.edn

This file was deleted.

5 changes: 5 additions & 0 deletions libs/kit-sql-hikari/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:paths ["src"]
:deps {integrant/integrant {:mvn/version "0.8.0"}
com.github.seancorfield/next.jdbc {:mvn/version "1.2.761"} ;; TODO: is this required here?
hikari-cp/hikari-cp {:mvn/version "2.13.0"}
io.github.kit-clj/kit-core {:mvn/version "1.0.1"}}}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
(ns kit.edge.db.sql.general
(ns kit.edge.db.sql.hikari
(:require
[hikari-cp.core :as cp]
[integrant.core :as ig]
[kit.ig-utils :as ig-utils]
[hikari-cp.core :as cp]
))

(defmethod ig/init-key :db.sql.general/connection
(defmethod ig/init-key :db.sql/hikari-connection
[_ pool-spec]
(cp/make-datasource pool-spec))

(defmethod ig/suspend-key! :db.sql.general/connection [_ _])
(defmethod ig/suspend-key! :db.sql/hikari-connection [_ _])

(defmethod ig/halt-key! :db.sql.general/connection
(defmethod ig/halt-key! :db.sql/hikari-connection
[_ conn]
(cp/close-datasource conn))

(defmethod ig/resume-key :db.sql.general/connection
(defmethod ig/resume-key :db.sql/hikari-connection
[key opts old-opts old-impl]
(ig-utils/resume-handler key opts old-opts old-impl))

Expand Down
3 changes: 3 additions & 0 deletions libs/kit-sql-migratus/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{:paths ["src"]
:deps {integrant/integrant {:mvn/version "0.8.0"}
migratus/migratus {:mvn/version "1.3.5"}}}
13 changes: 13 additions & 0 deletions libs/kit-sql-migratus/src/kit/edge/db/sql/migratus.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(ns kit.edge.db.sql.migratus
(:require
[integrant.core :as ig]
[migratus.core :as migratus]))

(defmethod ig/init-key :db.sql/migrations
[_ {:keys [migrate-on-init?]
:or {migrate-on-init? true}
:as component}]
(when migrate-on-init?
(migratus/migrate component))
component)

6 changes: 2 additions & 4 deletions libs/kit-sql/deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{:paths ["src"]
:deps {integrant/integrant {:mvn/version "0.8.0"}
conman/conman {:mvn/version "0.9.3"}
migratus/migratus {:mvn/version "1.3.5"}
io.github.kit-clj/kit-core {:mvn/version "1.0.0"}}}
:deps {io.github.kit-clj/kit-sql-conman {:mvn/version "1.0.0"}
io.github.kit-clj/kit-sql-migratus {:mvn/version "1.0.0"}}}
40 changes: 4 additions & 36 deletions libs/kit-sql/src/kit/edge/db/sql.clj
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
(ns kit.edge.db.sql
"This library simply in kit-sql-conman and kit-sql-migratus for compatibility purposes.
It serves no other purpose"
(:require
[conman.core :as conman]
[integrant.core :as ig]
[kit.ig-utils :as ig-utils]
[migratus.core :as migratus]))

(defmethod ig/init-key :db.sql/connection
[_ pool-spec]
(conman/connect! pool-spec))

(defmethod ig/suspend-key! :db.sql/connection [_ _])

(defmethod ig/halt-key! :db.sql/connection
[_ conn]
(conman/disconnect! conn))

(defmethod ig/resume-key :db.sql/connection
[key opts old-opts old-impl]
(ig-utils/resume-handler key opts old-opts old-impl))

(defmethod ig/init-key :db.sql/query-fn
[_ {:keys [conn options filename]
:or {options {}}}]
(let [queries (conman/bind-connection-map conn options filename)]
(fn
([query params]
(conman/query queries query params))
([conn query params & opts]
(apply conman/query conn queries query params opts)))))

(defmethod ig/init-key :db.sql/migrations
[_ {:keys [migrate-on-init?]
:or {migrate-on-init? true}
:as component}]
(when migrate-on-init?
(migratus/migrate component))
component)
[kit.edge.db.sql.conman]
[kit.edge.db.sql.migratus]))
12 changes: 8 additions & 4 deletions libs/lein-template/resources/leiningen/new/kit/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
io.github.kit-clj/kit-core {:mvn/version "<<versions.kit-core>>"}
io.github.kit-clj/kit-undertow {:mvn/version "<<versions.kit-undertow>>"}<% if xtdb? %>
io.github.kit-clj/kit-xtdb {:mvn/version "<<versions.kit-xtdb>>"}<% endif %><% if mysql? %>
io.github.kit-clj/kit-sql-general {:mvn/version "<<versions.kit-sql-general>>"}
io.github.kit-clj/kit-mysql {:mvn/version "<<versions.kit-mysql>>"}<% endif %><% if pgsql? %>
io.github.kit-clj/kit-sql {:mvn/version "<<versions.kit-sql>>"}
io.github.kit-clj/kit-postgres{:mvn/version "<<versions.kit-postgres>>"}<% endif %><% if hato? %>
io.github.kit-clj/kit-mysql {:mvn/version "<<versions.kit-mysql>>"}<%if conman? %>
io.github.kit-clj/kit-sql-conman {:mvn/version "<<versions.kit-sql-conman>>"}
io.github.kit-clj/kit-sql-migratus {:mvn/version "<<versions.kit-sql-migratus>>"}<% endif %><% if hikari? %>
io.github.kit-clj/kit-sql-hikari {:mvn/version "<<versions.kit-sql-hikari>>"}<% endif %><% endif %><% if sql? %>
io.github.kit-clj/kit-postgres{:mvn/version "<<versions.kit-postgres>>"}<%if conman? %>
io.github.kit-clj/kit-sql-conman {:mvn/version "<<versions.kit-sql-conman>>"}
io.github.kit-clj/kit-sql-migratus {:mvn/version "<<versions.kit-sql-conman>>"}<% endif %><% if hikari? %>
io.github.kit-clj/kit-sql-hikari {:mvn/version "<<versions.kit-sql-hikari>>"}<% endif %><% endif %><% if hato? %>
io.github.kit-clj/kit-hato {:mvn/version "<<versions.kit-hato>>"}<% endif %><% if quartz? %>
io.github.kit-clj/kit-quartz {:mvn/version "<<versions.kit-quartz>>"}<% endif %><% if redis? %>
io.github.kit-clj/kit-redis {:mvn/version "<<versions.kit-redis>>"}<% endif %><% if selmer? %>
Expand Down
72 changes: 0 additions & 72 deletions libs/lein-template/resources/leiningen/new/kit/project.clj

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
:db.xtdb/node
{}
<% endif %>
<% if mysql? %>
:db.sql.general/connection
<% if hikari? %>
:db.sql/hikari-connection
#profile {:dev {:jdbc-url "jdbc:mysql://127.0.0.1:3306/<<name>>?characterEncoding=utf8"}
:test {}
:prod {:auto-commit true
Expand All @@ -92,7 +92,7 @@
:driver-class-name "com.mysql.jdbc.Driver"
:register-mbeans false}}
<% endif %>
<% if pgsql? %>
<% if conman? %>
:db.sql/connection
#profile {:dev {:jdbc-url "jdbc:postgresql://localhost/<<name>>?user=<<name>>&password=<<name>>"}
:test {}
Expand All @@ -106,7 +106,8 @@
{:conn #ig/ref :db.sql/connection
:options {}
:filename "queries.sql"}

<% endif %>
<% if sql? %>
:db.sql/migrations
{:store :database
:db {:datasource #ig/ref :db.sql/connection}
Expand Down
11 changes: 6 additions & 5 deletions libs/lein-template/resources/leiningen/new/kit/src/clj/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

;; Edges <% if redis? %>
[kit.edge.cache.redis]<% endif %> <% if xtdb? %>
[kit.edge.db.xtdb]<% endif %><% if mysql? %>
[kit.edge.db.sql.general]
[kit.edge.db.sql.mysql]<% endif %><% if pgsql? %>
[kit.edge.db.sql]
[kit.edge.db.postgres]<% endif %> <% if hato? %>
[kit.edge.db.xtdb]<% endif %><% if hikari? %>
[kit.edge.db.sql.hikari]<% endif %><% if sql? %>
[kit.edge.db.sql.conman]
[kit.edge.db.sql.migratus]
[kit.edge.db.postgres]<% endif %><% if mysql? %>
[kit.edge.db.sql.mysql]<% endif %><% if hato? %>
[kit.edge.http.hato]<% endif %> <% if quartz? %>
[kit.edge.scheduling.quartz]<% endif %> <% if selmer? %>
[kit.edge.templating.selmer]<% endif %> <% if metrics? %>
Expand Down
Loading

0 comments on commit dc4a5b6

Please sign in to comment.