Fork me on GitHub
#beginners
<
2019-08-29
>
Tuukka17:08:32

Hi all, I am Tuukka from Finland. Nice to meet you all! I have 2 weeks of experience with Clojure (total noob!) and was wondering good tools/frameworks for connecting Mysql database to Clojure. At the moment I am using jdbc for the connection. All tips and suggestions are appreciated. Thanks a lot for accepting me to this community! Ps. Apologies if I am posting question to wrong thread ๐Ÿ™‚

Quest17:08:30

JDBC is the standard. You might consider also using https://github.com/jkk/honeysql for nicer query-syntax, it's a pretty common lib.

(def sqlmap {:select [:a :b :c]
             :from [:foo]
             :where [:= :f.a "baz"]})

๐Ÿ‘ 4
Tuukka17:08:49

Thanks @U22M06EKZ, I'll look into this.

manutter5117:08:19

Or HugSQL, if youโ€™re already familiar/comfortable with SQL. https://www.hugsql.org/

๐Ÿ‘ 4
Tuukka17:08:07

Thanks @U06CM8C3V I'll check this out as well!

Quest17:08:39

If you're looking for "opinionated backend" frameworks & not just a SQL driver we can recommend something there, but it'll probably still use JDBC if talking to a SQL database ๐Ÿ™‚

โ˜๏ธ 4
Tuukka17:08:05

Yeah, maybe I'll just keep it simple and stick to JDBC.

noisesmith17:08:30

@info293 assuming you mean clojure.java.jdbc instead of using jdbc directly

๐Ÿ‘ 4
Tuukka17:08:22

Yeah, that is what I meant. Thanks for clarification. As said, total noob ๐Ÿ™‚

noisesmith17:08:21

yeah - wouldn't expect a newcomer to use jdbc directly by interop, but sometimes people are much more ambitious than they are curious so we do see things like this sometimes

Tuukka17:08:31

I'm just making simple queries to database at the moment. Trying to learn the basics.

Tuukka17:08:03

Have to say that I'm very impressed to get this many answers in such short time. Thank you for making me feel welcome right away. You rule!

4
seancorfield17:08:51

@info293 Welcome! clojure.java.jdbc is very stable and has been around for years but all future work has moved to https://github.com/seancorfield/next-jdbc in case you feel like using the "next generation" JDBC library. I think the documentation is better (even if I do say so myself!). I'll still support clojure.java.jdbc (and I regularly answers questions about it in #sql ) but I'm trying to encourage folks who are starting new projects to use next.jdbc instead.

๐Ÿ’ฏ 4
Tuukka17:08:36

Thank you@U04V70XH6, I'll take a look at this as well. Better documentation is certainly a big plus ๐Ÿ™‚

Leon20:08:35

im doing this

(defn stringify-map-keys [my-map]
  ((zipmap ((map name (keys my-map)) (vals my-map)))))

(deftest stringify-map-keys
  (is (=
       (stringify-map-keys {:a "hi"})
       {"a" "hi"})))
and im getting an ArityException, saying that i'm passing the wrong number of args (1) to stringify-map-keys.... am i just stupid atm or is this strange

andy.fingerhut20:08:59

deftest declares a function with the same name, and running the test calls it. Best not to use same name for deftest as an ordinary function. Common practice is to have test- as prefix of deftest name or -test as suffix.

Leon20:08:17

oh wow, okay, it's me thats stupid haha

Leon20:08:19

thanks a lot

noisesmith20:08:24

@lkowarschick there is another arity exception I'd assume you'd see after that, thanks to extra parens

andy.fingerhut20:08:46

not stupid at all. It is pretty subtle, and probably bites several people the first time they use deftest.

noisesmith20:08:49

I guess you'd get the "can't call a lazy-seq" error before that though, because of yet another set of extra parens

noisesmith20:08:30

@lkowarschick generally parens aren't "free" in clojure, and don't just do grouping (the exceptions to this are very rare)

Leon20:08:04

yea that extra parens are just bad copy pasting ;D

andy.fingerhut20:08:42

Or another way of phrasing it, unlike C/Java-like syntax languages, every set of parens has significance. There are no "redundant" ones you can add in without changing the meaning, whereas in C/Java-like languages, you can throw in extra parens in math expressions with no effect.

noisesmith20:08:21

@andy.fingerhut I really wanted to say it in that sweeping a way, but there's at least one exception where parens do just do grouping :D

andy.fingerhut20:08:53

I'm not thinking of it. What case are you thinking of?

noisesmith20:08:02

(case x 1 :one) (case x (1) :one) are identical in meaning

noisesmith20:08:13

I thought there was another one but I'm not remembering it off hand

andy.fingerhut20:08:27

Even there, it is because of case special handling of lists of constants. You can't add a second set of parens around that without changing the meaning.

noisesmith20:08:00

I guess inside ->, similarly, you get exactly one free set of optional parens on each subform after the first

noisesmith20:08:06

(as long as it has no args)

andy.fingerhut20:08:23

C/Java/etc (((((5))))) means exactly the same thing as 5 in arithmetic expressions.

noisesmith20:08:51

right, there's nothing in clojure that allows nested free parens, just individual contexts where one set of parens can be skipped optionally

sova-soars-the-sora21:08:18

how would you pick 4 random entries of a set that had 9 things?

sova-soars-the-sora21:08:26

4 random entries from a set that has 5 or more things, how about.

noisesmith21:08:30

(take 4 (shuffle s))

sova-soars-the-sora21:08:39

hot peppers

๐Ÿ˜‚ 4
noisesmith21:08:50

that's if you don't want duplicates of course :D

noisesmith21:08:44

right - but for some algorithms you want N fair choices from a set, even if you get one item twice

noisesmith22:08:19

for that you want (repeatedly 4 #(rand-nth (seq s)))

noisesmith22:08:50

one of the rare cases you need to call seq explicitly and it's not for nil checking

sova-soars-the-sora22:08:22

in this circumstance i strongly want to avoid duplicates

sova-soars-the-sora22:08:24

thank you ๐Ÿ™‚

Alex Miller (Clojure team)22:08:12

math.combinatorics has good (lazy!) answers for these kinds of things