sql-strip-comments
v0.0.23
Published
Remove line and block comments from sql code
Downloads
368
Readme
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 = require("sql-strip-comments");
let sql='SELECT * FROM customers; -- test comments';
console.log(1, strip(sql));
// SELECT * FROM customers;
sql='SELECT * FROM customers; /* -- test comments */';
console.log(2, strip(sql));
// SELECT * FROM customers;
sql=`
SELECT
"comments can be one line (-- comment text
) and multiline (/* comment text */)" AS literal,
*
FROM
customers; /* -- test comments */`;
console.log(3, strip(sql));
// SELECT "comments can be one line (-- comment text
// ) and multiline (/* comment text */)" AS literal, * FROM customers;