Fork me on GitHub
#babashka
<
2021-01-27
>
borkdude10:01:10

https://graalworkshop.github.io/2021/ ^ babashka talk at this conference

👍 12
Marco Pas11:01:27

I came across https://practicalli.github.io/clojure/clojure-tools/data-browsers/ using data browsers inside a clojure project. I was wondering if this also would be possible when using BB?

borkdude12:01:46

@marco.pasopas Try portal:

(require '[babashka.deps :as deps])

(deps/add-deps '{:deps {djblue/portal {:mvn/version "0.9.0"}}})

(require '[portal.api :as p])

(.addShutdownHook (Runtime/getRuntime)
                  (Thread. (fn [] (p/close))))


(p/open)
(p/tap)

(tap> [1 2 3])

@(promise)

borkdude12:01:18

The (tap> [1 2 3]) call is where you send data to portal and it will display it

borkdude12:01:01

@djblue Is the shutdown hook still needed or is this included by portal itself now? ^

djblue16:01:31

Not if you call portal.main 😄

borkdude16:01:42

it seemed portal shut down correctly when I pressed ctrl-c in the above snippet

borkdude16:01:52

oh yeah, I get your point now

💯 4
borkdude12:01:30

You can also do this "one-liner" to view e.g. an EDN file:

$ cat deps.edn | bb -e "(babashka.deps/add-deps '{:deps {djblue/portal {:mvn/version \"0.9.0\"}}})" \
                    -e "(require 'portal.main)" \
                    -e "(portal.main/-main \"edn\")" 

jaide18:01:14

Awesome! Testing it now with my cgi script

jaide18:01:38

… and it worked! 🚀

🎉 6
jaide18:01:55

Out of curiosity would it have been possible to uberjar the jdbc + postgresql driver? When should a pod be chosen over creating an uberjar?

borkdude18:01:46

@jayzawrotny babashka doesn't run a JVM so just a postgres driver doesn't work.

jaide18:01:57

I see so the pod is a specific package written for babashka where as an uberjar is suited for cross-platform or already babashka friendly code?

borkdude18:01:36

a pod can be written in any language, as long as it offers the API in a certain format. a pod is basically another CLI that acts as a service

borkdude18:01:53

Messages go back and forth in EDN, JSON or transit. So all the function args you use have to be either pure data, or there has to be some magic to represent objects as data. E.g. we represent db connections or transactions by an id that is sent back and forth.

👍 6
jaide18:01:21

Ahh good to know, and sounds like a pretty powerful\flexible system.

6