This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-23
Channels
- # announcements (3)
- # babashka (68)
- # beginners (297)
- # calva (13)
- # cider (4)
- # clj-kondo (8)
- # cljs-dev (10)
- # cljsrn (26)
- # clojure (100)
- # clojure-europe (4)
- # clojure-germany (1)
- # clojure-italy (9)
- # clojure-nl (5)
- # clojure-spec (9)
- # clojure-uk (41)
- # clojurescript (69)
- # conjure (70)
- # cursive (44)
- # data-science (20)
- # datascript (2)
- # datomic (55)
- # emacs (1)
- # exercism (3)
- # graalvm (2)
- # kaocha (11)
- # leiningen (6)
- # meander (9)
- # mental-health (1)
- # off-topic (73)
- # pathom (6)
- # pedestal (1)
- # re-frame (3)
- # reagent (52)
- # reitit (8)
- # rum (39)
- # shadow-cljs (152)
- # spacemacs (10)
- # tools-deps (28)
- # xtdb (5)
Can we connect to database with babashka? To write scripts that involve db queries, mutations, transactions.
@ahmed1hsn not without shelling out, today. I do have an example where Iβm using SQLite by shelling out in the examples directory. I do want to see if we can bake some JDBC thing into bb later
Maybe one day babashka could use something like https://github.com/dscarpetti/codax π
@borkdude haven't checked in on babashka for a month or so, quite some impressive progress! kudos on the statically linked linux binary also. nice to be able to use it on alpine.

@tomisme well, that could be useful, but I'd like to see if I can get some JDBC like thing working as well: https://github.com/borkdude/babashka/issues/372
wow, it seems to work...
(def db
{:dbtype "postgres"
:dbname "medline"
:host "localhost"
:port 5555
:user "develop"
:password "develop"})
(require '[clojure.java.jdbc :as jdbc])
(jdbc/query db ["select count(*) from who_ictrp"])
$ ./bb /tmp/jdbc.clj
({:count 10})
surprise functionality is the best functionality
i was just going to ask about that, given next.jdbc
is the next defacto standard
Alright. It seems to work:
(def db
{:dbtype "postgres"
:dbname "medline"
:host "localhost"
:port 5555
:user "develop"
:password "develop"})
(require '[next.jdbc :as next])
(next/execute!
(next/get-datasource db)
["select title from who_ictrp limit 1"])
$ ./bb /tmp/jdbc.clj
[{:who_ictrp/title "6x3 Crossover, Bioavailability, Safety and Tolerability Among Different Eutropin Formulations in Healthy Volunteers"}]
if any of you would like to try this out, I now added most of the next.jdbc
namespace and binaries are posted here: https://clojurians.slack.com/archives/CSDUA8S6B/p1587645883001500
Works on osx and psql 11.3 for me. Excited to use this at work if it lands! Fwiw I paired this with https://github.com/cldwalker/clj-clis/blob/master/clj-table for a more psql feel:
$ ./bb tmp.clj | clj-table
| :Trial/name | :Trial/created_at |
|---------------------------+------------------------------|
| Gabriel Seeded Trial ID 1 | Sat Aug 21 00:17:18 PDT 2021 |
| Gabriel Seeded Trial ID 2 | Fri Nov 30 08:18:10 PST 2018 |
print-table looks simple enough to add to babashka. I made an issue for it: https://github.com/borkdude/babashka/issues/375
The reason not all of pprint is there right now, is that we chose fipp instead of normal clojure.pprint, because I could not get clojure.pprint to work with graalvm
i can try it out in a little bit, would remove a chunk of our db output-parsing π
I'm pretty excited about this, since we work with postgres at work too and this would allow inspecting the database in little scripts.. and spewing out some stats. less pgadmin, more clojure
β1 β (cd scripting && ./run.sh kube-ops.tools.counting)
[{:count 2693}]
works for me
@ddouglass Cool! Did you build it from source?
i did not, i downloaded the osx binary
from ci builds
oh heh, i opened the link but didn't join
Β―\(γ)/Β―
yeah it's going to be nice
technically our db code was only like 30 lines
but now it's down to 13 π
Hey! A question about equality. I want to check if an update is successful. The data sources are an api and a database query thru shell. The api sends things as an int. The database gives me the same id as a string. I convert the api response to a string. When I do (= string-from-number-api-source string-from-db-call)
I get false but the values are the same e.g (= "123" "123")
when I print them out. When I try it in the repl it works as expected, as well as when I do str/includes?
. When I try str/includes thought I get this even if I wrap them in a str
before I compare them:
@belea.simion sometimes there can be invisible control characters or whitespaces. Can you do (map int ...) over the id and then check if they are the same on both sides?
Now I get ClassCastException: ava.lang.String cannot be cast java.lang.Character
.
it says java.lang.String
for both
one looks like a proper hash, the other either a string or an empty string.
can you try to isolate this into some code that I can run myself? I don't know what I'm looking at anymore
what is the recommended way for reuse in babashka? i.e. sharing some common scripting functionalities across multiple scripts (that might live in totally different environments / setups). Would that be deps.clj + uberscript (to ensure that the target build is as small as possible)?
we use it for moitoring ES, et al. we use lein to create a classpath and set that on calls to bb with --classpath $(cat .bb-env)
build that into a docker image, put it up in kube, and voila
@stijn there is load-file
to load files from disk, babashka.curl
to fetch sources from the web, babashka.classpath
to add sources to the classpath dynamically so you can require
them. also you can use --uberscript
to assemble a single script. I don't have one standard way of doing things right now, it's just a matter of what works in your situation
and like Darin suggests, you can use lein
or clojure
to do dependency resolution. clojure
is especially nice since you can use git deps, so you can also put your scripts in a github repo without pushing them to clojars or something
deps.clj
is just a replacement for clojure
, it's nice to have, but functionally, it's identical
@pez I'm mostly using Cursive for clojure work, but it doesn't play well with the 'shell script' structure of a babashka script. So tried out Calva just today, and really impressed by how fast I was up to speed, nice work! :)
Calva also has too many ideas about a project structure, which get in the way for one-file scripting. Babashka sort of topple things and disturb circles. But that's fun. We'll be happy to play catch-up. π
~ clj -e '(re-find "abc" #"\p{C}" "")'
Execution error (ArityException) at user/eval1 (REPL:1).
Wrong number of args (3) passed to: clojure.core/re-find
Full report at:
/tmp/clojure-2536549118888962578.edn
aaaah forget it. my mistake.. i was running a very old version, whilst under assumptoin i had latest
Nice idea of @cldwalker to add clojure.pprint/print-table
to print query results:
(require '[next.jdbc :as jdbc]
'[clojure.pprint :refer [print-table]])
(defn query []
(let [db {:dbtype "postgres"
:dbname "medline"
:host "localhost"
:port 5555
:user "develop"
:password "develop"}]
(jdbc/execute!
(jdbc/get-datasource db)
["select main_id, published from who_ictrp limit 5"])))
(print-table (query))
$ ./bb /tmp/jdbc.clj
| :who_ictrp/main_id | :who_ictrp/published |
|--------------------+----------------------|
| NCT04085224 | 2019-09-10 |
| NCT04086225 | 2019-01-17 |
| NCT04084184 | 2019-03-15 |
| NCT04084197 | 2018-12-19 |
| NCT04085042 | 2020-06-01 |