diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-08-04 11:56:31 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-08-04 12:38:58 -0400 |
commit | f2fa9d000b44a54b0fd3ae6114eb5d53ef20c3b8 (patch) | |
tree | d7cec44ced27243d7f0d4a62831e5f4de9903bdc /lib/sqlalchemy/dialects/postgresql/json.py | |
parent | af6f4ab938f1ef66491cf239c91ffff393275d95 (diff) | |
download | sqlalchemy-f2fa9d000b44a54b0fd3ae6114eb5d53ef20c3b8.tar.gz |
Build string/int processors for JSONIndexType, JSONPathType
Fixed regression in JSON datatypes where the "literal processor" for
a JSON index value, that needs to take effect for example within DDL,
would not be invoked for the value. The native String and Integer
datatypes are now called upon from within the JSONIndexType
and JSONPathType. This is applied to the generic, Postgresql, and
MySQL JSON types.
Change-Id: Ifa5f2acfeee57a79d01d7fc85d265a37bd27c716
Fixes: #3765
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/json.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/json.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py index b0f0f7cf0..05c4d014d 100644 --- a/lib/sqlalchemy/dialects/postgresql/json.py +++ b/lib/sqlalchemy/dialects/postgresql/json.py @@ -49,10 +49,28 @@ CONTAINED_BY = operators.custom_op( class JSONPathType(sqltypes.JSON.JSONPathType): def bind_processor(self, dialect): + super_proc = self.string_bind_processor(dialect) + + def process(value): + assert isinstance(value, collections.Sequence) + tokens = [util.text_type(elem)for elem in value] + value = "{%s}" % (", ".join(tokens)) + if super_proc: + value = super_proc(value) + return value + + return process + + def literal_processor(self, dialect): + super_proc = self.string_literal_processor(dialect) + def process(value): assert isinstance(value, collections.Sequence) - tokens = [util.text_type(elem) for elem in value] - return "{%s}" % (", ".join(tokens)) + tokens = [util.text_type(elem)for elem in value] + value = "{%s}" % (", ".join(tokens)) + if super_proc: + value = super_proc(value) + return value return process |