[#389] SQL feature flags

This commit is contained in:
Michiel Borkent 2020-04-29 14:50:25 +02:00 committed by GitHub
parent 249abdb6ad
commit 0d1cabd4dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 82 additions and 41 deletions

View file

@ -1,4 +1,4 @@
{:paths ["src" "src-xml" "sci/src" "babashka.curl/src" "resources" "sci/resources"],
{:paths ["src" "feature-xml" "feature-yaml" "sci/src" "babashka.curl/src" "resources" "sci/resources"],
:deps {org.clojure/clojure {:mvn/version "1.10.2-alpha1"},
org.clojure/tools.reader {:mvn/version "1.3.2"},
borkdude/edamame {:mvn/version "0.0.11-alpha.9"},

View file

@ -21,16 +21,18 @@
[org.clojure/data.csv "1.0.0"]
[cheshire "5.10.0"]
[fipp "0.6.22"]
[com.cognitect/transit-clj "1.0.324"]
[seancorfield/next.jdbc "1.0.424"]
[org.postgresql/postgresql "42.2.12"]]
:profiles {:feature/xml {:source-paths ["src-xml"]
[com.cognitect/transit-clj "1.0.324"]]
:profiles {:feature/xml {:source-paths ["feature-xml"]
:dependencies [[org.clojure/data.xml "0.2.0-alpha6"]]}
:feature/yaml {:source-paths ["src-yaml"]
:feature/yaml {:source-paths ["feature-yaml"]
:dependencies [[clj-commons/clj-yaml "0.7.1"]]}
:feature/hsqldb {:dependencies [[org.hsqldb/hsqldb "2.4.0"]]}
:feature/jdbc {:source-paths ["feature-jdbc"]
:dependencies [[seancorfield/next.jdbc "1.0.424"]]}
:feature/postgresql [:feature/jdbc {:dependencies [[org.postgresql/postgresql "42.2.12"]]}]
:feature/hsqldb [:feature/jdbc {:dependencies [[org.hsqldb/hsqldb "2.4.0"]]}]
:test [:feature/xml
:feature/yaml
:feature/postgresql
:feature/hsqldb
{:dependencies [[clj-commons/conch "0.9.2"]
[com.clojure-goes-fast/clj-async-profiler "0.4.1"]]}]

View file

@ -1,13 +0,0 @@
#!/usr/bin/env bash
docker run --name babashka-postgres -p 54322:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
if [ "$BABASHKA_TEST_ENV" = "native" ]; then
BB_CMD="./bb"
else
BB_CMD="lein bb"
fi
"$BB_CMD" -f test-resources/babashka/postgres_test.clj
docker rm -f babashka-postgres

20
script/postgresql_test Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
set -eu
trap 'docker rm -f babashka-postgres' EXIT
docker run --name babashka-postgres -p 54322:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
BABASHKA_TEST_ENV=${BABASHKA_TEST_ENV:-}
if [ "$BABASHKA_TEST_ENV" = "native" ]; then
BB_CMD="./bb"
else
BB_CMD="lein with-profiles +feature/jdbc,+feature/postgresql bb"
fi
BABASHKA_FEATURE_JDBC=true \
BABASHKA_FEATURE_POSTGRESQL=true \
$BB_CMD -f test-resources/babashka/postgresql_test.clj

View file

@ -2,13 +2,27 @@
set -eo pipefail
BABASHKA_LEIN_PROFILES=""
BABASHKA_LEIN_PROFILES="+uberjar"
if [ "$BABASHKA_FEATURE_JDBC" = "true" ]
then
BABASHKA_LEIN_PROFILES+=",+feature/jdbc"
else
BABASHKA_LEIN_PROFILES+=",-feature/jdbc"
fi
if [ "$BABASHKA_FEATURE_POSTGRESQL" = "true" ]
then
BABASHKA_LEIN_PROFILES+=",+feature/postgresql"
else
BABASHKA_LEIN_PROFILES+=",-feature/postgresql"
fi
if [ "$BABASHKA_FEATURE_HSQLDB" = "true" ]
then
BABASHKA_LEIN_PROFILES+="+feature/hsqldb"
BABASHKA_LEIN_PROFILES+=",+feature/hsqldb"
else
BABASHKA_LEIN_PROFILES+="-feature/hsqldb"
BABASHKA_LEIN_PROFILES+=",-feature/hsqldb"
fi
if [ "$BABASHKA_FEATURE_XML" != "false" ]
@ -25,8 +39,7 @@ else
BABASHKA_LEIN_PROFILES+=",-feature/yaml"
fi
if [ -z "$BABASHKA_JAR" ]; then
lein with-profiles "+reflection,$BABASHKA_LEIN_PROFILES" do run
lein with-profiles "+uberjar,$BABASHKA_LEIN_PROFILES" do clean, uberjar
lein with-profiles "$BABASHKA_LEIN_PROFILES,+reflection,-uberjar" do run
lein with-profiles "$BABASHKA_LEIN_PROFILES" do clean, uberjar
fi

View file

@ -8,10 +8,24 @@ if "%GRAALVM_HOME%"=="" (
set JAVA_HOME=%GRAALVM_HOME%
set PATH=%PATH%;%GRAALVM_HOME%\bin
if "%BABASHKA_FEATURE_HSQLDB%"=="true" (
set BABASHKA_LEIN_PROFILES=+feature/hsqldb
set BABASHKA_LEIN_PROFILES=+uberjar
if "%BABASHKA_FEATURE_JDBC%"=="true" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/jdbc
) else (
set BABASHKA_LEIN_PROFILES=-feature/hsqldb
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/jdbc
)
if "%BABASHKA_FEATURE_POSTGRESQL%"=="true" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/postgresql
) else (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/postgresql
)
if "%BABASHKA_FEATURE_HSQLDB%"=="true" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/hsqldb
) else (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/hsqldb
)
if not "%BABASHKA_FEATURE_XML%"=="false" (
@ -21,14 +35,14 @@ if not "%BABASHKA_FEATURE_XML%"=="false" (
)
if not "%BABASHKA_FEATURE_YAML%"=="false" (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/yaml
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/yaml
) else (
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/yaml
set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/yaml
)
call lein with-profiles %BABASHKA_LEIN_PROFILES% bb "(+ 1 2 3)"
call lein with-profiles +reflection,%BABASHKA_LEIN_PROFILES% do run
call lein with-profiles %BABASHKA_LEIN_PROFILES%,+reflection,-uberjar do run
if %errorlevel% neq 0 exit /b %errorlevel%
call lein with-profiles "%BABASHKA_LEIN_PROFILES%" do clean, uberjar

View file

@ -6,4 +6,6 @@
(def xml? (not= "false" (System/getenv "BABASHKA_FEATURE_XML")))
;; excluded by default
(def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC")))
(def postgresql? (= "true" (System/getenv "BABASHKA_FEATURE_POSTGRESQL")))
(def hsqldb? (= "true" (System/getenv "BABASHKA_FEATURE_HSQLDB")))

View file

@ -16,7 +16,6 @@
[babashka.impl.csv :as csv]
[babashka.impl.curl :refer [curl-namespace]]
[babashka.impl.features :as features]
[babashka.impl.jdbc :as jdbc]
[babashka.impl.nrepl-server :as nrepl-server]
[babashka.impl.repl :as repl]
[babashka.impl.socket-repl :as socket-repl]
@ -62,6 +61,9 @@
(when features/yaml?
(require '[babashka.impl.yaml]))
(when features/jdbc?
(require '[babashka.impl.jdbc]))
(binding [*unrestricted* true]
(sci/alter-var-root sci/in (constantly *in*))
(sci/alter-var-root sci/out (constantly *out*))
@ -280,10 +282,10 @@ Everything after that is bound to *command-line-args*."))
json cheshire.core
curl babashka.curl
transit cognitect.transit
bencode bencode.core
jdbc next.jdbc}
bencode bencode.core}
features/xml? (assoc 'xml 'clojure.data.xml)
features/yaml? (assoc 'yaml 'clj-yaml.core)))
features/yaml? (assoc 'yaml 'clj-yaml.core)
features/jdbc? (assoc 'jdbc 'next.jdbc)))
(def cp-state (atom nil))
@ -317,11 +319,11 @@ Everything after that is bound to *command-line-args*."))
'clojure.pprint pprint-namespace
'babashka.curl curl-namespace
'cognitect.transit transit-namespace
'bencode.core bencode-namespace
'next.jdbc jdbc/njdbc-namespace
'next.jdbc.sql jdbc/next-sql-namespace}
'bencode.core bencode-namespace}
features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))))
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))
features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace)
'next.jdbc.sql @(resolve 'babashka.impl.jdbc/next-sql-namespace))))
(def bindings
{'java.lang.System/exit exit ;; override exit, so we have more control

View file

@ -17,7 +17,8 @@
(while
(not
(try (jdbc/execute! db ["select version()"])
(catch Exception _
(catch Exception e
(prn (ex-message e))
(Thread/sleep 100))))))
(deftest create-table-test