sql-strip-comments

0.0.23 • Public • Published

npm npm ghit.me

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;
 

Readme

Keywords

Package Sidebar

Install

npm i sql-strip-comments

Weekly Downloads

107

Version

0.0.23

License

MIT

Last publish

Collaborators

  • decemberster