Closed fantix closed 2 years ago
I don't like the codec context object -- do we actually need it (or to expose it)? Why can't we copy the config API here, something like
client=client.with_client_options(
auto_unpack_json=True
)
IOW not even tie this to codecs, which we should allow overriding in some remote future. Thoughts?
cc @elprans @tailhook
A couple of thoughts:
set_type_codec
API, where you can change the decoded type of any EdgeDB type.cli.with_codec_context(edgedb.codecs.DEFAULT).query(...)
--codecs edgedb.codecs.DEFAULT_WITH_JSON_UNPACK
param and --unpack-json
as a shortcut.To state it again: changing connection params must not influence types for generated code. I.e these must be equivalent:
from generated import test_json
await test_json(cli)
await test_json(cli.with_codec_context(whatever_codec_i_like))
This also means that only_replace_default
has not much sense.
Something like this, could be a shortcut to changing codecs:
client = client.with_client_options(
auto_unpack_json=True
)
But the problem is that we also need resetting those options. And we have a confusing dichotomy where with_config
is incremental but with_transaction_options
is not.
All in all, it's more complex that we would like it to be. If we need set_type_codec
API, it's probably better to go with with_codec_context
(or similar).
If we don't need set_type_codec
API it's probably better to always unpack JSONs and release 2.0. (and advise <str><json>x
for anyone who wants a string).
@fantix Sigh, I did not intend to merge this PR and I've already reverted the merge. I'll open a new issue.
Requires https://github.com/MagicStack/py-pgproto/pull/18
Sample code to enable JSON handling:
Sample generated code with JSON handling turned ON:
Sample generated code with JSON handling turned OFF (default behavior):