Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogrocker/b7c8dac90f33d1e79f151056f1774c42 to your computer and use it in GitHub Desktop.
Save dogrocker/b7c8dac90f33d1e79f151056f1774c42 to your computer and use it in GitHub Desktop.
Returns the actual name of a given table name.

This method will strip off curly brackets from the given table name

and replace the percentage character '%' with [[tablePrefix]].

let re = /{{(.*?)}}/g
let str = 'SELECT * FROM {{%user}} FROM WHERE id IN (?)'
let tablePrefix = 'tbl_'
console.log(str.replace(re, '$1').replace('%', tablePrefix))
  • INPUT
SELECT * FROM {{%user}} FROM WHERE id IN (?)
  • OUTPUT
SELECT * FROM tbl_user FROM WHERE id IN (?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment