-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New codec setting API #389
Comments
I'm not sure why you want a factory in My thinking is that you should have very few codecs even if more than one. And instantiating one on every query (more specifically every |
We do that though for every type descriptor for every query. Saying that I see now that we should clarify the relationship between a odec, a factory, etc. Sounds like |
The alternative would be to set the whole codec collection: connection.with_codecs(edgedb.codecs.DEFAULT)
connection.with_codecs(edgedb.codecs.DEFAULT_WITH_UNPACKED_JSON) The collection itself has interface like this: class Codecs:
def get_type_name(self, descriptor) -> str:
# roughly this:
return self.__type_names[descriptor.type_name]
def get_codec(self, descriptor) -> str:
# roughly this:
return self.__codecs[descriptor.type_name] Then you can either inherit the collection type: class MyCodecs(Codecs):
def get_type_name(self, descriptor) -> str:
if descriptor.type_name.starts_with('myapp'):
return self._custom_type(descriptor)
else:
return super().get_type_name(descriptor) Or use it as a mutable collection: codecs = edgedb.codecs.DEFAULT.copy()
codecs.add_codec('myapp::MyScalar', MyScalarCodec, 'myapp.MyType')
conn.with_codecs(codecs) This is kinda a bit more cumbersome if you need to change just one type. But is more extensible if you want to change decoding all enum types or all integer types. Also it will allow us adding more information to the Few variations are possible. Like maybe |
To simplify single type case, we can also probably allow both ways: connection.with_codec(MyDecimalCodec)
# being equivalent to
connection.with_codecs(
connection.get_codecs().with_codec(MyDecimalCodec)
) But I think this means copying the whole codec dictionary, which means it's better to do it at the global level: DECIMAL_CODECS = edgedb.codecs.DEFAULT.with_codec(MyDecimalCodec)
de request():
conn = conn.with_codecs(DECIMAL_CODECS) |
I'd like to continue the discussion started in #388.
Paul shared a number of great thoughts in his comment #388 (comment) and later Fantix and I had a quick 1:1 call and naturally discussed the API a bit.
Here's what I think we should do:
with_client_options
API that I proposed.I propose the following API:
A new method called
client.with_codec(codec: Codec)
. Enables the passed codec for the new client instance the method returns. Usage:A new method called
client.with_default_codecs()
. Returns a new client instance with all codecs reset to the default mapping. We need this in the codegen - to reset all codecs before we run the query.A new
Codec
interface:New command-line option for codegen:
--with-codec
that would accept a fully qualified nameto a Python factory for the codec, e.g.
mypackage.mytype.EdgeDBCodec
.cc @fantix @tailhook
The text was updated successfully, but these errors were encountered: