sql

All things SQL and JDBC...
seancorfield 2020-04-30T02:50:57.369Z

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.

👏 1
nikolavojicic 2020-04-30T14:43:12.374600Z

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)

seancorfield 2020-04-30T15:53:17.376500Z

@nikolavojicic Can you be a bit more specific about what you're asking? Which library? Which spec? Which file/line?

seancorfield 2020-04-30T15:56:59.379600Z

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)))

seancorfield 2020-04-30T15:57:16.380100Z

If you are using those libraries, you should be using their specs.

nikolavojicic 2020-04-30T16:07:25.385Z

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.

nikolavojicic 2020-04-30T16:13:57.385600Z

Ofc I can override it for my project so it's not a big deal.

seancorfield 2020-04-30T17:56:10.389700Z

@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.

👍 2
seancorfield 2020-04-30T17:58:06.391600Z

(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)

💯 1