Skip to content

Instantly share code, notes, and snippets.

@nivb52
Created January 11, 2022 20:09
Show Gist options
  • Select an option

  • Save nivb52/5191d58481bd750f08b607252bba3181 to your computer and use it in GitHub Desktop.

Select an option

Save nivb52/5191d58481bd750f08b607252bba3181 to your computer and use it in GitHub Desktop.
SQL/Posgress Query Builder Function
/**
* @param jsonPath {String}
* @example 'name.people.joe' returns 'name ->> people ->> joe'
* @returns {String}
*/
function createSearchJsonQuery (jsonPath) {
const add = jsonPath.split('.').join(' -> ');
return (add.substring(0, add.lastIndexOf('->')) + ' ->> ' + add.substring(add.lastIndexOf('->') +3 ));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment