I use jsonb columns in Postgres to store arbitrary data. I don't automatically convert these columns when I query, preferring to wait until it's necessary. I can convert those columns before passing the results to match?, but it would be nice to perform that automatically within the matcher.
However, implementing Matcher for the PGObject or PGArray doesn't work if I use a normal sequence or object in the expected position, as the built-in matcher implementations check the type of actual to short-circuit an otherwise lengthy check. For example, here's sequence-match as used by EqualSeq.
I'm not sure the right way to go about this, as there's a step of transformation that must happen before the actual can be checked, which I'm seeking to automate. Maybe that's outside the purview of matcher-combinators?
Problem statement
I use jsonb columns in Postgres to store arbitrary data. I don't automatically convert these columns when I query, preferring to wait until it's necessary. I can convert those columns before passing the results to
match?
, but it would be nice to perform that automatically within the matcher.However, implementing
Matcher
for the PGObject or PGArray doesn't work if I use a normal sequence or object in theexpected
position, as the built-in matcher implementations check the type ofactual
to short-circuit an otherwise lengthy check. For example, here'ssequence-match
as used by EqualSeq.https://github.com/nubank/matcher-combinators/blob/afdb64012757719bb699c2a7a3d9d8c2f06a9d32/src/cljc/matcher_combinators/core.cljc#L262-L265
Proposed solution
I'm not sure the right way to go about this, as there's a step of transformation that must happen before the
actual
can be checked, which I'm seeking to automate. Maybe that's outside the purview of matcher-combinators?Thanks so much.
Repro: