Repository navigation
sqltypes.py: add json (de)serializers for dialects which lack corresp… - #443
Nutigoodpipes wants to merge 1 commit into
Conversation
|
So, you probably know there's a real SQLite JSON type happening at: https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/706/, in case that's helpful. Here, I'm not understanding why you need to use the actual |
|
Thanks for your answer, I haven't heard about that incoming type. Will look at it. What I need basically is I was going for Maybe I'm doing it the wrong way, but the only solutions that works for me was to implement a decorated type with |
|
You can't use the "->>" operators in your program because you are trying to be compatible with SQLite, unless you are implementing those operators as well. In your example above, I can use If you can just send me an example of the whole thing you are doing and where it's failing, that would help. |
|
The ->> operator is linked to the "astext" method in any case, and per the guidelines at http://docs.sqlalchemy.org/en/latest/core/type_basics.html?highlight=json#sqlalchemy.types.JSON, to do platform agnostic JSON you need to use cast. In your program, this works too: on postgresql this renders as: |
|
more correctly, according to the docs:
|
|
Here is a more complete example for the reason why those methods are needed. What I would like to do is match columns or json fields with inserted values directly (except with explicit casts such as Yes I saw the documentation, and that's also a reason why I went for custom JSON. Using this I can match just knowing the structure and given that I implemented the backend agnostic layer correctly. Given that this is a module of a project that already have postgresql support, I really would like to be consistent with this syntax especially for types and operators that are not implemented ( |
|
OK, it looks like you want a SQLIte JSON type that also has the "astext" bit. See that's a big deal because that is completely at odds with how I've designed the whole thing, and if there is really really a reason people need this "astext" approach like this, I need to know. now why exactly do you need to say: and not: ? is it strictly the verbosity? or is there some other quality (performance, collation, or something) of the "->>" operator you are trying to get? Because really, the feature we want then is some kind of magic operator on the base JSON type that does that cast() thing that's currently in the docs. We can work on making PG's "astext" something that invokes from the base JSON type, and does the cast() thing or whatever on other backends. That would be way better here, because at the moment, even when I implement the SQLite JSON type, it doesn't do what you want and that is a big failure on my end. I'm sorry this has to be a longer process but this is why I always need to understand what it is someone wants to do, it often refers to some much bigger issue that needs to be addressed. |
|
I cannot talk about performance because I haven't done any benchmark for now. But the goal here was indeed to render astext with in the Comparator subclass. This operator being interpreted with the access_astext function for sqlite wich do the cast. That's fine to take time to put things clearly. This may be an error of mine in the first design so I'm coming back if I have more elements. |
|
as always we need to focus on the end result. if we get the base JSON type to have data['foo'].astext == 'bar' and make that work for MySQL as well as the SQLite JSON type in gerrit, that's what you want, right? because everybody wants that anyway. you can work on that if you want to contribute code. |
|
also, the code here is weird that it assumes the base dialect has that attribute and it's None otherwise, sure, but it bothered me that you'd have your code using your SQLite-level json translator for some cases and the base JSON json translator in others. that was the problem. |
Summary
When implementing json type for dialects which doesn't support it, default json serializer is not defined.
Details
All methods and classes here to keep the example minimal but complete are void to keep the example minimal and complete. Removing the
coerce_compared_valuewould not trigger the bug, but this is needed thereafter for comparators to work with native python dictionnary.Running with 'master' triggers
(exceptions.AttributeError) 'SQLiteDialect_pysqlite' object has no attribute '_json_serializer'Tested with python 3.6 and 2.7