Re: Adding value to the map in sql statement dynamically

2020-12-20 Thread Erik Assum
Hi Ganesh, Please don’t do it this way, as you’re opening yourself to sql-injection. When doing parameterized queries in sql, please reach for prepared statements. As others have mentioned, next.jdbc with a sprinkle of honeysql on top should be exact what you’re looking for. Erik. -- i fa

Re: Adding value to the map in sql statement dynamically

2020-12-20 Thread Brandon R
Hey Ganesh, Just to add to the above information, you may want to check out next.jdbc as well. If you specifically want to create functions that return complete SQL, then maybe this isn't what you want, but I just wanted to point out parameterization in next.jdbc since you mentioned you're new to

Re: Adding value to the map in sql statement dynamically

2020-12-20 Thread alpeware llc
The most straight forward approach is to simply define a different function for each use case you have using the same approach. At some point you will have to decide which function to call with what input. In more general terms, you want to think about taking an input (a map), applying some trans

Re: Adding value to the map in sql statement dynamically

2020-12-20 Thread Ganesh Neelekani
Hello Alpaware, Thanks for the reply, In the above, I just gave an example, Bt this will be dynamic, Any number of keys can come, How to segregate and assigned to particular variable? Thanking you. -- With regards. Ganesh N Neel

Re: Adding value to the map in sql statement dynamically

2020-12-20 Thread alpeware llc
Welcome to Clojure! You could just define a function taking a map as an argument and return the query as a string using destructering [0] (defn people [{:keys [table person id]}] (str "SELECT * FROM " table " WHERE person_id = " person " ORDER BY " id)) You may want to have a look at Sean Corn

Adding value to the map in sql statement dynamically

2020-12-20 Thread Ganesh Neelekani
Hello Team, I am new to clojure and I wanted to write a function where input from map keys are passed as parameter as input to the sql query. (def query-body1 " select first_name, last_name from ${table_name} where person_id=${person_id} order by ${id} ") (def query-body2 " select first_nam

Re: map-in

2015-03-24 Thread Francis Avila
The reduce in your mapped function is already implemented by get-in. Other possible implementations using get-in: (defn map-in [coll ks f & args] (->> coll (map #(get-in % ks)) (map #(apply f % args Or: (defn map-in [coll ks f & args] (map #(apply f (get

map-in

2015-03-24 Thread Steve Ashton
Is there anything for map which operates like update-in and assoc-in, where we can call a function with the value looked up in a nested structure? What I've come up with: (defn map-in "Returns a lazy sequence consisting of the results of calling map on coll, for each value i

Re: map> vs map< in core.async

2013-12-16 Thread Joachim De Beule
Thanks, that's very helpful! -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe fr

Re: map> vs map< in core.async

2013-12-13 Thread Walter van der Laan
Please try these exercises if you want to know what a channel is: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj Op vrijdag 13 december 2013 11:01:57 UTC+1 schreef Joachim De Beule: > > Thanks, that indeed did the trick. > > More genera

Re: map> vs map< in core.async

2013-12-13 Thread Joachim De Beule
Thanks, that indeed did the trick. More generally it's not clear to me what makes a channel an "output channel" or an "input channel". Aren't all channels input and output channels depending on whether you read from or write to it? Op vrijdag 13 december 2013 04:28:53 UTC+1 schreef Carlo: >

Re: map> vs map< in core.async

2013-12-12 Thread Carlo Zancanaro
On Thu, Dec 12, 2013 at 06:08:11PM -0800, Joachim De Beule wrote: > I expected to see a sequence of the form "<><><>...". However, only one or > very few ">" get printed, so I get a sequence "<>>>...". Why? They're getting buffered. Try this: (as/pipe (as/map< (fn [x] (print "<") (flush) x) sou

map> vs map< in core.async

2013-12-12 Thread Joachim De Beule
Dear list, I'm playing around with core.async and I don't understand the following. 1) I make a "source" channel that emits a random number every second. (def continue (atom true)) (def source (let [out (as/chan)] (as/go-loop [] (when @continue (as/pu

Re: How to change map in doseq ?

2013-10-28 Thread Alan Forrester
On 28 October 2013 05:23, Jiaqi Liu wrote: >> 2013/10/28 Jiaqi Liu >>> >>> i really don't get it. >>> Any suggestion?? >> >> >> Clojure data structures are immutable. clojure.core/assoc >> produces a new data structure instead of changing the one you have. >> >> You can use an atom if you need t

Re: How to change map in doseq ?

2013-10-27 Thread Jiaqi Liu
Thanks for your suggests~ The above piece of code is just for test. The practical problem i want to solve is that -->read a very big log file (each line is like that : "user id, latitude, longitude, timeStamp") -->statistic the number of each user (store in a map like that { id1 100 , id2 200, id3

Re: How to change map in doseq ?

2013-10-27 Thread Michael Klishin
2013/10/28 Jiaqi Liu > i really don't get it. > Any suggestion?? > Clojure data structures are immutable. clojure.core/assoc produces a new data structure instead of changing the one you have. You can use an atom if you need to update a map from doseq but more likely you want to use the actual

How to change map in doseq ?

2013-10-27 Thread Jiaqi Liu
Hi , all I am new to Clojure. For now , i have a piece of code : (let [res {}] (doseq [id [111 222 333] num [2 3 4]] (assoc res id num)) (count res)) i want to get the res {111 2 , 222 3 , 333 4} and count 3 but the repl return me {} and 0 i r

Re: alter a map in a vector (reference)

2013-06-12 Thread Laurent PETIT
Hello, A note about the code organization : I think you should strive to separate the code that does side effects from the code that works on the datastructures. This means you could refactor your refactored version as such: => (def example (ref [{:id 1 :email {"a...@mail.com" 1}}

Re: alter a map in a vector (reference)

2013-06-11 Thread Kelker Ryan
Here's the refactored version.user> (def example (ref [{:id 1 :email {"a...@mail.com" 1}} {:id 2 :email {"d...@mail.com" 1}} {:id 3 :email {"g...@mail.com" 2}} {:id 4 :email {"f...@mail.com" 2}}])) #'user/example user> (defn

Re: alter a map in a vector (reference)

2013-06-11 Thread Meikel Brandmeyer (kotarak)
Hi, Am Mittwoch, 12. Juni 2013 06:39:59 UTC+2 schrieb Kelker Ryan: > > user> (defn update-counter [id xs] > > (let [at-after (drop-while #(not= id (:id %)) @xs) > to-modify (-> at-after first :email) > mod-key (-> to-modify keys first) > location (

Re: alter a map in a vector (reference)

2013-06-11 Thread Kelker Ryan
I've seen some interesting responses, but here's my solution. user> (def example (ref [{:id 1 :email {"a...@mail.com" 1}} {:id 2 :email {"d...@mail.com" 1}} {:id 3 :email {"g...@mail.com" 2}} {:id 4 :email {"f...@mail.com" 2}}])) #'user/example user>

Re: alter a map in a vector (reference)

2013-06-11 Thread Yoshinori Kohyama
Solutions seem to depend on whether you have two or more mail addresses in a ':emails' section or not. If you have, you should identify the mail address of which you want to increment the value. Anyway, try below: (dosync (alter result (fn [v] (mapv second (update-in (into {}

Re: alter a map in a vector (reference)

2013-06-03 Thread Alex Baranosky
You *can* update this inside the vector, but if you want to key by :id, I would personally recommend, you put the email data into a map and look it up by :id, like this: {1 {:id 1 :email {"a...@mail.com 1}} 2 {:id 2 :email {"d...@mail.com 1}} 3 {:id 3 :email {"g...@mail.com 2}}} Best, Alex O

Re: alter a map in a vector (reference)

2013-06-03 Thread Yinka Erinle
Thanks Meikel for the prompt reply, that does it. Please can you elaborate on how I can use the solution below to update a particular entry in the vector. [{:id 1 :email {"a...@mail.com 1}} {:id 2 :email {"d...@mail.com 1}} {:id 3 :email {"g...@mail.com 2}}] So I will like to write a functi

Re: alter a map in a vector (reference)

2013-06-03 Thread Meikel Brandmeyer (kotarak)
Hi, Am Montag, 3. Juni 2013 22:16:54 UTC+2 schrieb Yinka Erinle: > > Given I have the following > (def result (ref [ { :id 1 :emails { "yi...@mail.com " 1}} ] > ) ) > > I like to alter the result in a transaction to become > [{:id 1 :emails { "yi...@mail.com " 2}}]; increment the > counter

alter a map in a vector (reference)

2013-06-03 Thread Yinka Erinle
Hi, I struggling to find a way to alter a value in a map that resides in a vector. Given I have the following (def result (ref [ { :id 1 :emails { "yi...@mail.com" 1}} ] ) ) I like to alter the result in a transaction to become [{:id 1 :emails { "yi...@mail.com" 2}}]; increment the counter

Pulling "remaining keys" out of a map in core.logic

2013-01-04 Thread Conrad
HI, I'm looking for functionality like the "featurec" function, but I need to be able to capture the unused keys. Here is how "featurec" currently works: (run* [q] (== q {:a 1 :b 2}) (featurec q {:b 2}))) ==> ({:a 1 :b 2}) However, I need to capture the keys th

Re: mapv-in or map-in?

2012-10-05 Thread Gijs S.
Look at clojure.walk for mapping functions over nested structures: (defn mapv-in [f coll] (clojure.walk/prewalk #(if (coll? %) % (f %)) coll)) Clojure walk api: http://clojure.github.com/clojure/clojure.walk-api.html On Friday, October 5, 2012 7:58:30 AM UTC+2, nchurch wrote: > > I ended u

mapv-in or map-in?

2012-10-04 Thread nchurch
I ended up needing the following utility, modified from the Clojure source: (defn mapv-in "maps f over a nested vector structure" ([f coll] (let [f #(if (coll? %)(mapv-in f %)(f %))] (-> (reduce (fn [v o] (conj! v (f o))) (transient []) coll) persistent! I wrote just as

Re: reduce-kv doesn't reduce a sorted-map in order

2012-08-10 Thread Stuart Halloway
Confirmed -- thanks for the report. Stu > Hi, > > It seems reduce-kv doesn't reduce a sorted-map in the correct order. > > Example - > > user> (def *sm (into (sorted-map) {:aa 1 :zz 2 :bb 3 :yy 4 :cc 5 :xx 6})) > ;=> #'user/*sm > > user> *s

Re: reduce-kv doesn't reduce a sorted-map in order

2012-08-10 Thread Alex Baranosky
Sounds like a bug to me, in that it doesn't behave as I would expect. On Thu, Aug 9, 2012 at 7:29 PM, Baishampayan Ghose wrote: > Hi, > > It seems reduce-kv doesn't reduce a sorted-map in the correct order. > > Example - > > user> (def *sm (into (sorted-map) {:

reduce-kv doesn't reduce a sorted-map in order

2012-08-09 Thread Baishampayan Ghose
Hi, It seems reduce-kv doesn't reduce a sorted-map in the correct order. Example - user> (def *sm (into (sorted-map) {:aa 1 :zz 2 :bb 3 :yy 4 :cc 5 :xx 6})) ;=> #'user/*sm user> *sm ;=> {:aa 1, :bb 3, :cc 5, :xx 6, :yy 4, :zz 2} ;; plain reduce user> (reduce (fn [re

Re: Matching map in ArraySeq

2012-06-29 Thread Meikel Brandmeyer (kotarak)
Hi, (defn example [& args] (let [[opts args] (let [opts? (first args)] (if (map? opts?) [opts? (next args)] [nil args]))] (reduce str args))) Kind regards Meikel -- You received this message because you are subscribed

Re: Matching map in ArraySeq

2012-06-29 Thread Timothy Baldridge
> My question is: I would like to allow the first parameter to be an > (optional) map containing key values for the function.  What's a clean, > readable way to do that? How about this: (defn example [& args] (let [opts (when map? (first args)) args (when opts (next args))] (redu

Matching map in ArraySeq

2012-06-29 Thread Peter Ashford
I've just started playing with Clojure and I have a newbie question: I have an anonymous function that takes a variable number of parameters. I coded it so it takes a list of strings or functions that return strings and concatenates the resultant strings like so: (defn example [& args] (reduce

Re: ordered map in Clojure?

2011-07-02 Thread Tassilo Horn
Alan Malloy writes: Hi Alan, > If I were using this for some performance-critical task and never > disjoined, I'd use ninjudd's version. Otherwise I'd use mine, just > because it's easier to build and tweak since it's in clojure. I tried your implementation, and I couldn't see any relevant slow

Re: ordered map in Clojure?

2011-06-28 Thread Alan Malloy
Well, I wrote the clojure version after boasting to ninjudd that deftype would let you do it without writing any java at all. I did some simple-minded benchmarking, and while I don't recall the exact numbers his java version is ~10-50% faster. If you look through the git logs, somewhere I have a ve

Re: ordered map in Clojure?

2011-06-28 Thread Tassilo Horn
Alan Malloy writes: Hi Alan, > ArrayMap isn't very performant for large collections. You might like > https://github.com/flatland/ordered in my clojure app, I totally rely on ordered sets. Currently, I use https://github.com/ninjudd/ordered-set for which I've implemented transient support

Re: ordered map in Clojure?

2011-06-25 Thread Alan Malloy
Note that it's still pretty immature - I started writing it last weekend. It's tested fairly thoroughly, and I spent four or five days hunting down the best performance I could, so it should be perfectly usable. However, if you have any problems please let me know. Especially, if you plan to disso

Re: ordered map in Clojure?

2011-06-25 Thread Alan Malloy
array-map turns into a hashmap after ten insertions, currently, but that's far from guaranteed: user> (->> {} (iterate #(assoc % (rand-int 1e6) 1)) (drop-while (comp #{(class {})} class)) (first) (count)) 10 My ordered-set/map are now available on cloja

Re: ordered map in Clojure?

2011-06-25 Thread Alex Baranosky
I wonder at what point array-map becomes a hash-map? Maybe I could use it? On second thought, I don't really want to depend on something so flimsy. Alan, is your ordered map code available on clojars? Alex -- You received this message because you are subscribed to the Google Groups "Cloj

Re: ordered map in Clojure?

2011-06-25 Thread Ivan Koblik
ries from the map. > > Note that a map of refs doesn't cut it as a substitute for a > ConcurrentHashMap if keys will be added/removed by multiple threads, > and sticking the entire map in an atom doesn't if you want to support > more concurrency than a plain old Collection

Re: ordered map in Clojure?

2011-06-25 Thread Ken Wesson
t though by putting a WeakReference(val) in in a wrapper layer and using a ReferenceQueue and a thread that drains the queue every so often to prune dead Map.Entries from the map. Note that a map of refs doesn't cut it as a substitute for a ConcurrentHashMap if keys will be added/removed by mul

Re: ordered map in Clojure?

2011-06-25 Thread Laurent PETIT
Beware the devil hidden in the details: " Note that an array map will only maintain sort order when un-'modified'. Subsequent assoc-ing will eventually cause it to 'become' a hash-map. " 2011/6/25 Alex Baranosky : > Ha!  Perfect.  Thanks. > > On Sat, Jun 25, 2011 at 4:00 PM, James Estes wrote: >>

Re: ordered map in Clojure?

2011-06-25 Thread Alan Malloy
ArrayMap isn't very performant for large collections. You might like https://github.com/flatland/ordered On Jun 25, 1:11 pm, Alex Baranosky wrote: > Ha!  Perfect.  Thanks. > > > > > > > > On Sat, Jun 25, 2011 at 4:00 PM, James Estes wrote: > > ArrayMap? > >http://clojure.org/data_structures#toc2

Re: ordered map in Clojure?

2011-06-25 Thread Alex Baranosky
Ha! Perfect. Thanks. On Sat, Jun 25, 2011 at 4:00 PM, James Estes wrote: > ArrayMap? > http://clojure.org/data_structures#toc21 > > James > > > On Sat, Jun 25, 2011 at 1:55 PM, Alex Baranosky > wrote: > > What are some options for having a map that guarantees ordering of its > keys > > in Clo

Re: ordered map in Clojure?

2011-06-25 Thread James Estes
ArrayMap? http://clojure.org/data_structures#toc21 James On Sat, Jun 25, 2011 at 1:55 PM, Alex Baranosky wrote: > What are some options for having a map that guarantees ordering of its keys > in Clojure? (note: sorted-map won't do!)  My first try was to use > LinkedHashMap, but am running into

ordered map in Clojure?

2011-06-25 Thread Alex Baranosky
What are some options for having a map that guarantees ordering of its keys in Clojure? (note: sorted-map won't do!) My first try was to use LinkedHashMap, but am running into exceptions of the " java.util.LinkedHashMap cannot be cast to clojure.lang.Associative" variety. So then I tried to use e

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-05 Thread Rowdy Rednose
You're right, the scenario that I described doesn't need it. In my actual code I need it because the function actually reads #(conj (or % #{}) constraint#) If I don't do that, I get a list instead of a set. On Jul 5, 5:12 pm, Meikel Brandmeyer wrote: > Hi, > > Am 05.07.2009 um 07:27 schrieb Row

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-05 Thread Meikel Brandmeyer
Hi, Am 05.07.2009 um 07:27 schrieb Rowdy Rednose: user=> (dosync (alter gnu-rms update-in [:key1 :key2 :key3] #(conj % "foo"))) {:key1 {:key2 {:key3 #{"foo" You actually don't need the anonymous function... (dosync (alter gnu-rms update-in [:key1 :key2 :key3] conj "foo")) Sincerely M

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} I just found update-in, which is even better, as I want to update a set: user=> (def gnu-rms (ref {:key1 {:key2 {:key3 #{)) #'user/gnu-rms user=> (dosync

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:23 pm, Richard Newman wrote: > However, I'd point out that: > > * This might be a sign that you're doing things 'wrong'. Could be. I'm still figuring out how to do things the functional way. The reason I have these nested maps is to give my data structure. I don't want to have a loos

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Much better! Thanks. On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > You could use assoc-in... > > (def rms (ref {:key1 {:key2 {:key3 #{)) > > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} > > Rgds, Adrian. > > On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Re

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Richard Newman
Rowdy, > Do I really have to assoc all the way through to the inner map? Isn't > there a more succinct way to write this? In Common Lisp there's (setf > (getf ...)) Remember, Clojure's data structures are immutable. You're not adding a value to a set -- what you're describing is (in Clojure) a

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Adrian Cuthbertson
You could use assoc-in... (def rms (ref {:key1 {:key2 {:key3 #{)) (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) {:key1 {:key2 {:key3 "foo"}}} Rgds, Adrian. On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Rednose wrote: > > Say I have a data structure like this > > (def ref-map-map-map-set

adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Say I have a data structure like this (def ref-map-map-map-set (ref {:key1 {:key2 {:key3 #{)) If I want to add a new member to the set which is the value of :key3, I currently do this: (dosync (let [key1 (:key1 @ref-map-map-map-set) key2 (:key2 key1) key3 (:key3 key2)] (re