mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #26511 -- Fixed json.KeyTextTransform() on MySQL/MariaDB.
This commit is contained in:
@@ -4,6 +4,7 @@ from django import forms
|
||||
from django.core import checks, exceptions
|
||||
from django.db import NotSupportedError, connections, router
|
||||
from django.db.models import lookups
|
||||
from django.db.models.fields import TextField
|
||||
from django.db.models.lookups import PostgresOperatorLookup, Transform
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -366,6 +367,17 @@ class KeyTransform(Transform):
|
||||
class KeyTextTransform(KeyTransform):
|
||||
postgres_operator = "->>"
|
||||
postgres_nested_operator = "#>>"
|
||||
output_field = TextField()
|
||||
|
||||
def as_mysql(self, compiler, connection):
|
||||
if connection.mysql_is_mariadb:
|
||||
# MariaDB doesn't support -> and ->> operators (see MDEV-13594).
|
||||
sql, params = super().as_mysql(compiler, connection)
|
||||
return "JSON_UNQUOTE(%s)" % sql, params
|
||||
else:
|
||||
lhs, params, key_transforms = self.preprocess_lhs(compiler, connection)
|
||||
json_path = compile_json_path(key_transforms)
|
||||
return "(%s ->> %%s)" % lhs, tuple(params) + (json_path,)
|
||||
|
||||
|
||||
class KeyTransformTextLookupMixin:
|
||||
|
||||
Reference in New Issue
Block a user