This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-14
Channels
- # adventofcode (62)
- # beginners (78)
- # boot (26)
- # boot-dev (9)
- # cider (73)
- # cljs-dev (33)
- # cljsrn (36)
- # clojure (159)
- # clojure-android (1)
- # clojure-austin (1)
- # clojure-greece (79)
- # clojure-italy (10)
- # clojure-nl (3)
- # clojure-russia (11)
- # clojure-spec (33)
- # clojure-uk (26)
- # clojurescript (107)
- # core-async (22)
- # core-logic (12)
- # cursive (16)
- # datomic (13)
- # devcards (5)
- # duct (36)
- # emacs (4)
- # figwheel (3)
- # fulcro (107)
- # graphql (171)
- # hoplon (27)
- # instaparse (24)
- # jobs-discuss (34)
- # juxt (3)
- # lein-figwheel (1)
- # leiningen (8)
- # lumo (11)
- # off-topic (9)
- # onyx (79)
- # parinfer (1)
- # pedestal (75)
- # re-frame (27)
- # rum (1)
- # shadow-cljs (11)
- # spacemacs (20)
- # specter (17)
- # unrepl (96)
I can't find the source code of ig/init-key for :duct.module.web/api
in http://github.com/duct-framework/module.web
where is it?
@weavejester I did have :duct.module.web/api
because I generated the template with +api
. So the problem now is I don't know how to destructure json (or edn) params from http requests with ataraxy
@myguidingstar In the duct.module.web
namespace
Have you checked the guide that’s halfway done? That gives examples of destructuring parameters.
The API module loads in Muuntaja’s wrap-format
, which puts the parsed body in :body-params
.
oh i was looking at duct.middleware.web 😄 silly me
I started with that guide. I was poking around the config file to get understanding
and in a moment of unconsciousness I changed :body-params
to :json-params
but never changed it back
I didn't know it's muuntaja that is underneat instead of ring-json
I’ll see about improving the docs to perhaps make it more obvious in future.
Muuntaja handles edn
as well, and potentially other formats. It also handles content negotiation correctly.
how grateful I am as I see you've done a lot both in terms of code and docs
thank you
in dev
namespace, how do I pull sql instance from system
var so I can make real queries with it?
never mind, found it again in duct guide
but I need explanation for this adhoc function:
`(defn db [] (-> system (ig/find-derived-1 :duct.database/sql) val :spec))`
@myguidingstar The (ig/find-derived-1 m k)
function looks for a single key in m
that’s derived from k
. So in the above case, it’s saying: “Find a key that inherits from :duct.database/sql
”
Like clojure.core/find
, ig/find-derived-1
returns a key/value pair.
So we then use val
to get the value.
That gives us the database boundary record (`duct.database.sql.Boundary`), and that has a key :spec
that contains the database spec.
Oh, and in case it’s not obvious, system
is a var that stores the running system in development.
We could have also have written:
(defn db []
(-> system :duct.database.sql/hikaricp :spec))
Because :duct.database.sql/hikaricp
is the actual database key. But if we changed that in any way, using a different connection pool library for instance, then the db
function would need to be changed.
By using ig/find-derived-1
instead of looking up the key directly, we’re telling the function to find anything that looks like a SQL database connection.
If there’s multiple database connections, ig/find-derived-1
will throw an ambiguous key exception.
my guess is :duct.database.sql/hikaricp
is unique so it can never cause ig/find-derived-1
throw an ambiguous key exception, while :duct.database/sql
can. Is it correct?
btw, how do we call the relation between :duct.database/sql
and :duct.database.sql/hikaricp
? (I think that will help with understanding)
@myguidingstar Yes, unless you have multiple SQL databases in your application
:duct.database.sql/hikaricp
derives from :duct.database/sql
Namespaced keywords in Clojure can be derived from one another. There’s an inheritance hierarchy.
So (find-derived m k)
searches for all map entries in m
where the key derives from k
And (find-derived-1 m k)
looks for a single derived map entry, and throws an error if it’s ambiguous.