architecture

richiardiandrea 2021-02-02T02:34:43.097200Z

talking about protocols, is :extend-with-meta the only way to attach an implementation to a particular object instance?

phronmophobic 2021-02-02T02:36:42.098300Z

it's not quite attaching to a particular object, but depending on the use case, proxy or reify may work for you

richiardiandrea 2021-02-02T02:39:31.098600Z

yeah my use case was to attach the ISQLParameter protocol impl to an instance of InputStream I did not want to extend all of the InputStreams

seancorfield 2021-02-02T02:43:13.099Z

Since it requires metadata, you can't add it to a Java object.

seancorfield 2021-02-02T02:45:56.099200Z

Extending protocols with metadata works for Clojure data but not Java data. So in that case you are either going to have to extend ISQLParameter to all InputStream's or you're going to need some sort of explicit wrapper around InputStream perhaps?

phronmophobic 2021-02-02T02:47:26.099400Z

it seems like you could use proxy for this use case to wrap the input stream and also implement ISQLParameter . not sure it would be a good idea.

richiardiandrea 2021-02-02T02:58:55.099600Z

yeah the wrapper is what I went for anyways, but I was naively thinking that I could just (assoc my-wrapper-m 'clojure.java.jdbc/set-parameter (fn [] ...)) Am I completely off here?

richiardiandrea 2021-02-02T03:00:01.100100Z

actually it should be using with-meta but I wanted to add that ad-hoc if it makes sense

seancorfield 2021-02-02T03:08:59.100300Z

Yeah, you can attach metadata to a function, and you could use (constantly my-input-stream) and then have the set-parameter implementation call the value that is passed in and then read the data from that I guess...

seancorfield 2021-02-02T03:13:03.100500Z

(with-meta (constantly is) {'clojure.java.jdbc/set-parameter (fn [v stmt ix] (.setBinaryWhatever stmt (v) ix))}) something like that?

richiardiandrea 2021-02-02T03:19:43.100700Z

I think that would work, but do we need :extend-via-metadata true on the protocol also? I have actually opened a support issue today for that

seancorfield 2021-02-02T03:25:37.100900Z

Yes, the protocol must be :extend-via-metadata true for you to extend it via metadata 🙂

seancorfield 2021-02-02T03:26:45.101100Z

Which means you can't do that with clojure.java.jdbc as it stands today, sorry.

seancorfield 2021-02-02T03:27:44.101300Z

The protocols in next.jdbc can nearly all be extended via metadata tho'...

seancorfield 2021-02-02T03:34:08.101500Z

@richiardiandrea I guess I could make a new version of clojure.java.jdbc for you that makes some of the protocols extensible via metadata?

seancorfield 2021-02-02T04:03:57.101700Z

OK, 0.7.12 is heading to Maven Central with those protocols now extensible via metadata. Just for you!

🤘 2
richiardiandrea 2021-02-02T04:50:55.101900Z

woooooah whaat 😄

richiardiandrea 2021-02-02T04:51:54.102100Z

I was planning to patch tomorrow lol - I know we are in the same time zone so I have no other words than a big Thank you!

1