Remove line (-- comment text \n
) and block (\* comment text *\
) comments from sql code. Comments in string literals are not treated as comments. Nested block comments are not supported.
Install
$ npm install sql-strip-comments --save
Usage
const strip = ; let sql='SELECT * FROM customers; -- test comments';console;// SELECT * FROM customers; sql='SELECT * FROM customers; /* -- test comments */';console;// SELECT * FROM customers; sql=`SELECT "comments can be one line (-- comment text ) and multiline (/* comment text */)" AS literal, * FROM customers; /* -- test comments */`;console;// SELECT "comments can be one line (-- comment text // ) and multiline (/* comment text */)" AS literal, * FROM customers;