diff options
| author | hesham942 <heshamhatem2004@gmail.com> | 2025-05-13 13:37:02 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-05-14 13:21:18 +0200 |
| commit | a8716f3c4c6d78d38ce86d79c816062346dcc5bf (patch) | |
| tree | 482900744d3eb4fda1772396deb753319d272dc3 /django/db/backends/base | |
| parent | 6e36f7f78415e454dcde1d9ee33f2d2c7fdfdfad (diff) | |
Refs #36085 -- Moved compile_json_path to BaseDatabaseOperations.
Diffstat (limited to 'django/db/backends/base')
| -rw-r--r-- | django/db/backends/base/operations.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py index fea73bc1e4..ba6650ed69 100644 --- a/django/db/backends/base/operations.py +++ b/django/db/backends/base/operations.py @@ -792,3 +792,18 @@ class BaseDatabaseOperations: def format_debug_sql(self, sql): # Hook for backends (e.g. NoSQL) to customize formatting. return sqlparse.format(sql, reindent=True, keyword_case="upper") + + def compile_json_path(self, key_transforms, include_root=True): + """ + Hook for backends to customize all aspects of JSON path construction. + """ + path = ["$"] if include_root else [] + for key_transform in key_transforms: + try: + num = int(key_transform) + except ValueError: # Non-integer. + path.append(".") + path.append(json.dumps(key_transform)) + else: + path.append("[%s]" % num) + return "".join(path) |
