From f06a749249daf1d7d0c200ccb75c72fa303b89d8 Mon Sep 17 00:00:00 2001 From: Nik Date: Sun, 28 Nov 2021 16:34:54 +0800 Subject: [PATCH] Add support for SQLite via a BABASHKA_FEATURE_SQLITE feature flag (#1079) * implement native sqlite support as a feature flag following [1] ([1] is mentioned as a checklist of sorts as to how to add a new feature flag in [2]) [1] https://github.com/babashka/babashka/commit/13f65f05aeff891678e88965d9fbd146bfa87f4e [2] https://github.com/babashka/babashka/blob/master/doc/build.md * bump to latest sqlite-jdbc, remove some no longer needed config+libs based on feedback from borkdude here [1], bump xerial/sqlite-jdbc 3.36.0.3, which includes the graalvm classes and resource config previously implemented via ericdallo/sqlite-jni-graal-fix and a `-H` flag in `script/compile` [1]: https://github.com/babashka/babashka/pull/1079#issuecomment-980533178 --- doc/build.md | 1 + project.clj | 1 + script/uberjar | 7 +++++++ script/uberjar.bat | 6 ++++++ src/babashka/impl/features.clj | 1 + src/babashka/main.clj | 1 + 6 files changed, 17 insertions(+) diff --git a/doc/build.md b/doc/build.md index 4fe43140..a5f83235 100644 --- a/doc/build.md +++ b/doc/build.md @@ -107,6 +107,7 @@ Babashka supports the following feature flags: | `BABASHKA_FEATURE_TEST_CHECK` | Includes the [clojure.test.check](https://github.com/clojure/test.check) library | `true` | | `BABASHKA_FEATURE_SPEC_ALPHA` | Includes the [clojure.spec.alpha](https://github.com/clojure/spec.alpha) library (WIP) | `false` | | `BABASHKA_FEATURE_JDBC` | Includes the [next.jdbc](https://github.com/seancorfield/next-jdbc) library | `false` | +| `BABASHKA_FEATURE_SQLITE` | Includes the [sqlite-jdbc](https://github.com/xerial/sqlite-jdbc) library | `false` | | `BABASHKA_FEATURE_POSTGRESQL` | Includes the [PostgresSQL](https://jdbc.postgresql.org/) JDBC driver | `false` | | `BABASHKA_FEATURE_HSQLDB` | Includes the [HSQLDB](http://www.hsqldb.org/) JDBC driver | `false` | | `BABASHKA_FEATURE_ORACLEDB` | Includes the [Oracle](https://www.oracle.com/database/technologies/appdev/jdbc.html) JDBC driver | `false` | diff --git a/project.clj b/project.clj index 9e4c4fee..565462c9 100644 --- a/project.clj +++ b/project.clj @@ -33,6 +33,7 @@ :dependencies [[clj-commons/clj-yaml "0.7.107"]]} :feature/jdbc {:source-paths ["feature-jdbc"] :dependencies [[seancorfield/next.jdbc "1.1.610"]]} + :feature/sqlite [:feature/jdbc {:dependencies [[org.xerial/sqlite-jdbc "3.36.0.3"]]}] :feature/postgresql [:feature/jdbc {:dependencies [[org.postgresql/postgresql "42.2.18"]]}] ;:feature/oracledb [:feature/jdbc {:dependencies [[com.oracle.database.jdbc/ojdbc8 "19.8.0.0"]]}] :feature/oracledb [:feature/jdbc {:dependencies [[io.helidon.integrations.db/ojdbc "2.1.0"]]}] ; ojdbc10 + GraalVM config, by Oracle diff --git a/script/uberjar b/script/uberjar index 6a318385..f595aef8 100755 --- a/script/uberjar +++ b/script/uberjar @@ -35,6 +35,13 @@ else BABASHKA_LEIN_PROFILES+=",-feature/jdbc" fi +if [ "$BABASHKA_FEATURE_SQLITE" = "true" ] +then + BABASHKA_LEIN_PROFILES+=",+feature/sqlite" +else + BABASHKA_LEIN_PROFILES+=",-feature/sqlite" +fi + if [ "$BABASHKA_FEATURE_POSTGRESQL" = "true" ] then BABASHKA_LEIN_PROFILES+=",+feature/postgresql" diff --git a/script/uberjar.bat b/script/uberjar.bat index 38ab72ff..b7bcd2d1 100755 --- a/script/uberjar.bat +++ b/script/uberjar.bat @@ -16,6 +16,12 @@ if "%BABASHKA_FEATURE_JDBC%"=="true" ( set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/jdbc ) +if "%BABASHKA_FEATURE_SQLITE%"=="true" ( + set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/sqlite +) else ( + set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,-feature/sqlite +) + if "%BABASHKA_FEATURE_POSTGRESQL%"=="true" ( set BABASHKA_LEIN_PROFILES=%BABASHKA_LEIN_PROFILES%,+feature/postgresql ) else ( diff --git a/src/babashka/impl/features.clj b/src/babashka/impl/features.clj index 96b59978..22c7a326 100644 --- a/src/babashka/impl/features.clj +++ b/src/babashka/impl/features.clj @@ -19,6 +19,7 @@ ;; excluded by default (def jdbc? (= "true" (System/getenv "BABASHKA_FEATURE_JDBC"))) +(def sqlite? (= "true" (System/getenv "BABASHKA_FEATURE_SQLITE"))) (def postgresql? (= "true" (System/getenv "BABASHKA_FEATURE_POSTGRESQL"))) (def oracledb? (= "true" (System/getenv "BABASHKA_FEATURE_ORACLEDB"))) (def hsqldb? (= "true" (System/getenv "BABASHKA_FEATURE_HSQLDB"))) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 71ccd55a..b947a50c 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -253,6 +253,7 @@ Use bb run --help to show this help output. features/xml? features/yaml? features/jdbc? + features/sqlite? features/postgresql? features/hsqldb? features/oracledb?