forked from taozhi8833998/node-sql-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.js
More file actions
19 lines (16 loc) · 705 Bytes
/
sql.js
File metadata and controls
19 lines (16 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { bigQueryToSQL, unionToSQL, multipleToSQL } from './union'
const surportedTypes = ['select', 'delete', 'update', 'insert', 'drop', 'rename', 'truncate', 'call', 'use', 'alter', 'set', 'create', 'lock', 'unlock', 'bigquery', 'declare', 'show']
function checkSupported(expr) {
const ast = expr && expr.ast ? expr.ast : expr
if (!surportedTypes.includes(ast.type)) throw new Error(`${ast.type} statements not supported at the moment`)
}
export default function toSQL(ast) {
if (Array.isArray(ast)) {
ast.forEach(checkSupported)
return multipleToSQL(ast)
}
checkSupported(ast)
const { type } = ast
if (type === 'bigquery') return bigQueryToSQL(ast)
return unionToSQL(ast)
}