Fork me on GitHub
#beginners
<
2019-10-05
>
tjb04:10:53

hey team im confused on this. when i get parameters from ring i get the following map {query test, tags [clojure something]} and when i check this via an if statement i cannot do (if (contains? params :tags) true false) but i can do (if (contains? params "tags") true false) why is that?

seancorfield04:10:15

@tjb It depends on the middleware you have in play

seancorfield04:10:34

There is middleware that turns parameters into keywords

seancorfield04:10:17

(`ring-middleware-keyword-params`)

tjb00:10:37

awesome this is good info. thank you @U04V70XH6!

Vachi12:10:39

hi guys, I'm trying to convert a string to a qualified keyword

"product-attribute/id-product-attribute" -> :product-attribute/id-product-attribute 
I used
(keyword) 
but it only returns the keyword
:id-product-attribute 
I need the fully qualified ones, how can I achieve it?

jaihindhreddy12:10:16

Maybe (apply keyword (clojure.string/split "product-attribute/id-product-attribute" #"/"))

Vachi12:10:41

thanks, I solved this way

(defn ->snake-case [s]
  (let [ns (str/replace (namespace s) #"-" "_")
        kw (str/replace (name s) #"-" "_")]
    (keyword ns kw)))
 

jaihindhreddy12:10:51

but I have a feeling it might not be a good idea depending on why exactly you're doing this, and where exactly those strings come from.

Vachi12:10:44

next.jdbc returns the results with _ keywords instead of - , so I have to do a conversion in order to stay consistent and idiomatic

seancorfield19:10:13

Use a builder function that does what you want @UJ9KCME4U That's the correct way to do it.

seancorfield19:10:15

You probably want to add camel-snake-kebab as a dependency so you can use well tested functions

seancorfield19:10:58

Questions about next.jdbc are best asked in #sql to make sure I see them BTW

Vachi19:10:47

@U04V70XH6 thank you!!

Shaitan15:10:40

is this binding (defn funcv [{:keys [db server-name]} token]... takes token and splits it into db and server name or something else happens?

schmee16:10:26

it extracts the keys db and server-name from the first argument, where the first argument is a map: https://clojure.org/guides/destructuring#_associative_destructuring

schmee16:10:08

oh, missed that this was already answered below

chris_johnson15:10:10

I would have to noodle around at a REPL for a bit to confirm but I am pretty sure what you have there is a two-argument fn where the first arg is a map, from which you are pulling the :db and :server-name keys into symbols, and the second arg is something unspecified that you’re calling token

chris_johnson15:10:36

I suspect that what you want to do is: (defn funcv [{:keys [db server-name] :as token}] ...), which would take a single argument that is a map, pull out :db and :server-name from that map as symbols, and also the entire map as token for use elsewhere. The community-standard reference for the powerful, but complex, set of tools for destructuring stuff is here: https://gist.github.com/john2x/e1dca953548bfdfb9844