Fork me on GitHub

hi - i have a honeysql question (there doesn’t appear to be a room for it - if there’s a better room for this question, please let me know). I’m trying to slowly build a query, and using merge-where, but i’m not sure i’m using it right. it recursively nests the where clauses, where i’d rather see them all ANDed together at the “root” of the query, so to speak - is there something I’m missing?

user=> (require '[honeysql.core :as sql])
user=> (require '[honeysql.helpers :as h])
user=> (def query {:select [:*] :from [:mytable]})
user=> (def w1 (h/merge-where query [:= :a 1]))
user=> (def w2 (h/merge-where w1 [:= :b 2]))
user=> (def w3 (h/merge-where w2 [:= :c 3]))
user=> w3
{:select [:*], :from [:mytable], :where [:and [:and [:= :a 1] [:= :b 2]] [:= :c 3]]}
user=> (sql/format w3)
["SELECT * FROM mytable WHERE ((a = 1 AND b = 2) AND c = 3)”]


I know that logically, it doesn’t make any difference, but as I build more complex thing, I’m a little nervous of some little subtle thing I miss, and a simpler query would make more sense to me - thanks in advance for any advice!


where will combine multiple clauses together using and:

(-> (select :*)
    (from :foo)
    (where [:= :a 1] [:< :b 100])
=> ["SELECT * FROM foo WHERE (a = 1 AND b < 100)”]


Hope this is what you are looking for.


hey thanks - yeah, i got that far, i’m trying to pass the query map around among a bunch of functions, adding on clauses as i go (“is there a :b param? add that to the query - is there a :c param? add that to the query” - etc


so i thought in each function, i could add another clauses to the :where in the map, and they would all be ANDed together at the end


so maybe i should just build up a list of clauses as i go, and add it to the query map at the end?


hi everyone! what kind of path i need to set up for hiccup image? relative or absolute or else? [:img {:style "width:1366px;height:180px;", :alt "myImg", :src "/resources/public/img/image.png"}]


I'm trying to find documentation on this bit of code ['in [1 2 3 4]] .. The 'in. I'm not sure what this is called nor what it does. Any links/suggestions?


byronwoodfork: ' is quote.


(quote e) is actually a compiler special form which yields e unevaluated.


So normally if you write a symbol, such as in, it's evaluated which means that you don't get in back, you get the value bound to in.


But if you quote in, you get the symbol in back. (eval (quote e)) <=> e


does that make sense?


It does. Reading through the documentation and playing with it in the repl now. Thanks! 😃


please show someone how to define hiccup image element


@agi_underground: I would start with an absolute path to be sure it works and experiment from there, other than that relative or absolute is your preference (exactly the same as if you were writing html). Also hiccup tests are always a nice reference when in doubt (or your REPL also) .