Created
April 7, 2022 12:20
-
-
Save abdulloooh/8a52a4bd0791a7f54d1c391d53337d63 to your computer and use it in GitHub Desktop.
Convert JS array to psql array
This file contains 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
const toPsqlArray = (arr) => { | |
let value = 'array[]::text[]'; | |
if (arr && arr.length > 0) { | |
value = 'ARRAY ['; | |
arr.map((each) => { | |
value = `${value} '${each}',`; | |
}); | |
value = `${value.slice(0, -1)} ]`; | |
} | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment