caminte
caminte copied to clipboard
JSON values converted to strings with some NoSQL adapters
Columns of type JSON result in objects being written as strings with some adapters (redis in my case), e.g.:
{"foo": "bar"}
yields:
"{\"foo\":\"bar\"}"
The immediate cause is that AbstractClass._forDB
method checks this.schema.adapter.name
(which is not always set inside adapters) against a pre-defined list of NoSQL drivers, from which redis
is absent.
As an expedient my pull request #43 fixes the problem (n.b. in a data backwards-incompatible fashion).
However, I see a few problems with this approach:
- Abstract DB class has to know in advance of adapter implementations.
-
NoSQL
is really a vague umbrella term. The important thing here is whether a given adapter can handle JSON objects on its own or not. - Adapters names are not enforced; however, data massaging logic depends on it.
I figure the best solution would be to have adapters extend from a common prototype having:
a. an "abstract" name
method that by default throws an Exception and should be overriden in derivatives.
b. an implementation-specific method able to massage data fields as necessary prior to insertion, or
c. an implementation-specific method that tells whether the adapter can handle given data type on its own.
Whatever the implementation, the concept is letting the adapters handle data massaging on their own, or at least avoid forcing the higher level classes to know which adapters can handle which data types.