This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-30
Channels
- # babashka (46)
- # beginners (234)
- # bristol-clojurians (4)
- # cider (7)
- # clj-kondo (39)
- # cljdoc (8)
- # cljs-dev (10)
- # cljsjs (10)
- # cljsrn (24)
- # clojure (84)
- # clojure-brasil (7)
- # clojure-europe (12)
- # clojure-germany (4)
- # clojure-italy (3)
- # clojure-nl (41)
- # clojure-spec (17)
- # clojure-uk (66)
- # clojurescript (64)
- # conjure (161)
- # cursive (12)
- # data-science (45)
- # datomic (20)
- # devops (11)
- # docker (2)
- # duct (9)
- # events (7)
- # figwheel (1)
- # figwheel-main (20)
- # fulcro (32)
- # graalvm (5)
- # helix (82)
- # jackdaw (9)
- # jobs-discuss (19)
- # kaocha (11)
- # local-first-clojure (1)
- # malli (6)
- # meander (3)
- # nrepl (12)
- # off-topic (2)
- # other-lisps (15)
- # pathom (14)
- # rdf (6)
- # re-frame (8)
- # reactive (1)
- # reagent (5)
- # reitit (4)
- # rum (3)
- # shadow-cljs (77)
- # spacemacs (3)
- # sql (9)
- # test-check (31)
- # tools-deps (13)
- # vim (62)
- # xtdb (18)
I've updated the Getting Started page in the docs (on master) to convert the explicit Component example over to the new component
function, showing that you don't need to create a record with start
/`stop` methods.
Spec for opts
, e.g. in get-connection
can be nilable
, with nil
it works just fine.
Isn't map?
too restrictive? It forces me to do (or opts {})
just to be able to use instrumentation.
(This may be question for clojure-spec
channel though)
@nikolavojicic Can you be a bit more specific about what you're asking? Which library? Which spec? Which file/line?
Both clojure.java.jdbc
and next.jdbc
provide their own specs and both have :opts
as an optional parameter for get-connection
:
;; clojure.java.jdbc/get-connection:
(s/fdef sql/get-connection
:args (s/cat :db-spec ::db-spec
:opts (s/? ::connection-options))
:ret ::connection)
;; next.jdbc/get-connection:
(s/fdef jdbc/get-connection
:args (s/cat :spec ::db-spec
:opts (s/? ::opts-map)))
If you are using those libraries, you should be using their specs.
I'm using next.jdbc
.
My question is would it be ok to change get-connection
spec to accept nil
opts, i.e: :opts (s/? (s/nilable ::opts-map))
?
Use case is when opts for connection is taken from another map, and it may be absent -> nil
.
With nil
opts, get-connection
works the same as with {}
opts.
Ofc I can override it for my project so it's not a big deal.
@nikolavojicic Sorry for the delay. I'm on vacation today so I'm away from my computer quite a bit. I really don't like optional parameters that can also be nil
or the intended value, which is why the specs are as they are. I understand that nil
"works" in place of opts
in some (all?) API functions in next.jdbc
(and clojure.java.jdbc
) but that's just an artifact of the implementation and not something I'm prepared to support as an official part of the API -- so the specs will remain stricter than the implementation here. Since you are fetching your options from another map, you can supply a "not found" value of {}
at the point of access: (:jdbc-opts my-map {})
or (get my-map :jdbc-opts {})
and then the intent is clear.
(and if that key in your map can be nil
then I'd say you have an upstream problem: finding nil
values in a Clojure hash map is a code/design smell as far as I'm concerned -- except in very specific cases where nil
has a specific semantic meaning and you need to distinguish between contains?
and an actual nil
value)