// support all database parser, but file size is about 750K
<script src="https://unpkg.com/node-sql-parser/umd/index.umd.js"></script>
// or you can import specified database parser only, it's about 150K<scriptsrc="https://unpkg.com/node-sql-parser/umd/mysql.umd.js"></script><scriptsrc="https://unpkg.com/node-sql-parser/umd/postgresql.umd.js"></script>
NodeSQLParser object is on window
<!DOCTYPE html><htmllang="en" ><head><title>node-sql-parser</title><metacharset="utf-8" /></head><body><p><em>Check console to see the output</em></p><scriptsrc="https://unpkg.com/node-sql-parser/umd/mysql.umd.js"></script><script>window.onload = function () {
// Example parserconst parser = newNodeSQLParser.Parser()
const ast = parser.astify("select id, name from students where age < 18")
console.log(ast)
const sql = parser.sqlify(ast)
console.log(sql)
}
</script></body></html>
whiteListCheck function check on table mode and MySQL database by default
const { Parser } = require('node-sql-parser');
const parser = newParser();
const sql = 'UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'const whiteTableList = ['(select|update)::(.*)::(a|b)'] // array that contain multiple authoritiesconst opt = {
database: 'MySQL',
type: 'table',
}
// opt is optional
parser.whiteListCheck(sql, whiteTableList, opt) // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
check column authority
const { Parser } = require('node-sql-parser');
const parser = newParser();
const sql = 'UPDATE a SET id = 1 WHERE name IN (SELECT name FROM b)'const whiteColumnList = ['select::null::name', 'update::a::id'] // array that contain multiple authoritiesconst opt = {
database: 'MySQL',
type: 'column',
}
// opt is optional
parser.whiteListCheck(sql, whiteColumnList, opt) // if check failed, an error would be thrown with relevant error message, if passed it would return undefined
:kissing_heart: Acknowledgement
This project is inspired by the SQL parser flora-sql-parser module.
The npm package @openobserve/node-sql-parser receives a total of 2,127 weekly downloads. As such, @openobserve/node-sql-parser popularity was classified as popular.
We found that @openobserve/node-sql-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 2 open source maintainers collaborating on the project.
Package last updated on 06 Jun 2025
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.