This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Helper function that builds a PostgreSQL jsonb_set function that also deeply creates missing objects | |
* | |
* Usage: | |
* 1. jsonbSetDeep(target = "my_field", path = arrayOf("depth1","depth2"), newJsonValue = "[]") | |
* returns - | |
* jsonb_set( | |
* CASE | |
* WHEN my_field IS NULL THEN '{"depth1": {}}' | |
* WHEN my_field -> 'depth1' IS NULL THEN jsonb_set(my_field, array['depth1'], '{}') |