Fork me on GitHub
#babashka
<
2020-11-10
>
holyjak15:11:02

Hello! I see bb supports some JDBC drivers. How difficult is it / what does it take to add another one? In particular, I would like to talk to Oracle. (Yes, I know. Sorry, I am forced to do that 😉.)

borkdude15:11:13

@holyjak Driver support depends on how well it compiles with GraalVM. Since both Oracle DB and GraalVM are from Oracle, one would expect it to work maybe? ;)

borkdude15:11:17

@holyjak There are a bunch of feature flags here: https://github.com/borkdude/babashka/blob/master/doc/build.md#feature-flags One for postgres for example. You would need to make a PR for the Oracle driver that implements such a feature flag.

borkdude15:11:25

I vaguely remember that @mbjarland also had interest in doing something with Oracle, but I could be mixing stuff up

holyjak15:11:45

1. How do I test that the oracle driver compiles? 2. I would be happy to send a PR if I get it working. But I suspect oracle jdbc cannot be redistributed so the user would need to supply it herself?

borkdude15:11:10

1. Look for existing examples. Quarkus is a Java framework for GraalVM which has lots of plugins, I see they also have Oracle support (https://blogs.oracle.com/developers/configuring-the-oracle-jdbc-drivers-with-quarkus) 2) Yes

holyjak15:11:50

thanks a lot! Will have a look.

holyjak16:11:47

Awesome, thanks a lot! BTW do you recommend going the feature flag way or making a pod? I'm not up to speed..

borkdude16:11:46

Making a feature flag might be easier to find out if it's going to work. If it works, with this knowledge you could proceed to make a pod.

👍 1
borkdude16:11:27

Making a pod is an extra level of complexity, so for proof of concept feature flag is better

mbjarland19:11:54

And you are right @U04V15CAJ i did start looking into this, I'll dig tomorrow and see where I left it. Seem to remember there being some trickery involved with classloading and next-jdbc...or something, I'll see if I can dig it up

mbjarland10:11:11

so back when I looked into this I was trying to make a standalone script to be run with a custom compiled babashka which included next.jdbc and which dynamically loaded the oracle jar

mbjarland10:11:21

how far I got:

#!/usr/bin/env bb

; when in a babashka execution context, add extra jars to the classpath.
(ns scripts.babashka-classpath
  (:import [ File]))
(when-let [bb-ns (find-ns 'babashka.classpath)]
  (let [shared (str (.getParentFile (File. ^String *file*)) "/shared")
        acp-fn (ns-resolve bb-ns (symbol "add-classpath"))
        add-cp (fn [& r]
                 (let [path (clojure.string/join "/" r)]
                   (println "adding" path)
                   (acp-fn path)))]
    (add-cp shared "ojdbc6_g.jar")))

(ns scripts.jdbc-test
  (:require [next.jdbc :as jdbc])
  (:import [java.sql.Connection]))

(println "loading class")
(println "class:" (Class/forName "oracle.jdbc.driver.OracleDriver"))
(println "class loaded")

(def url "jdbc:oracle:thin:@172.20.0.80:1521:orcl")

(let [ds (jdbc/get-datasource {:jdbcUrl url :user "password" :password "password"})]
  (with-open [^java.sql.Connection c (jdbc/get-connection ds)]

mbjarland10:11:59

and:

─➤ ./bb jdbc-test.clj
adding <elided for brevity>/babashka/matias/shared/ojdbc6_g.jar
loading class
class: oracle.jdbc.driver.OracleDriver
class loaded
clojure.lang.ExceptionInfo: IO Error: Message file 'oracle.net.mesg.Message' is missing. [at /home/mbjarland/projects/clojure/babashka/matias/jdbc-test.clj, line 27, column 38]

mbjarland10:11:14

so not that far, let me know if you end up solving this

borkdude10:11:59

Ah I see, you tried to run the Oracle driver from babashka source. Unfortunately that won't work. You will have to add it via a feature flag, like the postgres driver. You cannot load classes at runtime in babashka / graal

nate16:11:55

might be in the TL;DR realm at this point

nate16:11:57

a suggestion: make the repo README mostly about how to develop and contribute to babashka, and move all the (very rich) documentation somewhere else

nate16:11:39

perhaps articles so they show up in https://cljdoc.org/d/borkdude/babashka/0.2.3/ and that can be the doc site?

borkdude16:11:49

do you mean split up by topic and move to their own page?

borkdude16:11:18

I'm partial to using cljdoc for primary docs since they don't have a good way to change docs after release

nate16:11:42

yeah, if you split them up into separate pages by topic

nate16:11:55

then the left column on cljdoc is like a table of contents for all doc

borkdude16:11:28

ironically I already split the REPL docs up into its own page. Maybe that was the reason he couldn;'t find it ;)

nate16:11:39

I like cljdoc too, because then the docs are versioned with the releases

holmdunc19:11:37

I've seen long READMEs on github that simply put a table-of-contents at the top that links to the markdown headers, and it helps a lot

👍 3
sogaiu04:11:13

it would be nice to have auto toc - fwiw, i thought i heard that asciidoc has some kind of toc support