MCPcopy
hub / github.com/django/django / as_native

Method as_native

django/db/models/functions/json.py:19–33  ·  view source on GitHub ↗
(self, compiler, connection, *, returning, **extra_context)

Source from the content-addressed store, hash-verified

17 return super().as_sql(compiler, connection, **extra_context)
18
19 def as_native(self, compiler, connection, *, returning, **extra_context):
20 # PostgreSQL 16+ and Oracle remove SQL NULL values from the array by
21 # default. Adds the NULL ON NULL clause to keep NULL values in the
22 # array, mapping them to JSON null values, which matches the behavior
23 # of SQLite.
24 null_on_null = "NULL ON NULL" if len(self.get_source_expressions()) > 0 else ""
25
26 return self.as_sql(
27 compiler,
28 connection,
29 template=(
30 f"%(function)s(%(expressions)s {null_on_null} RETURNING {returning})"
31 ),
32 **extra_context,
33 )
34
35 def as_postgresql(self, compiler, connection, **extra_context):
36 # Casting source expressions is only required using JSONB_BUILD_ARRAY

Callers 3

as_oracleMethod · 0.95
as_postgresqlMethod · 0.45
as_postgresqlMethod · 0.45

Calls 2

as_sqlMethod · 0.95

Tested by

no test coverage detected