This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # aws (1)
- # beginners (60)
- # boot (12)
- # cider (7)
- # cljs-dev (8)
- # cljsrn (24)
- # clojure (169)
- # clojure-nl (1)
- # clojure-russia (3)
- # clojure-spec (15)
- # clojure-switzerland (1)
- # clojure-uk (24)
- # clojurescript (120)
- # core-async (9)
- # datomic (3)
- # emacs (2)
- # gsoc (3)
- # klipse (2)
- # leiningen (4)
- # numerical-computing (13)
- # off-topic (95)
- # om (7)
- # onyx (1)
- # powderkeg (2)
- # protorepl (2)
- # re-frame (6)
- # reagent (58)
- # ring-swagger (1)
- # rum (28)
- # untangled (42)
- # vim (6)
Getting a no suitable driver exception when using clojure.java.jdbc and I'm not sure why. I added the mysql maven dependency to my project structure via maven (using intelliJ + cursive). Do I need to do something with my project.clj for Lein?
mbcev the point here is that you can use your IDE to add deps - as long as deps your project defines are visible to clojure in the classpath at runtime
usually, I would use lein to declare deps, and I mostly use lein as a tool for setting my project classpath
but what really matters is the classpath the java process running clojure.jar sees
I understand the words that you're saying but I don't understand how to achieve what you're saying. I added
[org.clojure/java.jdbc "0.7.0-alpha3"] to my project.clj but that's just the wrapper for JDBC right? They're saying you also need the JDBC driver you intend to use but there isn't any instruction there regarding adding that to my classpath?
oh okay, so it should be the same as what I added via cursive via maven then I assume
no need to feel stupid - I don't know if I ever found that documented anywhere, I just figured it out trial and error based on other project.clj entries
there's probably a utility somewhere that takes a maven pom and outputs a vector for project.clj
that's a personal thing, but I like hugsql https://github.com/layerware/hugsql - get input from other people though since there's a big bit of opinion in that
@mbcev Just catching up on the JDBC discussion. Happy to field any further questions you have — I’m the maintainer of
We use MySQL very heavily at World Singles with
java.jdbc and the HoneySQL library. We like HoneySQL when we have complex queries that are built up programmatically — because we can build query fragments and then compose them together.
Thanks @seancorfield . I'm not sure if I have any obvious questions right now. Just kind of playing around right now I guess. Just trying to query my local db to see what makes sense I guess. I'm sure there are several great options but they're all the same to me since I haven't used any of them hah.
My impression is that Korma is no longer maintained (since you mentioned that) but some people still like its “ORM” style approach.
Okay wait, so Honey outputs vectors that I can pass into jdbc/query ? Am I understanding that correctly?
It builds data structures and then turns those into SQL and parameters in a vector.
So you can do stuff like this:
(jdbc/query (-> application :database :pooled-db) (-> (cond-> (-> (select :u.*) (cross-equivalence? site) (platinum?) (from [:user :u]) (with-primary-photo) (where [:in :u.id ids]) (order-by [(apply sql/call :field :u.id ids)])) (and self (site/has-covalence? site)) (with-covalence self)) (sql/format :quoting :mysql)))
platinum?is like this
(defn platinum? "Given a query map over user u, add in platinum, along with the left join on userGroup needed for that." [query] (-> query (merge-select [(sql/call :<> :ug.id nil) :platinum]) (merge-left-join [:userGroup :ug] [:and [:= :ug.userid :u.id] [:= :ug.groupid 2]])))
The nice thing is that each function can contribute parts to the select, the joins, the where clause etc.
(we have some really complex reporting queries that are built up from tables of metadata)
One of my colleagues gave a talk at Clojure/West 2015 about how we use HoneySQL https://www.youtube.com/watch?v=alkcjyhesjI
Right, right. Yeah I'm thinking I'm understanding how Honey works. What's tripping me up a little right now is http://clojure.github.io/java.jdbc/ functions but I'm assuming that this is just a wrapper for Java JDBC so I need to go look up something like http://docs.oracle.com/javase/tutorial/jdbc/basics/ to better understand how and when to use what?
java.jdbc library provides fairly straightforward functions to
update! rows, to run
[”some sql string” param1 param2] etc.
You’ll probably find the community docs for
java.jdbc will be helpful http://clojure-doc.org/articles/ecosystem/java_jdbc/home.html
Hopefully this example in the README will get you started with MySQL https://github.com/clojure/java.jdbc/#example-usage
No worries; I appreciate the help @seancorfield . I think I've got it from here. At least enough to get myself into trouble.
will I run into trouble using
(= "string" "string") over
(= 0 (compare "str" "str")) to evaluate two strings being equal like I would in Java?
I'm referring to how in pure Java the == operator on strings is comparing by object reference not object value like .equal or .compareTo would.
So to answer your original question - no, you won't get in trouble and you should use = in Clojure
I've got a function to move ants randomly in a grid and I iterate over all ants to move them using this function
When I iterate over them with the following functions, it works as expected and all ants walk randomly every loop iteration
(defn loop-ant [ant-ref] (move-ant! ant-ref (random-direction)))
But if I call it using a map function like in the following code, the ants do nothing and I cry internally
(defn loop-ants  (loop [ant (first ants) left-ants (rest ants)] (if (nil? ant) nil (do (loop-ant ant) (recur (first left-ants) (rest left-ants))))))
If I use
(defn loop-ants  (map loop-ant ants))
pmapinstead, only some of the ants move
Each grid cell (defining if an ant and what is present in that tile) and each ant struct are wrapped in
ref if that changes anything.
Anyone has an idea on what's going on?
you can use run! instead of map if you don't need the value from each loop-ant call
@noisesmith Omg I can't believe I didn't notice that. That's exactly what I needed, thank you!
also, if you need to do other collection operations for side effects, two common options are to wrap in
dorun (if you don't need the values) or
doall (if you need them but not right away) or to use
doseq (if you have a lazy operation to make the values, but want to operate on each one imperatively
It's funny... I used