I'm a little confused about what's happening behind the scenes wrt next.jdbc's built-in HikariCP-component support.
When I evaluate (connection/component HikariDataSource <my-dbspec>), I get an empty map, just {}. It clearly works, as invoking that connection/component with (component/start (...)) gives me a valid datasource that I can use to query, but I'm just very lost as of course running (component/start {}) is not going to give me a proper datasource. Whats really happening here?
much appreciated all-around! this is definitely eye-opening: A new branch in the Clojure Skill-Tree has been revealed 😄
See this:
(meta (connection/component HikariDataSource db-spec))
The component function uses new-ish feature of implementing protocols via metadata - so all the relevant bits are not in the map itself, but the map's metadata. See more here: https://clojure.org/reference/protocols#_extend_via_metadataWhoahh, I see, appreciate it, meta stuff is definitely still something I haven't looked at enough yet
Happy to help!
do (set! *print-meta* true) and then evaluate them again
Perhaps also a little mind-blowing in this case is that while connection/component gives you a hash map with metadata, when you start it, you get back a function with metadata. If you call the function, you get the underlying datasource out of the component. If you stop the function, you'll get back the empty hash map with metadata (so you can start it again).
Sierra's Component library has been able to work with just metadata for a while. That means that any Clojure object that can carry metadata can be a "Component" if it has no dependencies. For a "Component" with dependencies, you must have an object that is associative by key (keyword) so you must have a hash map or a record.