How to use node-sql-parser in frontend #1921
-
How to use node-sql-parser in frontend? |
Beta Was this translation helpful? Give feedback.
Answered by
taozhi8833998
May 26, 2024
Replies: 1 comment
-
// 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
<script src="https://unpkg.com/node-sql-parser/umd/mysql.umd.js"></script>
<script src="https://unpkg.com/node-sql-parser/umd/postgresql.umd.js"></script>
<!DOCTYPE html>
<html lang="en" >
<head>
<title>node-sql-parser</title>
<meta charset="utf-8" />
</head>
<body>
<p><em>Check console to see the output</em></p>
<script src="https://unpkg.com/node-sql-parser/umd/mysql.umd.js"></script>
<script>
window.onload = function () {
// Example parser
const parser = new NodeSQLParser.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> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
huxiaoyan0824
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NodeSQLParser
object is onwindow