Fork me on GitHub
#babashka
<
2023-07-19
>
Matthew Twomey02:07:49

I’m having trouble getting the mysql pod up and running:

#!/usr/bin/env bb

(ns user-lists)

(load-file (str (System/getProperty "user.home") "/.babashka/bb.clj"))

(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/mysql "0.1.2")
(require '[pod.babashka.mysql :as mysql])

(def db {:dbtype   "mysql"
         :host     "127.0.0.1"
         :dbname   "pearpop_dev"
         :user     "admin"
         :password "XXXXXXX"
         :port     3401})

(mysql/execute! db "select name from users")
This produces clojure.lang.ExceptionInfo: java.lang.Character cannot be cast to java.lang.String

2
seancorfield02:07:50

Wrap the SQL in a vector

seancorfield02:07:31

The error suggests a string has had a sequence function called on it (String -> Character) and then that first character is used where a string is expected.

Matthew Twomey03:07:29

Oh! Thank you. Wrapping it in a vector fixes it!

Matthew Twomey03:07:26

Oh :man-facepalming: all the examples have it wrapped in a vector too. I was somehow blind to that.

seancorfield03:07:33

It's a common mistake, when there are no parameters, to try to just use a string... That's why I recognized the exception.

mmer08:07:52

Has anyone used babashka to drive openshift?

nitin08:07:44

I'm trying https://github.com/charmbracelet/gum with a https://github.com/lispyclouds/bblgum made by @rahul080327, I've just started playing with it, and filter command seems to work only with input streams, but it should work with lists too as described. ==Clojure== ;; Works (gum :choose ["Apple" "Banana" "Orange"]) ;; Doesn't Works (gum :filter ["Apple" "Banana" "Orange"]) My question is, is gum filter intended to work with only input streams? What if, I made long list of options from some nested data, I can't use gum filter directly on it, I have to spit it in a file first? Before posting it here I tried gum filter on terminal too, and it didn't worked same as gum choose, which made me think, this isn't issue about wrapper, its either intended to work with inputs or I am making some mistake somewhere. ==Terminal== ;; Works gum choose Apple Banana Orange ;; Doesn't Works gum filter Apple Banana Orange Does anyone have any idea about this? SOLVED by @borkdude@rahul080327 As per https://github.com/charmbracelet/gum/blob/d1ad453ce61aeb1181e5cf86ceb28c888ab92ff2/filter/command.go#L36, it takes only input via input stream, and the wrapper has`:in` option to pass desired input. Hence, the only way to pass some data (other than input stream or file) to gum filter in clojure (for now) is to pass data as string list: (gum :filter :in (str/join "\n" data))

4
borkdude08:07:13

Some commands work via stdin:

echo 'Apple\nBanana\nOrange' | gum filter

nitin08:07:21

How can I input some sequence to gum filter in babashka? Do I have to spit it in a file first?

borkdude08:07:09

@rahul080327 You didn't answer his question though ;)

lispyclouds08:07:33

Yeah looking for the option on the phone is harder 😆

borkdude08:07:59

The README has:

(b/gum :filter :in ( "flavours.txt"))

borkdude09:07:24

I think you can put a (.StringReader. "foo\nbar\nbaz") in there

lispyclouds09:07:40

I’m looking for a way to make a string an input stream. Join the seq with new lines and then send it

nitin09:07:07

I have seen the go source but didn't get much, as per source, choose too reads via stdin, but it has a check that if options passed are 0, does that makes filter to think inputs passed as options? https://github.com/charmbracelet/gum/blob/d1ad453ce61aeb1181e5cf86ceb28c888ab92ff2/choose/command.go#L31C8-L31C8

lispyclouds09:07:39

If there’s no stdin, it filters the files in the current directory

borkdude09:07:41

This worked for me:

bb -cp src -e "(require '[bblgum.core :as b])" -e "(b/gum :filter :in (java.io.StringReader. \"foo\nbar\nbaz\"))"

borkdude09:07:11

Perhaps just passing a string to have the same behavior could be nice

borkdude09:07:16

babashka.process works the same way

borkdude09:07:31

oh that already works, since it's built on bb process ;)

borkdude09:07:42

so just:

(b/gum :filter :in "foo\nbar\nbaz")

4
lispyclouds09:07:48

Can use (str/join \newline your-seq) to make the string

borkdude09:07:14

I think adding this example to the README would be nice

borkdude09:07:26

rather than the file

lispyclouds09:07:49

Can do it as soon as I have access to a machine and PR welcome!

nitin09:07:05

Yes I just tried that it works, adding it to README will be nice.

nitin09:07:37

I tried joining sequence with newline, but didn't give :in with it :man-facepalming::skin-tone-3: because I thought this isn't input stream.

lispyclouds09:07:47

The examples in my README is pretty much a verbatim translation of the gum examples

nitin09:07:12

But with filter it seems :in is necessary always, I was playing, trying without :in supplying it a sequence, a string with newlines etc. and it wasn't working, but it seems filter works with :in only as it takes input stream only as its input.

borkdude09:07:06

or a string

lispyclouds09:07:23

Filter is designed in the same spirit as grep, compose on the command line

borkdude09:07:23

basically everything that babashka.process supports for :in

nitin09:07:14

No not a string, if string was supported it should work (gum :filter "foo\nbar\nbaz") but needs :in always which takes string via input option. Avoiding confusion 😅

lispyclouds09:07:24

What we mean is a string also supported for :in and not just input streams.