
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
js-sql-parser
Advanced tools
parse / stringify sql (select grammar) in js.
sql grammar follows https://dev.mysql.com/doc/refman/5.7/en/select.html
table_factor since v1.6.0PlaceHolder like ${param} since v1.5.0 #43using ' & " for column alias? since v1.4.1 #40, #44having since v1.2.1. #29for more changes see CHANGELOG
npm install --save js-sql-parser
const parser = require('js-sql-parser');
const ast = parser.parse('select * from dual');
console.log(JSON.stringify(ast, null, 2));
ast.value.selectItems.value[0].value = 'foo';
ast.value.from.value[0].value.value.value = 'bar';
console.log(parser.stringify(ast));
// SELECT foo FROM bar
// placeholder test
const parser = require('js-sql-parser');
const ast = parser.parse('select ${a} as a');
ast['value']['selectItems']['value'][0]['value'] = "'value'";
console.log(parser.stringify(ast));
// SELECT 'value' AS a
Note: PlaceHolder is an literal value but not an identifier. Table_name / column_name / function_name are identifier thus should NOT be placed with placeholder.
<script src="./dist/parser/sqlParser.js"><script/>
var sqlParser = window.sqlParser;
var ast = sqlParser.parse('select * from dual');
var sql = sqlParser.stringify(ast);
...
npm run build to build the distributable.MIT
FAQs
> parse / stringify sql (select grammar) in js.
The npm package js-sql-parser receives a total of 54,748 weekly downloads. As such, js-sql-parser popularity was classified as popular.
We found that js-sql-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.