This commit is contained in:
Michiel Borkent 2020-05-08 22:16:05 +02:00
parent 50c32d521c
commit c78d873264
10 changed files with 8 additions and 207 deletions

View file

@ -30,11 +30,8 @@ _below_ in Polish and Russian. In Romanian it means _bridge_
### Examples
Eductional examples of pods can be found [here](../examples/pods):
- [pod-babashka-hsqldb](../examples/pods/pod-babashka-hsqldb): a pod that allows
you to create and fire queries at a [HSQLDB](http://www.hsqldb.org/)
database. Implemented in Clojure.
Beyond the already available pods mentioned above, eductional examples of pods
can be found [here](../examples/pods):
- [pod-lispyclouds-sqlite](../examples/pods/pod-lispyclouds-sqlite): a pod that
allows you to create and fire queries at a [sqlite](https://www.sqlite.org/)

View file

@ -16,11 +16,14 @@
(ns hsqldb-unused-vars
(:require
[babashka.pods :as pods]
[clojure.edn :as edn]
[clojure.java.shell :refer [sh]]
[clojure.pprint :refer [print-table]]
[next.jdbc :as jdbc]
[next.jdbc.sql :as sql]))
[clojure.pprint :refer [print-table]]))
(pods/load-pod "pod-babashka-hsqldb")
(require '[pod.babashka.hsqldb :as jdbc]
'[pod.babashka.hsqldb.sql :as sql])
(def db "jdbc:hsqldb:mem:testdb;sql.syntax_mys=true")

View file

@ -1,20 +0,0 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
/bb
.clj-kondo/.cache
!java/src/babashka/impl/LockFix.class
!test-resources/babashka/src_for_classpath_test/foo.jar
!test-resources/pom.xml
.cpcache
!reflection.json
hsqldb-babashka-plugin

View file

@ -1,13 +0,0 @@
# pod-babashka-hsqldb
## Compile
Run `./compile`
## Run
``` clojure
(babashka.pods/load-pod "./pod-babashka-hsqldb")
(pod.babashka.hsqldb/execute! "jdbc:hsqldb:mem:testdb;sql.syntax_mys=true" ["create table foo ( foo int );"])'
;;=> [#:next.jdbc{:update-count 0}]
```

View file

@ -1,33 +0,0 @@
#!/usr/bin/env bash
set -xeo pipefail
if [ -z "$GRAALVM_HOME" ]; then
echo "Please set GRAALVM_HOME"
exit 1
fi
"$GRAALVM_HOME/bin/gu" install native-image || true
export PATH=$GRAALVM_HOME/bin:$PATH
JAR=target/pod-babashka-hsqldb-0.0.1-SNAPSHOT-standalone.jar
lein do clean, uberjar
$GRAALVM_HOME/bin/native-image \
-jar $JAR \
-H:Name=pod-babashka-hsqldb \
-H:+ReportExceptionStackTraces \
-J-Dclojure.spec.skip-macros=true \
-J-Dclojure.compiler.direct-linking=true \
"-H:IncludeResources=SCI_VERSION" \
-H:ReflectionConfigurationFiles=reflection.json \
--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder \
--initialize-at-build-time \
-H:Log=registerResource: \
--verbose \
--no-fallback \
--no-server \
--report-unsupported-elements-at-runtime \
"-H:IncludeResources=org/hsqldb/.*\.properties" "-H:IncludeResources=org/hsqldb/.*\.sql" \
"-J-Xmx4500m"

View file

@ -1,22 +0,0 @@
(defproject org.babashka/pod-babashka-hsqldb "0.0.1-SNAPSHOT"
:description "babashka"
:url "https://github.com/borkdude/babashka"
:scm {:name "git"
:url "https://github.com/borkdude/babashka"}
:license {:name "Eclipse Public License 1.0"
:url "http://opensource.org/licenses/eclipse-1.0.php"}
:source-paths ["src"]
:resource-paths ["resources"]
:dependencies [[org.clojure/clojure "1.10.2-alpha1"]
[org.hsqldb/hsqldb "2.4.0"]
[seancorfield/next.jdbc "1.0.424"]
[nrepl/bencode "1.1.0"]]
:profiles {:uberjar {:global-vars {*assert* false}
:jvm-opts ["-Dclojure.compiler.direct-linking=true"
"-Dclojure.spec.skip-macros=true"]
:aot :all
:main pod.babashka.hsqldb}}
:deploy-repositories [["clojars" {:url "https://clojars.org/repo"
:username :env/clojars_user
:password :env/clojars_pass
:sign-releases false}]])

View file

@ -1,15 +0,0 @@
[ {
"name" : "org.hsqldb.jdbcDriver"
},
{
"methods" : [{"name":"<init>", "parameterTypes":[ "org.hsqldb.Database"]} ],
"name" : "org.hsqldb.dbinfo.DatabaseInformationFull"
},
{
"methods" : [ {
"name" : "getBundle",
"parameterTypes" : [ "java.lang.String", "java.util.Locale", "java.lang.ClassLoader" ]
} ],
"name" : "java.util.ResourceBundle"
}
]

View file

@ -1,51 +0,0 @@
(ns pod.babashka.hsqldb
(:refer-clojure :exclude [read read-string])
(:require [bencode.core :as bencode]
[clojure.edn :as edn]
[next.jdbc :as jdbc])
(:import [java.io PushbackInputStream])
(:gen-class))
(def stdin (PushbackInputStream. System/in))
(def lookup
{'pod.babashka.hsqldb/execute! jdbc/execute!})
(defn write [v]
(bencode/write-bencode System/out v)
(.flush System/out))
(defn read-string [^"[B" v]
(String. v))
(defn read []
(bencode/read-bencode stdin))
(defn -main [& _args]
(loop []
(let [message (try (read)
(catch java.io.EOFException _
::EOF))]
(when-not (identical? ::EOF message)
(let [op (get message "op")
op (read-string op)
op (keyword op)]
(case op
:describe (do (write {"format" "edn"
"namespaces" [{"name" "pod.babashka.hsqldb"
"vars" [{"name" "execute!"}]}]
"ops" {"shutdown" {}}})
(recur))
:invoke (let [var (-> (get message "var")
read-string
symbol)
id (-> (get message "id")
read-string)
args (get message "args")
args (read-string args)
args (edn/read-string args)]
(write {"value" (pr-str (apply (lookup var) args))
"id" id
"status" ["done"]})
(recur))
:shutdown (System/exit 0)))))))

View file

@ -1,45 +0,0 @@
(ns test
(:refer-clojure :exclude [read])
(:require [bencode.core :as bencode]
[clojure.edn :as edn])
#_(:import java.lang.ProcessBuilder$Redirect))
(defn write [stream v]
(bencode/write-bencode stream v)
(.flush stream))
(defn read [stream]
(bencode/read-bencode stream))
(defn bytes->string [^"[B" bytes]
(String. bytes))
(defn query [stream q]
(write stream {"op" "invoke"
"id" "1"
"var" "pod.babashka.hsqldb/execute!"
"args" (pr-str ["jdbc:hsqldb:mem:testdb;sql.syntax_mys=true" q])}))
(let [pb (ProcessBuilder. #_["lein" "run" "-m" "pod.babashka.hsqldb"]
["./pod-babashka-hsqldb"])
_ (.redirectErrorStream pb true)
;; _ (.redirectOutput pb ProcessBuilder$Redirect/INHERIT)
p (.start pb)
stdin (.getOutputStream p)
stdout (.getInputStream p)
stdout (java.io.PushbackInputStream. stdout)]
(write stdin {"op" "describe"})
(let [reply (read stdout)]
(println "format:" (String. (get reply "format")))) ;;=> edn
(query stdin ["create table foo ( foo int );"])
(let [reply (read stdout)]
(println "reply:" (edn/read-string (String. (get reply "value"))))) ;;=> [{:next.jdbc/update-count 0}]
(query stdin ["insert into foo values ( 1, 2, 3);"])
(let [reply (read stdout)]
(println "reply:" (edn/read-string (String. (get reply "value"))))) ;;=> [{:next.jdbc/update-count 3}]
(query stdin ["select * from foo;"])
(let [reply (read stdout)]
(println "reply:" (edn/read-string (String. (get reply "value")))))) ;=> [{:FOO/FOO 1} {:FOO/FOO 2} {:FOO/FOO 3}]