-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db9c1d7
commit 408ef27
Showing
34 changed files
with
472 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
examples/poly-rcf/.clj-kondo/com.github.seancorfield/next.jdbc/config.edn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{:hooks | ||
{:analyze-call | ||
{next.jdbc/with-transaction | ||
hooks.com.github.seancorfield.next-jdbc/with-transaction}} | ||
:lint-as {next.jdbc/on-connection clojure.core/with-open}} |
18 changes: 18 additions & 0 deletions
18
...kondo/com.github.seancorfield/next.jdbc/hooks/com/github/seancorfield/next_jdbc.clj_kondo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns hooks.com.github.seancorfield.next-jdbc | ||
(:require [clj-kondo.hooks-api :as api])) | ||
|
||
(defn with-transaction | ||
"Expands (with-transaction [tx expr opts] body) | ||
to (let [tx expr] opts body) per clj-kondo examples." | ||
[{:keys [:node]}] | ||
(let [[binding-vec & body] (rest (:children node)) | ||
[sym val opts] (:children binding-vec)] | ||
(when-not (and sym val) | ||
(throw (ex-info "No sym and val provided" {}))) | ||
(let [new-node (api/list-node | ||
(list* | ||
(api/token-node 'let) | ||
(api/vector-node [sym val]) | ||
opts | ||
body))] | ||
{:node new-node}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
**/classes | ||
**/target | ||
**/.artifacts | ||
**/.cpcache | ||
**/.DS_Store | ||
**/.gradle | ||
|
||
# User-specific stuff | ||
.idea/**/workspace.xml | ||
.idea/**/tasks.xml | ||
.idea/**/usage.statistics.xml | ||
.idea/**/shelf | ||
.idea/**/statistic.xml | ||
.idea/dictionaries/** | ||
.idea/libraries/** | ||
|
||
# File-based project format | ||
*.iws | ||
*.ipr | ||
|
||
# Cursive Clojure plugin | ||
.idea/replstate.xml | ||
*.iml | ||
|
||
/example/example/** | ||
artifacts | ||
projects/**/pom.xml | ||
|
||
# nrepl | ||
.nrepl-port | ||
|
||
# clojure-lsp | ||
.lsp/.cache | ||
|
||
# clj-kondo | ||
.clj-kondo/.cache | ||
|
||
# Calva VS Code Extension | ||
.calva/output-window/output.calva-repl | ||
|
||
.portal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"calva.replConnectSequences": [ | ||
{ | ||
"projectType": "deps.edn", | ||
"name": "poly-rcf", | ||
"cljsType": "none", | ||
"menuSelections": { | ||
"cljAliases": ["dev", "test", "+default"] | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
;; I had to add hyperfiddle/rcf + slf4j, for the tests to run. | ||
{:paths ["src"] | ||
:deps {com.hyperfiddle/rcf {:mvn/version "20220405"}} | ||
:aliases {:test {:extra-paths ["test"] | ||
:extra-deps {org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(ns poly-rcf.empty.core) |
5 changes: 5 additions & 0 deletions
5
examples/poly-rcf/bases/empty/test/poly_rcf/empty/core_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(ns poly-rcf.empty.core-test | ||
(:require [clojure.test :as test :refer :all])) | ||
|
||
(deftest dummy-test | ||
(is (= 1 1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:paths ["src"] | ||
:deps {com.hyperfiddle/rcf {:mvn/version "20220405"}} | ||
:aliases {:test {:extra-paths ["test"] ;; We don't need "src" here. | ||
:extra-deps {org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns poly-rcf.rcf.config) | ||
;; A master configuration file. | ||
;; Can be overriden with configuration files down in the classpath, | ||
;; environment variables, and system properties | ||
|
||
{:dre {} | ||
:sentry {:dsn "" | ||
:environment ""}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns poly-rcf.rcf.src-ns | ||
(:require [hyperfiddle.rcf :refer [tests]])) | ||
|
||
(tests | ||
|
||
(+ 1 1) := 2 | ||
|
||
) |
11 changes: 11 additions & 0 deletions
11
examples/poly-rcf/bases/rcf/test/poly_rcf/rcf/sample2_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
(ns poly-rcf.rcf.sample2-test | ||
(:require [clojure.test :as t :refer [deftest is testing]])) | ||
|
||
(deftest math-works | ||
(testing "basic addition and subtraction" | ||
(is (= 42 (+ 40 2))) | ||
(is (= 42 (- 44 2))))) | ||
|
||
(deftest ^:integration test-i | ||
(is (= 1 1))) | ||
|
8 changes: 8 additions & 0 deletions
8
examples/poly-rcf/bases/rcf/test/poly_rcf/rcf/sample_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns poly-rcf.rcf.sample-test | ||
(:require [hyperfiddle.rcf :refer [tests]])) | ||
|
||
(tests | ||
|
||
(= 1 1) := true | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns poly-rcf.rcf.test-ns | ||
(:require [hyperfiddle.rcf :refer [tests]])) | ||
|
||
(tests | ||
|
||
(+ 1 1) := 2 | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{:paths ["src"] | ||
:deps {com.github.seancorfield/next.jdbc {:mvn/version "1.3.874"} | ||
com.github.seancorfield/honeysql {:mvn/version "2.4.1026"} | ||
com.zaxxer/HikariCP {:mvn/version "5.0.1" | ||
:exclusions [org.slf4j/slf4j-api]} | ||
org.clojure/tools.logging {:mvn/version "1.2.4"}} | ||
:aliases {:test {:extra-paths ["test" "src"] ;; Adding src makes poly tool discover RCF tests under src/ | ||
:extra-deps {com.h2database/h2 {:mvn/version "2.1.214"} | ||
com.stuartsierra/component {:mvn/version "1.1.0"}}}}} |
57 changes: 57 additions & 0 deletions
57
examples/poly-rcf/components/sqldb/src/poly_rcf/sqldb/core.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
;; Copyright (C) 2022, Doctor Evidence. All rights reserved. | ||
|
||
(ns poly-rcf.sqldb.core | ||
"SQL DB client impl." | ||
{:authors ["Jozef Wagner"]} | ||
(:require [clojure.tools.logging :refer [info]] | ||
[next.jdbc.connection :as connection]) | ||
(:import [com.zaxxer.hikari HikariDataSource])) | ||
|
||
(defn get-connection | ||
[sqlconn] | ||
(or (:hikari-datasource sqlconn) sqlconn)) | ||
|
||
;;; SQLDB | ||
|
||
;;; System Component | ||
|
||
(defn start-component | ||
[new-sqldb] | ||
(info "Create component with db" new-sqldb) | ||
(let [db-spec (:db-spec new-sqldb) | ||
hikari-datasource (connection/->pool HikariDataSource db-spec)] | ||
(assoc new-sqldb | ||
:hikari-datasource hikari-datasource))) | ||
|
||
(defn stop-component | ||
[sqldb] | ||
(when-let [^HikariDataSource ds (:hikari-datasource sqldb)] | ||
(when-not (.isClosed ds) | ||
(.close ds))) | ||
(dissoc sqldb :hikari-datasource)) | ||
|
||
(defn suspend-component | ||
[sqldb] | ||
(info "Suspending SQLDB component") | ||
sqldb) | ||
|
||
(defn resume-component | ||
[_new-sqldb suspended-sqldb] | ||
;; TODO: Proper reconnect when cfg changes | ||
(info "Resuming SQLDB component") | ||
suspended-sqldb) | ||
|
||
(defn new-component | ||
"Returns new sqldb system component." | ||
[cfg tag] | ||
(let [db-config (get-in cfg [:dre tag])] | ||
(-> db-config | ||
(with-meta {'com.stuartsierra.component/start start-component | ||
'com.stuartsierra.component/stop stop-component | ||
'suspendable.core/suspend suspend-component | ||
'suspendable.core/resume resume-component})))) | ||
|
||
(comment | ||
|
||
(set! *warn-on-reflection* true)) | ||
|
8 changes: 8 additions & 0 deletions
8
examples/poly-rcf/components/sqldb/src/poly_rcf/sqldb/interface.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(ns poly-rcf.sqldb.interface | ||
(:require [poly-rcf.sqldb.core :as core])) | ||
|
||
|
||
(defn new-component | ||
"Returns new sqldb system component." | ||
[cfg tag] | ||
(core/new-component cfg tag)) |
35 changes: 35 additions & 0 deletions
35
examples/poly-rcf/components/sqldb/test/poly_rcf/sqldb/interface_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns poly-rcf.sqldb.interface-test | ||
(:require [clojure.set :as set] | ||
[clojure.test :refer :all] | ||
[clojure.tools.logging :as log] | ||
[com.stuartsierra.component :as component] | ||
[next.jdbc :as jdbc] | ||
[next.jdbc.result-set :as rs] | ||
[poly-rcf.sqldb.interface :as sqldb])) | ||
|
||
;; This fails because of https://github.com/polyfy/polylith/issues/261 | ||
(deftest new-component-test | ||
"Test component works by starting a system and running a query." | ||
(let [config {:dre {:test {:db-spec {:maximum-pool-size 10 | ||
:connection-timeout 30000 | ||
:idle-timeout 600000 | ||
:validation-timeout 5000 | ||
:max-lifetime 1800000 | ||
:jdbcUrl "jdbc:h2:mem:semmed"}}}} | ||
sys (component/system-map | ||
:sqldb (sqldb/new-component config :test)) | ||
s (component/start-system sys) | ||
sqldb (:sqldb s) | ||
data-source (:hikari-datasource sqldb) | ||
_ (log/info "datasource" sqldb) | ||
;; read table metadata | ||
d (with-open [con (jdbc/get-connection data-source)] | ||
(-> (.getMetaData con) ; produces java.sql.DatabaseMetaData | ||
(.getTables nil nil nil (into-array ["TABLE" "VIEW"])) | ||
(rs/datafiable-result-set con))) | ||
some-tables #{"CONSTANTS" "ENUM_VALUES" "INDEXES" | ||
"INDEX_COLUMNS" "INFORMATION_SCHEMA_CATALOG_NAME"} | ||
all-tables (into #{} (map :TABLE_NAME d))] | ||
;; test that some tables are present in metadata | ||
(is (true? (set/subset? some-tables all-tables))) | ||
(component/stop-system s))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
;; To test this config, rename the file to deps.edn. | ||
{:aliases {:dev {:extra-paths ["development/src"] | ||
:extra-deps {poly/sqldb {:local/root "components/sqldb"} | ||
poly/empty {:local/root "bases/empty"} | ||
|
||
org.clojure/clojure {:mvn/version "1.11.1"}}} | ||
|
||
:test {:extra-paths ["bases/rcf/test" | ||
"bases/empty/test"] | ||
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} | ||
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}} | ||
:main-opts ["-m" "cognitect.test-runner"] | ||
:exec-fn cognitect.test-runner.api/test} | ||
|
||
:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"] | ||
:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"] | ||
:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
;; To test this config, rename the file to deps.edn. | ||
{:aliases {:dev {:extra-paths ["development/src"] | ||
:extra-deps {poly/sqldb {:local/root "components/sqldb"} | ||
poly/rcf {:local/root "bases/rcf"} | ||
|
||
org.clojure/clojure {:mvn/version "1.11.1"}}} | ||
|
||
:test {:extra-paths ["bases/rcf/test"] | ||
:extra-deps {org.clojure/test.check {:mvn/version "1.1.1"} | ||
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}} | ||
:main-opts ["-m" "cognitect.test-runner"] | ||
:exec-fn cognitect.test-runner.api/test} | ||
|
||
:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"] | ||
:jvm-opts ["-Dhyperfiddle.rcf.generate-tests=true"] | ||
:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{:aliases {:dev {:extra-paths ["development/src"] | ||
:extra-deps {poly/sqldb {:local/root "components/sqldb"} | ||
poly/rcf {:local/root "bases/rcf"} | ||
poly/empty {:local/root "bases/empty"} | ||
|
||
org.clojure/clojure {:mvn/version "1.11.1"}}} | ||
|
||
:test {:extra-paths ["bases/rcf/test" | ||
"bases/empty/test"]} | ||
|
||
:poly {:main-opts ["-m" "polylith.clj.core.poly-cli.core"] | ||
:jvm-opts [;; Run RCF tests when loading files in REPL | ||
;; https://github.com/hyperfiddle/rcf#ci | ||
"-Dhyperfiddle.rcf.generate-tests=true"] | ||
|
||
:extra-deps {polylith/clj-poly {:local/root "../../projects/poly"}}}}} | ||
;; Add this line to use the external test runner + a row in workspace.edn. | ||
;;io.github.seancorfield/polylith-external-test-runner {:git/tag "v0.4.0" :git/sha "eb954fe" :deps/root "projects/runner"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
;; Run tests with: clojure -A:dev -X:test | ||
{:aliases {:dev {:extra-paths ["src"] | ||
:extra-deps {com.github.seancorfield/next.jdbc {:mvn/version "1.3.874"} | ||
com.github.seancorfield/honeysql {:mvn/version "2.4.1026"} | ||
com.zaxxer/HikariCP {:mvn/version "5.0.1" :exclusions [org.slf4j/slf4j-api]} | ||
org.clojure/tools.logging {:mvn/version "1.2.4"} | ||
org.clojure/clojure {:mvn/version "1.11.1"}}} | ||
|
||
;; https://clojure.org/guides/deps_and_cli#test_runner | ||
:test {:extra-paths ["test"] | ||
:extra-deps {com.h2database/h2 {:mvn/version "2.1.214"} | ||
com.stuartsierra/component {:mvn/version "1.1.0"} | ||
org.clojure/test.check {:mvn/version "1.1.1"} | ||
org.slf4j/slf4j-simple {:mvn/version "2.0.0-beta1"} | ||
io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}} | ||
:main-opts ["-m" "cognitect.test-runner"] | ||
:exec-fn cognitect.test-runner.api/test}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(ns poly-rcf.empty.core) |
Oops, something went wrong.