You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
then ("pgrst_json_defs.val", "jsonb_array_elements", if isJsonObject then"jsonb_to_record"else"jsonb_to_recordset")
352
-
else ("pgrst_payload.json_data", "json_array_elements", if isJsonObject then"json_to_record"else"json_to_recordset")
353
-
354
-
jsonPlaceHolder =SQL.encoderAndParam (HE.nullable $if includeDefaults thenHE.jsonbLazyBytes elseHE.jsonLazyBytes) body
351
+
then ("pgrst_json_defs.val", "jsonb_array_elements", if isJsonObject then"jsonb_to_record"else"jsonb_to_recordset", "jsonb_object_agg", "::jsonb", "jsonb_build_array")
352
+
else ("pgrst_payload.json_data", "json_array_elements", if isJsonObject then"json_to_record"else"json_to_recordset", "json_object_agg", "::json", "json_build_array")
353
+
jsonPlaceHolder =
354
+
if isPgrstPatch
355
+
-- For pgrst patch updates, given json:
356
+
-- [{"op":"set","path":"name","value":"john"},
357
+
-- {"op":"set","path":"age" ,"value":20}]
358
+
-- We extract the key,values using pg json functions and convert
359
+
-- it to a regular json, so we get: {"name":"john","age": 20}.
<>SQL.encoderAndParam (HE.nullable $if includeDefaults thenHE.jsonbLazyBytes elseHE.jsonLazyBytes) body
364
+
<> jsonCastF <>") as patch_row )"
365
+
-- For regular updates, we encode the complete body as is, e.g {"name":"john","age":20}
366
+
else
367
+
SQL.encoderAndParam (HE.nullable $if includeDefaults thenHE.jsonbLazyBytes elseHE.jsonLazyBytes) body
355
368
isJsonObject =-- light validation as pg's json_to_record(set) already validates that the body is valid JSON. We just need to know whether the body looks like an object or not.
0 commit comments